Skip to content

Commit

Permalink
break out filter tests from function tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuadavidnelson committed Jan 13, 2024
1 parent 80430cd commit 01b47b2
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions tests/php/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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';
},
Expand All @@ -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' )
Expand All @@ -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 )
Expand Down Expand Up @@ -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' )
Expand Down

0 comments on commit 01b47b2

Please sign in to comment.