session->set( 'wc_notices', null ); } /** * Test wc_notice_count(). * * @since 2.2 */ function test_wc_notice_count() { // no error notices $this->assertEquals( 0, wc_notice_count( 'error' ) ); // single notice wc_add_notice( 'Bogus Notice', 'success' ); $this->assertEquals( 1, wc_notice_count() ); // specific notice 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' ); wc_add_notice( 'Bogus Error Notice 2', 'error' ); $this->assertEquals( 4, wc_notice_count() ); } /** * Test wc_has_notice(). * * @since 2.2 */ function test_wc_has_notice() { // negative wc_add_notice( 'Bogus Notice', 'success' ); $this->assertFalse( wc_has_notice( 'Legit Notice' ) ); // positive wc_add_notice( 'One True Notice', 'notice' ); $this->assertTrue( wc_has_notice( 'One True Notice', 'notice' ) ); } /** * Test wc_notice_add_notice(). * * @since 2.2 */ function test_wc_add_notice() { // default type wc_add_notice( 'Test Notice' ); $notices = wc_get_notices(); $this->assertArrayHasKey( 'success', $notices ); $this->assertEquals( 'Test Notice', $notices['success'][0] ); // clear notices WC()->session->set( 'wc_notices', null ); // specific type wc_add_notice( 'Test Error Notice', 'error' ); $notices = wc_get_notices(); $this->assertArrayHasKey( 'error', $notices ); $this->assertEquals( 'Test Error Notice', $notices['error'][0] ); } /** * Test wc_clear_notices(). * * @since 2.2 */ function test_wc_clear_notices() { wc_add_notice( 'Test Notice' ); wc_clear_notices(); $this->assertEmpty( WC()->session->get( 'wc_notices' ) ); } /** * Test wc_print_notices(). * * @since 2.2 */ public function test_wc_print_notices() { wc_add_notice( 'One True Notice', 'notice' ); $this->expectOutputString( '