Skip to content

Commit

Permalink
Address feedback for unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mukeshpanchal27 committed Oct 16, 2023
1 parent 0829172 commit eb3f667
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions tests/phpunit/Checker/Checks/Trademarks_Check_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public function test_trademarks_without_errors() {
$this->assertEmpty( $errors );
$this->assertEmpty( $warnings );

$this->assertEquals( 0, $check_result->get_error_count() );
$this->assertEquals( 0, $check_result->get_warning_count() );
$this->assertSame( 0, $check_result->get_error_count() );
$this->assertSame( 0, $check_result->get_warning_count() );
}

/**
* @dataProvider data_trademarks_check
*/
public function test_trademarks_with_different_scenarios( $type_flag, $plugin_basename, $expected_file, $expected_code ) {
public function test_trademarks_with_different_scenarios( $type_flag, $plugin_basename, $expected_file, $expected_error ) {
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . $plugin_basename );
$check_result = new Check_Result( $check_context );

Expand All @@ -40,18 +40,13 @@ public function test_trademarks_with_different_scenarios( $type_flag, $plugin_ba

$errors = $check_result->get_errors();

if ( $expected_code ) {
$this->assertNotEmpty( $errors );
$this->assertArrayHasKey( $expected_file, $errors );
$this->assertSame( 1, $check_result->get_error_count() );

$this->assertTrue( isset( $errors[ $expected_file ][0][0][0] ) );
$this->assertSame( 'trademarked_term', $errors[ $expected_file ][0][0][0]['code'] );
$this->assertStringContainsString( $expected_code, $errors[ $expected_file ][0][0][0]['message'] );
} else {
$this->assertEmpty( $errors );
$this->assertEquals( 0, $check_result->get_error_count() );
}
$this->assertNotEmpty( $errors );
$this->assertArrayHasKey( $expected_file, $errors );
$this->assertSame( 1, $check_result->get_error_count() );

$this->assertTrue( isset( $errors[ $expected_file ][0][0][0] ) );
$this->assertSame( 'trademarked_term', $errors[ $expected_file ][0][0][0]['code'] );
$this->assertSame( $expected_error, $errors[ $expected_file ][0][0][0]['message'] );
}

public function data_trademarks_check() {
Expand All @@ -60,50 +55,57 @@ public function data_trademarks_check() {
Trademarks_Check::TYPE_README,
'test-trademarks-plugin-readme-errors/load.php',
'readme.txt',
'"plugin"',
'The plugin name includes a restricted term. Your chosen plugin name - <code> Test Plugin with readme </code> - contains the restricted term "plugin" which cannot be used at all in your plugin name.',
),
'Plugin header - Test Trademarks Plugin Header Name Errors' => array(
Trademarks_Check::TYPE_NAME,
'test-trademarks-plugin-header-name-errors/load.php',
'load.php',
'"plugin"',
'The plugin name includes a restricted term. Your chosen plugin name - <code>Test Trademarks Plugin Header Name Errors</code> - contains the restricted term "plugin" which cannot be used at all in your plugin name.',
),
'Plugin slug - test-trademarks-plugin-header-slug-errors' => array(
Trademarks_Check::TYPE_SLUG,
'test-trademarks-plugin-header-slug-errors/load.php',
'load.php',
'"plugin"',
'The plugin slug includes a restricted term. Your plugin slug - <code>test-trademarks-plugin-header-slug-errors</code> - contains the restricted term "plugin" which cannot be used at all in your plugin slug.',
),
'Plugin headers - WooCommerce Example String' => array(
Trademarks_Check::TYPE_NAME,
'test-trademarks-plugin-header-woocommerce-string/load.php',
'load.php',
'"woocommerce"',
),
'Plugin headers - Example String for WooCommerce' => array(
Trademarks_Check::TYPE_NAME,
'test-trademarks-plugin-header-example-string-for-woocommerce/load.php',
'load.php',
'',
'The plugin name includes a restricted term. Your chosen plugin name - <code>WooCommerce Example String</code> - contains the restricted term "woocommerce" which cannot be used within in your plugin name, unless your plugin name ends with "for woocommerce". The term must still not appear anywhere else in your name.',
),
'Plugin headers - WooCommerce String for WooCommerce' => array(
Trademarks_Check::TYPE_NAME,
'test-trademarks-plugin-header-woocommerce-string-for-woocommerce/load.php',
'load.php',
'"woocommerce"',
'The plugin name includes a restricted term. Your chosen plugin name - <code>WooCommerce String for WooCommerce</code> - contains the restricted term "woocommerce" which cannot be used within in your plugin name, unless your plugin name ends with "for woocommerce". The term must still not appear anywhere else in your name.',
),
'Plugin headers - WordPress String for WooCommerce' => array(
Trademarks_Check::TYPE_NAME,
'test-trademarks-plugin-header-wordpress-string-for-woocommerce/load.php',
'load.php',
'"wordpress"',
'The plugin name includes a restricted term. Your chosen plugin name - <code>WordPress String for WooCommerce</code> - contains the restricted term "wordpress" which cannot be used at all in your plugin name.',
),
'Plugin headers portmanteaus' => array(
Trademarks_Check::TYPE_NAME,
'test-trademarks-plugin-header-portmanteaus/load.php',
'load.php',
'"woo"',
'The plugin name includes a restricted term. Your chosen plugin name - <code>WooXample</code> - contains the restricted term "woo" which cannot be used at all in your plugin name.',
),
);
}

public function test_trademarks_with_for_woocommerce_exceptions() {
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-trademarks-plugin-header-example-string-for-woocommerce/load.php' );
$check_result = new Check_Result( $check_context );

$check = new Trademarks_Check( Trademarks_Check::TYPE_NAME );
$check->run( $check_result );

$errors = $check_result->get_errors();

$this->assertEmpty( $errors );
$this->assertSame( 0, $check_result->get_error_count() );
}
}

0 comments on commit eb3f667

Please sign in to comment.