diff --git a/.editorconfig b/.editorconfig index c48f395e5..61ff4c938 100644 --- a/.editorconfig +++ b/.editorconfig @@ -30,6 +30,11 @@ insert_final_newline = false indent_style = space indent_size = 2 +[*.feature] +insert_final_newline = false +indent_style = space +indent_size = 2 + [*.yml] insert_final_newline = false indent_style = space diff --git a/includes/Checker/Checks/Abstract_File_Check.php b/includes/Checker/Checks/Abstract_File_Check.php index 8296576db..f4b046831 100644 --- a/includes/Checker/Checks/Abstract_File_Check.php +++ b/includes/Checker/Checks/Abstract_File_Check.php @@ -203,7 +203,9 @@ private static function get_files( Check_Context $plugin ) { // If the location is a plugin folder, get all its files. // Otherwise, it is a single-file plugin. - if ( $plugin->path() === $location ) { + if ( $plugin->is_single_file_plugin() ) { + self::$file_list_cache[ $location ][] = $location; + } else { $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $location ) ); foreach ( $iterator as $file ) { if ( ! $file->isFile() ) { @@ -229,8 +231,6 @@ private static function get_files( Check_Context $plugin ) { self::$file_list_cache[ $location ][] = $file_path; } } - } else { - self::$file_list_cache[ $location ][] = $location; } return self::$file_list_cache[ $location ]; diff --git a/includes/Checker/Checks/Plugin_Readme_Check.php b/includes/Checker/Checks/Plugin_Readme_Check.php index 5e638f295..4cd91def9 100644 --- a/includes/Checker/Checks/Plugin_Readme_Check.php +++ b/includes/Checker/Checks/Plugin_Readme_Check.php @@ -47,6 +47,11 @@ public function get_categories() { */ protected function check_files( Check_Result $result, array $files ) { + // Check if single file plugin, then bail early. + if ( $result->plugin()->is_single_file_plugin() ) { + return; + } + $plugin_relative_path = $result->plugin()->path(); // Filter the readme files. diff --git a/includes/Checker/Checks/Trademarks_Check.php b/includes/Checker/Checks/Trademarks_Check.php index c0febafdf..7c8093164 100644 --- a/includes/Checker/Checks/Trademarks_Check.php +++ b/includes/Checker/Checks/Trademarks_Check.php @@ -307,6 +307,11 @@ private function check_for_name_in_main_file( Check_Result $result ) { * @param Check_Result $result The Check Result to amend. */ private function check_for_slug( Check_Result $result ) { + // Check if single file plugin, then bail early. + if ( $result->plugin()->is_single_file_plugin() ) { + return; + } + $plugin_slug = basename( $result->plugin()->path() ); try { diff --git a/includes/Plugin_Context.php b/includes/Plugin_Context.php index 1ba4d9b5d..a64d5e43c 100644 --- a/includes/Plugin_Context.php +++ b/includes/Plugin_Context.php @@ -85,4 +85,17 @@ public function location() { return $path; } + + /** + * Checks if the plugin is a single file plugin without a dedicated directory. + * + * This is the case when the single file is directly placed within `wp-content/plugins`. + * + * @since n.e.x.t + * + * @return bool true if the single file plugin, otherwise false. + */ + public function is_single_file_plugin() { + return $this->path() !== $this->location(); + } } diff --git a/tests/behat/features/plugin-check.feature b/tests/behat/features/plugin-check.feature index 84f9e1cac..693660fe2 100644 --- a/tests/behat/features/plugin-check.feature +++ b/tests/behat/features/plugin-check.feature @@ -14,9 +14,17 @@ Feature: Test that the WP-CLI command works. When I try the WP-CLI command `plugin check hello.php` Then STDOUT should contain: - """ - mt_rand() is discouraged. - """ + """ + mt_rand() is discouraged. + """ + And STDOUT should not contain: + """ + no_plugin_readme + """ + And STDOUT should not contain: + """ + trademarked_term + """ And STDOUT should contain: """ All output should be run through an escaping function diff --git a/tests/phpunit/tests/Checker/Checks/Plugin_Readme_Check_Tests.php b/tests/phpunit/tests/Checker/Checks/Plugin_Readme_Check_Tests.php index 3b1ca8c58..6944db8aa 100644 --- a/tests/phpunit/tests/Checker/Checks/Plugin_Readme_Check_Tests.php +++ b/tests/phpunit/tests/Checker/Checks/Plugin_Readme_Check_Tests.php @@ -181,4 +181,20 @@ public function test_run_root_readme_file_without_errors() { $this->assertEquals( 0, $check_result->get_error_count() ); $this->assertEquals( 0, $check_result->get_warning_count() ); } + + public function test_single_file_plugin_without_error_for_trademarks() { + $readme_check = new Plugin_Readme_Check(); + $check_context = new Check_Context( WP_PLUGIN_DIR . '/single-file-plugin.php' ); + $check_result = new Check_Result( $check_context ); + + $readme_check->run( $check_result ); + + $errors = $check_result->get_errors(); + $warnings = $check_result->get_warnings(); + + $this->assertEmpty( $errors ); + $this->assertEmpty( $warnings ); + $this->assertSame( 0, $check_result->get_error_count() ); + $this->assertSame( 0, $check_result->get_warning_count() ); + } } diff --git a/tests/phpunit/tests/Checker/Checks/Trademarks_Check_Tests.php b/tests/phpunit/tests/Checker/Checks/Trademarks_Check_Tests.php index d6babf67c..1d9976ccf 100644 --- a/tests/phpunit/tests/Checker/Checks/Trademarks_Check_Tests.php +++ b/tests/phpunit/tests/Checker/Checks/Trademarks_Check_Tests.php @@ -108,4 +108,21 @@ public function test_trademarks_with_for_woocommerce_exceptions() { $this->assertEmpty( $errors ); $this->assertSame( 0, $check_result->get_error_count() ); } + + public function test_single_file_plugin_without_error_for_trademarks() { + $trademarks_check = new Trademarks_Check(); + $check_context = new Check_Context( WP_PLUGIN_DIR . '/single-file-plugin.php' ); + $check_result = new Check_Result( $check_context ); + + $trademarks_check->run( $check_result ); + + $errors = $check_result->get_errors(); + $warnings = $check_result->get_warnings(); + + $this->assertEmpty( $errors ); + $this->assertEmpty( $warnings ); + + $this->assertSame( 0, $check_result->get_error_count() ); + $this->assertSame( 0, $check_result->get_warning_count() ); + } } diff --git a/tests/phpunit/tests/Plugin_Context_Tests.php b/tests/phpunit/tests/Plugin_Context_Tests.php index 688124481..e930aecb0 100644 --- a/tests/phpunit/tests/Plugin_Context_Tests.php +++ b/tests/phpunit/tests/Plugin_Context_Tests.php @@ -55,4 +55,11 @@ public function test_location_with_single_file_plugin() { $this->assertSame( $single_file, $context->location() ); } + + public function test_is_single_file_plugin() { + $single_file = WP_PLUGIN_DIR . '/single-file-plugin.php'; + $context = new Plugin_Context( $single_file ); + + $this->assertTrue( $context->is_single_file_plugin() ); + } }