Skip to content

Commit

Permalink
Fixed tests per our refactoring process.
Browse files Browse the repository at this point in the history
Now that we've refactored the FilterWPQuery class and its
interface, the test suites need to be updated too.

1. Rename the callback method.
2. Pass in the postsOrNull input to shouldFilter.
  • Loading branch information
hellofromtonya committed Apr 25, 2018
1 parent 2c2f728 commit 119a1a8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Tests/Integration/FilterWPQueryTest.php
Expand Up @@ -28,7 +28,7 @@ public function testAddFilter()
//Make sure addFilter() had the right effect -- it was added with priority 10
$this->assertEquals(
FilterWPQuery::getFilterPriority(),
has_filter('posts_pre_query', [FilterWPQuery::class, 'callback'])
has_filter('posts_pre_query', [FilterWPQuery::class, 'filterPreQuery'])
);
}

Expand All @@ -44,7 +44,7 @@ public function testFilterRemoved()
//Remove and test return type
$this->assertTrue(FilterWPQuery::removeFilter());
//Make sure removeFilter() had the right effect -- the filter was removed
$this->assertFalse(has_filter('posts_pre_query', [FilterWPQuery::class, 'callback']));
$this->assertFalse(has_filter('posts_pre_query', [FilterWPQuery::class, 'filterPreQuery']));
}


Expand All @@ -62,7 +62,7 @@ public function testNotFilteringByDefault()
//Add filter
FilterWPQuery::addFilter();
//Test that the filter SHOULD not do anything
$this->assertFalse(FilterWPQuery::shouldFilter());
$this->assertFalse(FilterWPQuery::shouldFilter([]));
//Query for all posts -- should only be one post, the one we just created.
$query = new \WP_Query(['post_type' => 'post']);
$this->assertFalse(empty($query->posts));
Expand Down
4 changes: 2 additions & 2 deletions Tests/Integration/RestRequestTest.php
Expand Up @@ -20,7 +20,7 @@ public function testShouldFilter()
$request = new \WP_REST_Request('GET', '/wp/v2/posts');
rest_api_loaded();
//Make sure the method returns true
$this->assertTrue(FilterWPQuery::shouldFilter());
$this->assertTrue(FilterWPQuery::shouldFilter(null));
}


Expand All @@ -34,7 +34,7 @@ public function testFilteringRESTRequest()
{
//Setup filter
AlwaysFilterWPQuery::addFilter();
$this->assertTrue(AlwaysFilterWPQuery::shouldFilter());
$this->assertTrue(AlwaysFilterWPQuery::shouldFilter(null));

//Create a request
$request = new \WP_REST_Request('GET', '/wp/v2/posts');
Expand Down
4 changes: 2 additions & 2 deletions Tests/Mock/AlwaysFilterWPQuery.php
Expand Up @@ -7,9 +7,9 @@ class AlwaysFilterWPQuery extends \CalderaLearn\RestSearch\FilterWPQuery
{

/** @inheritdoc */
public static function shouldFilter(): bool
public static function shouldFilter($postsOrNull): bool
{
return true;
return is_null($postsOrNull);
}

/** @inheritdoc */
Expand Down
4 changes: 2 additions & 2 deletions Tests/Mock/FilterWPQuery.php
Expand Up @@ -13,9 +13,9 @@
class FilterWPQuery extends \CalderaLearn\RestSearch\FilterWPQuery
{
/** @inheritdoc */
public static function shouldFilter() :bool
public static function shouldFilter($postsOrNull) :bool
{
return true;
return is_null($postsOrNull);
}

/** @inheritdoc */
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/FilterWPQueryTest.php
Expand Up @@ -68,7 +68,7 @@ public function testGetPostsArePosts()
*/
public function testShouldFilter()
{
$this->assertTrue(FilterWPQuery::shouldFilter());
$this->assertTrue(FilterWPQuery::shouldFilter(null));
}

/**
Expand Down

0 comments on commit 119a1a8

Please sign in to comment.