From 01b47b24859c6605470f46f5756db52964bbea76 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Tue, 26 Dec 2023 12:03:01 -0800 Subject: [PATCH] break out filter tests from function tests --- tests/php/FunctionsTest.php | 41 +++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/tests/php/FunctionsTest.php b/tests/php/FunctionsTest.php index ca34b3e..c1732e9 100644 --- a/tests/php/FunctionsTest.php +++ b/tests/php/FunctionsTest.php @@ -40,7 +40,7 @@ public function test_aps_is_frontend() { // Return false, then true. \WP_Mock::userFunction( 'is_admin', array( - 'times' => 2, + 'times' => 2, 'return_in_order' => array( false, true, @@ -64,7 +64,7 @@ public function test_aps_current_user_can_view() { // Mock the current_user_can() function. \WP_Mock::userFunction( 'current_user_can', array( - 'times' => 2, + 'times' => 1, 'return' => function( $capability ) { return $capability === 'read_private_posts'; }, @@ -77,6 +77,25 @@ public function test_aps_current_user_can_view() { // Confirm the default condition is true. $this->assertTrue( aps_current_user_can_view() ); + } + + /** + * Test the aps_current_user_can_view() filter. + * + * @since 0.3.9 + */ + public function test_aps_current_user_can_view_filter() { + + // Mock the current_user_can() function. + \WP_Mock::userFunction( + 'current_user_can', array( + 'times' => 1, + 'return' => function( $capability ) { + return $capability === 'read_private_posts'; + }, + ) + ); + // Pass false to the filter. WP_Mock::onFilter( 'aps_default_read_capability' ) ->with( 'read_private_posts' ) @@ -100,6 +119,15 @@ public function test_aps_is_read_only() { // Confirm default condition is true. $this->assertTrue( aps_is_read_only() ); + } + + /** + * Test the aps_is_read_only() function filters. + * + * @since 0.3.9 + */ + public function test_aps_is_read_only_filters() { + // Pass false to the filter. WP_Mock::onFilter( 'aps_is_read_only' ) ->with( true ) @@ -157,6 +185,15 @@ public function test_aps_is_excluded_post_type() { $this->assertTrue( aps_is_excluded_post_type( 'attachment' ) ); $this->assertFalse( aps_is_excluded_post_type( 'post' ) ); + } + + /** + * Test the aps_is_excluded_post_type() function filters. + * + * @since 0.3.9 + */ + public function test_aps_is_excluded_post_type_filters() { + // Pass false to the filter. WP_Mock::onFilter( 'aps_excluded_post_types' ) ->with( 'attachment' )