-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for plugin header requires check
- Loading branch information
1 parent
4962e94
commit 41e6942
Showing
5 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
tests/phpunit/testdata/plugins/test-plugin-header-requires-errors/load.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
/** | ||
* Plugin Name: Test Plugin Header Requires Errors | ||
* Plugin URI: https://github.com/WordPress/plugin-check | ||
* Description: Test plugin for the Plugin Header Requires check. | ||
* Version: 1.0.0 | ||
* Author: WordPress Performance Team | ||
* Author URI: https://make.wordpress.org/performance/ | ||
* License: GPLv2 or later | ||
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html | ||
* Text Domain: test-plugin-header-requires-errors | ||
* | ||
* @package test-plugin-header-requires-errors | ||
*/ |
10 changes: 10 additions & 0 deletions
10
tests/phpunit/testdata/plugins/test-plugin-header-requires-errors/readme.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
=== Test Plugin Header Requires Errors === | ||
|
||
Contributors: plugin-check | ||
Tested up to: 6.1 | ||
Stable tag: 1.0.0 | ||
License: GPLv2 or later | ||
License URI: https://www.gnu.org/licenses/gpl-2.0.html | ||
Tags: testing, security | ||
|
||
Plugin description. |
14 changes: 14 additions & 0 deletions
14
tests/phpunit/testdata/plugins/test-plugin-header-requires-without-errors/load.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
/** | ||
* Plugin Name: Test Plugin Header Requires Without Errors | ||
* Plugin URI: https://github.com/WordPress/plugin-check | ||
* Description: Test plugin for the Plugin Header Requires check. | ||
* Version: 1.0.0 | ||
* Author: WordPress Performance Team | ||
* Author URI: https://make.wordpress.org/performance/ | ||
* License: GPLv2 or later | ||
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html | ||
* Text Domain: test-plugin-header-requires-without-errors | ||
* | ||
* @package test-plugin-header-requires-without-errors | ||
*/ |
13 changes: 13 additions & 0 deletions
13
tests/phpunit/testdata/plugins/test-plugin-header-requires-without-errors/readme.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
=== Test Plugin Header Requires Without Errors === | ||
|
||
Contributors: plugin-check | ||
Tested up to: 6.1 | ||
Requires at least: 6.0 | ||
Requires PHP: 5.6 | ||
Stable tag: 1.0.0 | ||
License: GPLv2 or later | ||
License URI: https://www.gnu.org/licenses/gpl-2.0.html | ||
Tags: testing, security | ||
|
||
Plugin description. | ||
|
53 changes: 53 additions & 0 deletions
53
tests/phpunit/tests/Checker/Checks/Plugin_Header_Requires_Check_Tests.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
/** | ||
* Tests for the Plugin_Header_Requires_Check class. | ||
* | ||
* @package plugin-check | ||
*/ | ||
|
||
use WordPress\Plugin_Check\Checker\Check_Context; | ||
use WordPress\Plugin_Check\Checker\Check_Result; | ||
use WordPress\Plugin_Check\Checker\Checks\Plugin_Header_Requires_Check; | ||
|
||
class Plugin_Header_Requires_Check_Tests extends WP_UnitTestCase { | ||
|
||
public function test_run_with_errors() { | ||
$check = new Plugin_Header_Requires_Check(); | ||
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-header-requires-errors/load.php' ); | ||
$check_result = new Check_Result( $check_context ); | ||
|
||
$check->run( $check_result ); | ||
|
||
$errors = $check_result->get_errors(); | ||
$warnings = $check_result->get_warnings(); | ||
|
||
$this->assertNotEmpty( $errors ); | ||
$this->assertArrayHasKey( 'load.php', $errors ); | ||
$this->assertEquals( 2, $check_result->get_error_count() ); | ||
$this->assertEmpty( $warnings ); | ||
$this->assertEquals( 0, $check_result->get_warning_count() ); | ||
|
||
$this->assertArrayHasKey( 0, $errors['load.php'] ); | ||
$this->assertArrayHasKey( 0, $errors['load.php'][0] ); | ||
$this->assertArrayHasKey( 'code', $errors['load.php'][0][0][0] ); | ||
$this->assertEquals( 'missing_plugin_header', $errors['load.php'][0][0][0]['code'] ); | ||
$this->assertArrayHasKey( 'code', $errors['load.php'][0][0][1] ); | ||
$this->assertEquals( 'missing_plugin_header', $errors['load.php'][0][0][1]['code'] ); | ||
} | ||
|
||
public function test_run_without_errors() { | ||
$check = new Plugin_Header_Requires_Check(); | ||
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-header-requires-without-errors/load.php' ); | ||
$check_result = new Check_Result( $check_context ); | ||
|
||
$check->run( $check_result ); | ||
|
||
$errors = $check_result->get_errors(); | ||
$warnings = $check_result->get_warnings(); | ||
|
||
$this->assertEmpty( $errors ); | ||
$this->assertEquals( 0, $check_result->get_error_count() ); | ||
$this->assertEmpty( $warnings ); | ||
$this->assertEquals( 0, $check_result->get_warning_count() ); | ||
} | ||
} |