Merge pull request #18414 from woocommerce/fix/18412
Fix wc_notice_count logic and add test
This commit is contained in:
commit
8a7066e319
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue