Merge pull request #18414 from woocommerce/fix/18412

Fix wc_notice_count logic and add test
This commit is contained in:
Claudio Sanches 2018-01-10 11:39:08 -02:00 committed by GitHub
commit 8a7066e319
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 4 deletions

View File

@ -38,7 +38,7 @@ function wc_notice_count( $notice_type = '' ) {
} elseif ( empty( $notice_type ) ) {
foreach ( $all_notices as $notices ) {
$notice_count += absint( sizeof( $all_notices ) );
$notice_count += count( $notices );
}
}

View File

@ -35,10 +35,24 @@ class WC_Tests_Notice_Functions extends WC_Unit_Test_Case {
wc_add_notice( 'Bogus Error Notice', 'error' );
$this->assertEquals( 1, wc_notice_count( 'error' ) );
// multiple notices of different types
wc_add_notice( 'Bogus Notice 2', 'success' );
// multiple notices of different types.
wc_clear_notices();
wc_add_notice( 'Bogus 1', 'success' );
wc_add_notice( 'Bogus 2', 'success' );
wc_add_notice( 'Bogus Notice 1', 'notice' );
wc_add_notice( 'Bogus Notice 2', 'notice' );
wc_add_notice( 'Bogus Error Notice 1', 'error' );
wc_add_notice( 'Bogus Error Notice 2', 'error' );
$this->assertEquals( 4, wc_notice_count() );
$this->assertEquals( 6, wc_notice_count() );
// repeat with duplicates.
wc_add_notice( 'Bogus 1', 'success' );
wc_add_notice( 'Bogus 2', 'success' );
wc_add_notice( 'Bogus Notice 1', 'notice' );
wc_add_notice( 'Bogus Notice 2', 'notice' );
wc_add_notice( 'Bogus Error Notice 1', 'error' );
wc_add_notice( 'Bogus Error Notice 2', 'error' );
$this->assertEquals( 12, wc_notice_count() );
}
/**