Skip to content

Commit

Permalink
Merge pull request #822 from WordPress/757-image-functions
Browse files Browse the repository at this point in the history
Change error type of NonEnqueuedImage in `ImageFunctions` sniff
  • Loading branch information
mukeshpanchal27 authored Dec 9, 2024
2 parents b7b19ce + e7e72e7 commit f23a0b4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function process_token( $stackPtr ) {

if ( preg_match_all( '#<img[^>]*(?<=src=)#', $content, $matches, \PREG_OFFSET_CAPTURE ) > 0 ) {
foreach ( $matches[0] as $match ) {
$this->phpcsFile->addError(
$this->phpcsFile->addWarning(
'Images should be added using wp_get_attachment_image() or similar functions',
$this->find_token_in_multiline_string( $stackPtr, $content, $match[1] ),
'NonEnqueuedImage'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ final class ImageFunctionsUnitTest extends AbstractSniffUnitTest {
* @return array <int line number> => <int number of errors>
*/
public function getErrorList() {
return array();
}

/**
* Returns the lines where warnings should occur.
*
* @return array <int line number> => <int number of warnings>
*/
public function getWarningList() {
return array(
1 => 1,
7 => 1,
Expand All @@ -32,13 +41,4 @@ public function getErrorList() {
25 => 1,
);
}

/**
* Returns the lines where warnings should occur.
*
* @return array <int line number> => <int number of warnings>
*/
public function getWarningList() {
return array();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public function test_run_with_errors() {

$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->assertNotEmpty( $warnings );
$this->assertArrayHasKey( 'load.php', $warnings );
$this->assertEquals( 2, $check_result->get_warning_count() );
}

public function test_run_without_errors() {
Expand All @@ -32,9 +32,9 @@ public function test_run_without_errors() {

$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 f23a0b4

Please sign in to comment.