Skip to content

Commit

Permalink
Lint fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeelia committed Feb 28, 2023
1 parent 3ff14a7 commit fb3c02f
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 65 deletions.
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
require_once __DIR__ . '/phpunit/factory/UserFactory.php';
12 changes: 6 additions & 6 deletions tests/phpunit/feature/TestBooleanSearchOperators.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand All @@ -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 );
}

/**
Expand All @@ -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 );
}
Expand All @@ -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 );
}
Expand All @@ -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"' ) );
Expand Down
46 changes: 23 additions & 23 deletions tests/phpunit/feature/TestCoAuthorsPlus.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand All @@ -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;
Expand All @@ -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 );
}

/**
Expand All @@ -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 );
}
Expand All @@ -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 <code>wp-admin/edit.php?author_name=&lt;name&gt;</code> and see correct results.', $output );
}
Expand All @@ -96,25 +96,25 @@ 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' => [
'bool' => [
'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 ] );
Expand All @@ -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 ] );
Expand All @@ -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 ] );
Expand Down
70 changes: 60 additions & 10 deletions tests/phpunit/feature/TestMetaKeyPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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' );
Expand All @@ -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' );
Expand All @@ -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' );
Expand All @@ -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' );
Expand Down
8 changes: 4 additions & 4 deletions tests/phpunit/feature/TestWooCommerceSubscriptionSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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,
);

Expand Down
Loading

0 comments on commit fb3c02f

Please sign in to comment.