Skip to content

Commit

Permalink
Add tests for plugin header requires check
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Jan 29, 2024
1 parent 4962e94 commit 41e6942
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 0 deletions.
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
*/
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.
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
*/
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.

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() );
}
}

0 comments on commit 41e6942

Please sign in to comment.