From fb3c02f778b3ce1748337afd2a2464e7b7e92bc1 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Tue, 28 Feb 2023 10:15:21 -0300 Subject: [PATCH] Lint fix tests --- tests/bootstrap.php | 2 +- .../feature/TestBooleanSearchOperators.php | 12 ++-- tests/phpunit/feature/TestCoAuthorsPlus.php | 46 ++++++------ tests/phpunit/feature/TestMetaKeyPattern.php | 70 ++++++++++++++++--- .../TestWooCommerceSubscriptionSearch.php | 8 +-- tests/phpunit/indexables/TestUser.php | 23 +----- 6 files changed, 96 insertions(+), 65 deletions(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 5360a50..f4a6fcd 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -112,4 +112,4 @@ function skip_translations_api() { require_once $_tests_dir . '/includes/functions.php'; require_once $_tests_dir . '/includes/bootstrap.php'; require_once __DIR__ . '/phpunit/BaseTestCase.php'; -require_once __DIR__ . '/phpunit/factory/UserFactory.php'; \ No newline at end of file +require_once __DIR__ . '/phpunit/factory/UserFactory.php'; diff --git a/tests/phpunit/feature/TestBooleanSearchOperators.php b/tests/phpunit/feature/TestBooleanSearchOperators.php index dc2fd2d..800b161 100644 --- a/tests/phpunit/feature/TestBooleanSearchOperators.php +++ b/tests/phpunit/feature/TestBooleanSearchOperators.php @@ -23,7 +23,7 @@ class TestBooleanSearchOperators extends \WP_UnitTestCase { */ public function set_up() { $instance = new ElasticPressLabs\Feature\BooleanSearchOperators(); - \ElasticPress\Features::factory()->register_feature($instance); + \ElasticPress\Features::factory()->register_feature( $instance ); } /** @@ -44,8 +44,8 @@ protected function get_feature() { public function testConstruct() { $instance = $this->get_feature(); - $this->assertEquals( 'boolean_search_operators', $instance->slug ); - $this->assertEquals( 'Boolean Search Operators', $instance->title ); + $this->assertEquals( 'boolean_search_operators', $instance->slug ); + $this->assertEquals( 'Boolean Search Operators', $instance->title ); } /** @@ -56,7 +56,7 @@ public function testConstruct() { public function testBoxSummary() { ob_start(); $this->get_feature()->output_feature_box_summary(); - $output = ob_get_clean(); + $output = ob_get_clean(); $this->assertStringContainsString( 'Allow boolean operators in search queries', $output ); } @@ -69,7 +69,7 @@ public function testBoxSummary() { public function testBoxLong() { ob_start(); $this->get_feature()->output_feature_box_long(); - $output = ob_get_clean(); + $output = ob_get_clean(); $this->assertStringContainsString( 'Allows users to search using the following boolean operators:', $output ); } @@ -80,7 +80,7 @@ public function testBoxLong() { * @since 1.2.0 */ public function testQueryUsesBooleanOperators() { - $feature = $this->get_feature(); + $feature = $this->get_feature(); $this->assertTrue( $feature->query_uses_boolean_operators( '(museum (art))' ) ); $this->assertTrue( $feature->query_uses_boolean_operators( '"american museum"' ) ); diff --git a/tests/phpunit/feature/TestCoAuthorsPlus.php b/tests/phpunit/feature/TestCoAuthorsPlus.php index 6b77247..bc7bd8f 100644 --- a/tests/phpunit/feature/TestCoAuthorsPlus.php +++ b/tests/phpunit/feature/TestCoAuthorsPlus.php @@ -23,7 +23,7 @@ class TestCoAuthorsPlus extends \WP_UnitTestCase { */ public function set_up() { $instance = new ElasticPressLabs\Feature\CoAuthorsPlus(); - \ElasticPress\Features::factory()->register_feature($instance); + \ElasticPress\Features::factory()->register_feature( $instance ); } /** @@ -40,13 +40,13 @@ protected function get_feature() { * Get protected function as public * * @since 1.1.0 - * @param string $functionName - * @param string $className + * @param string $function_name Function name + * @param string $class_name Class name * @return ReflectionClass */ - protected function get_protected_function( $functionName, $className = 'ElasticPressLabs\Feature\CoAuthorsPlus' ) { - $reflector = new \ReflectionClass( $className ); - $function = $reflector->getMethod( $functionName ); + protected function get_protected_function( $function_name, $class_name = 'ElasticPressLabs\Feature\CoAuthorsPlus' ) { + $reflector = new \ReflectionClass( $class_name ); + $function = $reflector->getMethod( $function_name ); $function->setAccessible( true ); return $function; @@ -60,8 +60,8 @@ protected function get_protected_function( $functionName, $className = 'ElasticP public function testConstruct() { $instance = $this->get_feature(); - $this->assertEquals( 'co_authors_plus', $instance->slug ); - $this->assertEquals( 'Co-Authors Plus', $instance->title ); + $this->assertEquals( 'co_authors_plus', $instance->slug ); + $this->assertEquals( 'Co-Authors Plus', $instance->title ); } /** @@ -72,7 +72,7 @@ public function testConstruct() { public function testBoxSummary() { ob_start(); $this->get_feature()->output_feature_box_summary(); - $output = ob_get_clean(); + $output = ob_get_clean(); $this->assertStringContainsString( 'Add support for the Co-Authors Plus plugin in the Admin Post List screen by Author name', $output ); } @@ -85,7 +85,7 @@ public function testBoxSummary() { public function testBoxLong() { ob_start(); $this->get_feature()->output_feature_box_long(); - $output = ob_get_clean(); + $output = ob_get_clean(); $this->assertStringContainsString( 'If using the Co-Authors Plus plugin and the Protected Content feature, enable this feature to visit the Admin Post List screen by Author name wp-admin/edit.php?author_name=<name> and see correct results.', $output ); } @@ -96,12 +96,12 @@ public function testBoxLong() { * @since 1.1.0 */ public function testFilterOutAuthorNameAndId() { - $feature = $this->get_feature(); + $feature = $this->get_feature(); $function_filter_out_author_name_and_id_from_es_filter = $this->get_protected_function( 'filter_out_author_name_and_id_from_es_filter' ); - $this->assertEquals([], $function_filter_out_author_name_and_id_from_es_filter->invokeArgs( $feature, array([]))); + $this->assertEquals( [], $function_filter_out_author_name_and_id_from_es_filter->invokeArgs( $feature, array( [] ) ) ); - $this->assertEquals('', $function_filter_out_author_name_and_id_from_es_filter->invokeArgs( $feature, array( '' ) ) ); + $this->assertEquals( '', $function_filter_out_author_name_and_id_from_es_filter->invokeArgs( $feature, array( '' ) ) ); $formatted_args = [ 'post_filter' => [ @@ -109,12 +109,12 @@ public function testFilterOutAuthorNameAndId() { 'must' => [ [ 'term' => [ - 'post_author.display_name' => [ 'test' ] - ] - ] - ] - ] - ] + 'post_author.display_name' => [ 'test' ], + ], + ], + ], + ], + ], ]; $filtered_formatted_args = $function_filter_out_author_name_and_id_from_es_filter->invokeArgs( $feature, [ $formatted_args ] ); @@ -123,8 +123,8 @@ public function testFilterOutAuthorNameAndId() { $formatted_args['post_filter']['bool']['must'][] = [ 'terms' => [ - 'post_type.raw' => [ 'post' ] - ] + 'post_type.raw' => [ 'post' ], + ], ]; $filtered_formatted_args = $function_filter_out_author_name_and_id_from_es_filter->invokeArgs( $feature, [ $formatted_args ] ); @@ -135,8 +135,8 @@ public function testFilterOutAuthorNameAndId() { $formatted_args['post_filter']['bool']['must'][] = [ 'term' => [ - 'post_author.id' => [ 1 ] - ] + 'post_author.id' => [ 1 ], + ], ]; $filtered_formatted_args = $function_filter_out_author_name_and_id_from_es_filter->invokeArgs( $feature, [ $formatted_args ] ); diff --git a/tests/phpunit/feature/TestMetaKeyPattern.php b/tests/phpunit/feature/TestMetaKeyPattern.php index 0568264..03b3de5 100644 --- a/tests/phpunit/feature/TestMetaKeyPattern.php +++ b/tests/phpunit/feature/TestMetaKeyPattern.php @@ -16,49 +16,79 @@ class TestMetaKeyPattern extends \WP_UnitTestCase { /** * Setup each test. - * - * @since 3.5 */ public function set_up() { $instance = new ElasticPressLabs\Feature\MetaKeyPattern(); - \ElasticPress\Features::factory()->register_feature($instance); + \ElasticPress\Features::factory()->register_feature( $instance ); } + /** + * Get Meta Key Pattern feature + * + * @return MetaKeyPattern + */ protected function get_feature() { return \ElasticPress\Features::factory()->get_registered_feature( 'meta_key_pattern' ); } - protected function get_private_function( $functionName, $className = 'ElasticPressLabs\Feature\MetaKeyPattern' ) { - $reflector = new \ReflectionClass( $className ); - $function = $reflector->getMethod( $functionName ); + /** + * Get protected function as public + * + * @param string $function_name Function name + * @param string $class_name Class name + * @return ReflectionClass + */ + protected function get_private_function( $function_name, $class_name = 'ElasticPressLabs\Feature\MetaKeyPattern' ) { + $reflector = new \ReflectionClass( $class_name ); + $function = $reflector->getMethod( $function_name ); $function->setAccessible( true ); return $function; } + /** + * Test constrcut + * + * @group MetaKeyPattern + */ public function testConstruct() { $instance = $this->get_feature(); - $this->assertEquals( 'meta_key_pattern', $instance->slug ); - $this->assertEquals( 'Meta Key Pattern', $instance->title ); + $this->assertEquals( 'meta_key_pattern', $instance->slug ); + $this->assertEquals( 'Meta Key Pattern', $instance->title ); } + /** + * Test the `output_feature_box_summary` method. + * + * @group MetaKeyPattern + */ public function testBoxSummary() { ob_start(); $this->get_feature()->output_feature_box_summary(); - $output = ob_get_clean(); + $output = ob_get_clean(); $this->assertStringContainsString( 'Include or exclude meta key patterns.', $output ); } + /** + * Test the `output_feature_box_long` method. + * + * @group MetaKeyPattern + */ public function testBoxLong() { ob_start(); $this->get_feature()->output_feature_box_long(); - $output = ob_get_clean(); + $output = ob_get_clean(); $this->assertStringContainsString( 'This feature will give you the most control over the metadata indexed.', $output ); } + /** + * Test the `output_feature_box_settings` method. + * + * @group MetaKeyPattern + */ public function testOutputFeatureBoxSettings() { ob_start(); $this->get_feature()->output_feature_box_settings(); @@ -68,6 +98,11 @@ public function testOutputFeatureBoxSettings() { $this->assertStringContainsString( 'Deny patterns', $output ); } + /** + * Test the `is_match` method. + * + * @group MetaKeyPattern + */ public function testIsMatch() { $feature = $this->get_feature(); $function = $this->get_private_function( 'is_match' ); @@ -78,6 +113,11 @@ public function testIsMatch() { $this->assertFalse( $function->invokeArgs( $feature, array( 'meta_key_lorem', '//' ) ) ); } + /** + * Test the `has_delimiters` method. + * + * @group MetaKeyPattern + */ public function testHasDelimiters() { $feature = $this->get_feature(); $function = $this->get_private_function( 'has_delimiters' ); @@ -88,6 +128,11 @@ public function testHasDelimiters() { $this->assertFalse( $function->invokeArgs( $feature, array( 'm' ) ) ); } + /** + * Test the `remove_delimiters` method. + * + * @group MetaKeyPattern + */ public function testRemoveDelimiters() { $feature = $this->get_feature(); $function = $this->get_private_function( 'remove_delimiters' ); @@ -96,6 +141,11 @@ public function testRemoveDelimiters() { $this->assertEmpty( $function->invokeArgs( $feature, array( '//' ) ) ); } + /** + * Test the `prepare_regex` method. + * + * @group MetaKeyPattern + */ public function testPrepareRegex() { $feature = $this->get_feature(); $function = $this->get_private_function( 'prepare_regex' ); diff --git a/tests/phpunit/feature/TestWooCommerceSubscriptionSearch.php b/tests/phpunit/feature/TestWooCommerceSubscriptionSearch.php index 516f480..0c48e89 100644 --- a/tests/phpunit/feature/TestWooCommerceSubscriptionSearch.php +++ b/tests/phpunit/feature/TestWooCommerceSubscriptionSearch.php @@ -68,7 +68,7 @@ public function testSearchOnShopSubscriptionAdmin() { * Adding the order type, so WooCommerce can iterate of items (although inexistent) */ wc_register_order_type( 'shop_subscription', [] ); - + $subscription = new \WC_Order(); $subscription->set_billing_first_name( 'findme' ); $subscription->save(); @@ -84,9 +84,9 @@ public function testSearchOnShopSubscriptionAdmin() { $query = new \WP_Query(); $args = array( - 's' => 'findme', - 'post_type' => 'shop_subscription', - 'post_status' => 'wc-pending', + 's' => 'findme', + 'post_type' => 'shop_subscription', + 'post_status' => 'wc-pending', 'has_password' => true, ); diff --git a/tests/phpunit/indexables/TestUser.php b/tests/phpunit/indexables/TestUser.php index 7720711..be9ea27 100644 --- a/tests/phpunit/indexables/TestUser.php +++ b/tests/phpunit/indexables/TestUser.php @@ -93,7 +93,7 @@ public function createAndIndexUsers() { 'user_num' => 5, 'long_key' => 'here is a text field', ], - ], + ] ); $user_2 = $this->ep_factory->user->create( @@ -688,7 +688,7 @@ public function testUserQueryOrderbyUserNicename() { * We should not use a text/string field to sort * in Elasticsearch. * - * @return void * @group user + * @return void * @group user */ public function testFormatArgsOrderByUserNicename() { $user = new \ElasticPress\Indexable\User\User(); @@ -922,7 +922,6 @@ public function testUserQueryOrderDesc() { /** * Test meta query with simple args - * */ public function testUserMetaQuerySimple() { $this->createAndIndexUsers(); @@ -954,7 +953,6 @@ public function testUserMetaQuerySimple() { /** * Test meta query with simple args and meta_compare does not equal - * */ public function testUserMetaQuerySimpleCompare() { $this->createAndIndexUsers(); @@ -974,7 +972,6 @@ public function testUserMetaQuerySimpleCompare() { /** * Test meta query with no compare - * */ public function testUserMetaQueryNoCompare() { $this->createAndIndexUsers(); @@ -998,7 +995,6 @@ public function testUserMetaQueryNoCompare() { /** * Test meta query compare equals - * */ public function testUserMetaQueryCompareEquals() { $this->createAndIndexUsers(); @@ -1023,7 +1019,6 @@ public function testUserMetaQueryCompareEquals() { /** * Test meta query with multiple statements - * */ public function testUserMetaQueryMulti() { $this->createAndIndexUsers(); @@ -1051,7 +1046,6 @@ public function testUserMetaQueryMulti() { /** * Test meta query with multiple statements and relation OR - * */ public function testUserMetaQueryMultiRelationOr() { $this->createAndIndexUsers(); @@ -1079,7 +1073,6 @@ public function testUserMetaQueryMultiRelationOr() { /** * Test meta query with multiple statements and relation AND - * */ public function testUserMetaQueryMultiRelationAnd() { $this->createAndIndexUsers(); @@ -1107,7 +1100,6 @@ public function testUserMetaQueryMultiRelationAnd() { /** * Test basic user search - * */ public function testBasicUserSearch() { $this->createAndIndexUsers(); @@ -1125,7 +1117,6 @@ public function testBasicUserSearch() { /** * Test basic user search via user login - * */ public function testBasicUserSearchUserLogin() { $this->createAndIndexUsers(); @@ -1143,7 +1134,6 @@ public function testBasicUserSearchUserLogin() { /** * Test basic user search via user url - * */ public function testBasicUserSearchUserUrl() { $this->createAndIndexUsers(); @@ -1164,7 +1154,6 @@ public function testBasicUserSearchUserUrl() { /** * Test basic user search via meta - * */ public function testBasicUserSearchMeta() { $this->createAndIndexUsers(); @@ -1301,7 +1290,6 @@ public function testIntegrateSearchQueries() { /** * Test users that does not belong to any blog. - * */ public function testUserSearchLimitedToOneBlog() { // This user does not belong to any blog. @@ -1354,7 +1342,6 @@ public function testUserSearchLimitedToOneBlog() { /** * Test user query search by user login. - * */ public function testUserQueryUserLogin() { $this->createAndIndexUsers(); @@ -1375,7 +1362,6 @@ public function testUserQueryUserLogin() { /** * Test user query search by user nicename. - * */ public function testUserQueryUserNiceName() { $this->createAndIndexUsers(); @@ -1396,7 +1382,6 @@ public function testUserQueryUserNiceName() { /** * Test user query default orderby set to asc. - * */ public function testUserQueryDefaultOrderBy() { $this->createAndIndexUsers(); @@ -1429,7 +1414,6 @@ public function testUserQueryDefaultOrderBy() { /** * Test default order set to the score when orderby is set to empty - * */ public function testUserQueryDefaultOrder() { $this->createAndIndexUsers(); @@ -1461,7 +1445,6 @@ function( $preempt, $parsed_args, $url ) { /** * Test protected meta does not index. - * */ public function testProtectedMetaNotIndex() { @@ -1482,7 +1465,6 @@ public function testProtectedMetaNotIndex() { /** * Test whitelisted meta does index. - * */ public function testProtectedWhiteListMetaIndex() { @@ -1511,7 +1493,6 @@ function( $meta_keys ) { /** * Test query_db() function. - * */ public function testQueryDb() {