From 97673e2de824e9ea2345b0cbb0a7e95055d93a03 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 10 Jan 2018 12:43:48 +0000 Subject: [PATCH] Fix wc_notice_count logic and add test --- includes/wc-notice-functions.php | 2 +- tests/unit-tests/util/notice-functions.php | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/includes/wc-notice-functions.php b/includes/wc-notice-functions.php index 61f01704591..94a54c03943 100644 --- a/includes/wc-notice-functions.php +++ b/includes/wc-notice-functions.php @@ -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 ); } } diff --git a/tests/unit-tests/util/notice-functions.php b/tests/unit-tests/util/notice-functions.php index 01c43d821b0..1def7f5e835 100644 --- a/tests/unit-tests/util/notice-functions.php +++ b/tests/unit-tests/util/notice-functions.php @@ -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() ); } /**