Skip to content

Commit

Permalink
Fix wc_notice_count logic and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed Jan 10, 2018
1 parent d7718df commit 97673e2
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 97673e2

Please sign in to comment.