Skip to content

Commit

Permalink
Merge pull request woocommerce#18414 from woocommerce/fix/18412
Browse files Browse the repository at this point in the history
Fix wc_notice_count logic and add test
  • Loading branch information
claudiosanches committed Jan 10, 2018
2 parents 501f03e + 97673e2 commit 8a7066e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion includes/wc-notice-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}

Expand Down
20 changes: 17 additions & 3 deletions tests/unit-tests/util/notice-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,24 @@ function test_wc_notice_count() {
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( 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( 4, wc_notice_count() );
$this->assertEquals( 12, wc_notice_count() );
}

/**
Expand Down

0 comments on commit 8a7066e

Please sign in to comment.