Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| LinterTag | |
0.00% |
0 / 20 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
| sourceToDom | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
| lintHandler | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getConfig | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | declare( strict_types = 1 ); |
| 3 | |
| 4 | namespace Wikimedia\Parsoid\Mocks; |
| 5 | |
| 6 | use Wikimedia\Parsoid\DOM\DocumentFragment; |
| 7 | use Wikimedia\Parsoid\DOM\Element; |
| 8 | use Wikimedia\Parsoid\Ext\ExtensionModule; |
| 9 | use Wikimedia\Parsoid\Ext\ExtensionTagHandler; |
| 10 | use Wikimedia\Parsoid\Ext\ParsoidExtensionAPI; |
| 11 | |
| 12 | class LinterTag extends ExtensionTagHandler implements ExtensionModule { |
| 13 | /** @inheritDoc */ |
| 14 | public function sourceToDom( |
| 15 | ParsoidExtensionAPI $extApi, string $content, array $args |
| 16 | ): DocumentFragment { |
| 17 | $documentFragment = $extApi->extTagToDOM( $args, $content, [ |
| 18 | 'wrapperTag' => 'div', |
| 19 | ] ); |
| 20 | $doc = $documentFragment->ownerDocument; |
| 21 | $linterTag = $doc->createElement( 'div' ); |
| 22 | // <center> is an obsolete tag |
| 23 | $center = $doc->createElement( 'center' ); |
| 24 | $center->appendChild( $doc->createTextNode( 'ccc' ) ); |
| 25 | $linterTag->appendChild( $center ); |
| 26 | $linterTag->appendChild( $documentFragment->firstChild ); |
| 27 | // Now we have <div><center>...</center><div>...</div></div> in $linterTag |
| 28 | $documentFragment->appendChild( $linterTag ); |
| 29 | return $documentFragment; |
| 30 | } |
| 31 | |
| 32 | /** @inheritDoc */ |
| 33 | public function lintHandler( |
| 34 | ParsoidExtensionAPI $extApi, Element $linterTag, callable $defaultHandler |
| 35 | ): bool { |
| 36 | // We don't want to lint <center> from above |
| 37 | $wrapperTag = $linterTag->firstChild->nextSibling; |
| 38 | $defaultHandler( $wrapperTag ); |
| 39 | return true; |
| 40 | } |
| 41 | |
| 42 | /** @inheritDoc */ |
| 43 | public function getConfig(): array { |
| 44 | return [ |
| 45 | 'name' => 'LinterTag', |
| 46 | 'tags' => [ |
| 47 | [ 'name' => 'linter', 'handler' => self::class ], |
| 48 | ], |
| 49 | ]; |
| 50 | } |
| 51 | } |