Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing assertion #10

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
use WordPress\Plugin_Check\Checker\Check_Context;
use WordPress\Plugin_Check\Checker\Check_Result;
use WordPress\Plugin_Check\Checker\Checks\Late_Escaping_Check;
use WordPress\Plugin_Check\Test_Utils\TestCase\Advanced_UnitTestCase;

class Late_Escaping_Check_Tests extends WP_UnitTestCase {
class Late_Escaping_Check_Tests extends Advanced_UnitTestCase {

public function test_run_with_errors() {
$late_escape_check = new Late_Escaping_Check();
Expand All @@ -25,10 +26,7 @@ public function test_run_with_errors() {
$this->assertEquals( 1, $check_result->get_error_count() );

// Check for WordPress.Security.EscapeOutput error on Line no 24 and column no at 6.
$this->assertArrayHasKey( 24, $errors['load.php'] );
$this->assertArrayHasKey( 6, $errors['load.php'][24] );
$this->assertArrayHasKey( 'code', $errors['load.php'][24][6][0] );
$this->assertEquals( 'WordPress.Security.EscapeOutput.OutputNotEscaped', $errors['load.php'][24][6][0]['code'] );
$this->assertFileHasCodeInPosition( $errors, 'load.php', 'WordPress.Security.EscapeOutput.OutputNotEscaped', 24, 5 );
}

public function test_run_without_errors() {
Expand Down
21 changes: 21 additions & 0 deletions tests/phpunit/utils/TestCase/Advanced_UnitTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Abstract Advanced_UnitTestCase.
*
* @package plugin-check
*/

namespace WordPress\Plugin_Check\Test_Utils\TestCase;

use WP_UnitTestCase;

abstract class Advanced_UnitTestCase extends WP_UnitTestCase {

public function assertFileHasCodeInPosition( $actual, $file, $code, $line, $column ) {
$all_items = isset( $actual[ $file ][ $line ][ $column ] ) ? $actual[ $file ][ $line ][ $column ] : array();

$found = ! empty( $all_items ) ? wp_list_filter( $all_items, array( 'code' => $code ) ) : array();

$this->assertSame( count( $found ), 1, "Code {$code} could not be found in {$file} file in line {$line}, column {$column}." );
}
}