| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
use MediaWiki\MainConfigNames; |
| 22 |
use MediaWiki\Parser\Parsoid\LintErrorChecker; |
| 23 |
use MediaWiki\Registration\ExtensionRegistry; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
class LintErrorCheckerTest extends MediaWikiIntegrationTestCase { |
| 31 |
|
| 32 |
protected function setUp(): void { |
| 33 |
parent::setUp(); |
| 34 |
$this->overrideConfigValue( MainConfigNames::ParsoidSettings, [ |
| 35 |
'linting' => true |
| 36 |
] ); |
| 37 |
$this->overrideConfigValue( 'LinterCategories', [ |
| 38 |
|
| 39 |
] ); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
protected function getLintErrorChecker() { |
| 47 |
$services = $this->getServiceContainer(); |
| 48 |
$extReg = $this->createMock( ExtensionRegistry::class ); |
| 49 |
$extReg->method( 'isLoaded' )->willReturnCallback( static function ( string $which ) { |
| 50 |
return $which == 'Linter'; |
| 51 |
} ); |
| 52 |
|
| 53 |
return new LintErrorChecker( |
| 54 |
$services->get( '_Parsoid' ), |
| 55 |
$services->getParsoidPageConfigFactory(), |
| 56 |
$services->getTitleFactory(), |
| 57 |
$extReg, |
| 58 |
$services->getMainConfig(), |
| 59 |
); |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public function testCheck( $wikitext, $expected ) { |
| 66 |
$errors = $this->getLintErrorChecker()->check( $wikitext ); |
| 67 |
$this->assertSame( $expected, $errors ); |
| 68 |
} |
| 69 |
|
| 70 |
public static function provideCheck() { |
| 71 |
yield 'Perfect' => [ '<strong>Foo</strong>', [] ]; |
| 72 |
yield 'Unclosed tag' => [ |
| 73 |
'<strong>Foo', |
| 74 |
[ |
| 75 |
[ |
| 76 |
'type' => 'missing-end-tag', |
| 77 |
'dsr' => [ 0, 11, 8, 0 ], |
| 78 |
'templateInfo' => null, |
| 79 |
'params' => [ |
| 80 |
'name' => 'strong', |
| 81 |
'inTable' => false, |
| 82 |
] |
| 83 |
] |
| 84 |
] |
| 85 |
]; |
| 86 |
} |
| 87 |
|
| 88 |
public function testCheckSome() { |
| 89 |
|
| 90 |
$errors = $this->getLintErrorChecker()->checkSome( '<strong>Foo', [ 'missing-end-tag' ] ); |
| 91 |
$this->assertSame( [], $errors ); |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
public function testLinterCategory() { |
| 96 |
$input = '<font color="red">RED</font>'; |
| 97 |
$errors = $this->getLintErrorChecker()->check( $input ); |
| 98 |
$this->assertEquals( 'obsolete-tag', $errors[0]['type'] ); |
| 99 |
|
| 100 |
|
| 101 |
$this->overrideConfigValue( 'LinterCategories', [ |
| 102 |
'obsolete-tag' => [ 'priority' => 'none' ], |
| 103 |
] ); |
| 104 |
|
| 105 |
$errors = $this->getLintErrorChecker()->check( $input ); |
| 106 |
$this->assertSame( [], $errors ); |
| 107 |
} |
| 108 |
} |