1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace dlindberg\BlobChunk\Manager; |
||
6 | |||
7 | use dlindberg\BlobChunk\Manager\Config as Config; |
||
8 | use dlindberg\DOMDocumentFactory\DOMDocumentFactory; |
||
9 | use dlindberg\DOMDocumentFactory\DOMDocumentFactoryConfig; |
||
10 | |||
11 | final class NodeCheckerAltDataTest extends \PHPUnit\Framework\TestCase |
||
12 | { |
||
13 | /** |
||
14 | * @var array |
||
15 | */ |
||
16 | private $testData = [ |
||
17 | [ |
||
18 | 'group' => 'parents', |
||
19 | 'attributes' => [['name' => 'id', 'value' => "a"], ['name' => 'class', 'value' => "b"],], |
||
20 | ], |
||
21 | [ |
||
22 | 'group' => 'specials', |
||
23 | 'attributes' => [['name' => 'id', 'value' => 'c'], ['name' => 'class', 'value' => 'd'],], |
||
24 | ], |
||
25 | [ |
||
26 | 'group' => 'rowCol', |
||
27 | [ |
||
28 | 'parent' => ['type' => 'attribute', 'name' => 'class', 'value' => 'e',], |
||
29 | 'colDefs' => ['type' => 'tag', 'value' => 'thead',], |
||
30 | 'rowsGroup' => ['type' => 'tag', 'value' => 'tbody',], |
||
31 | 'row' => ['type' => 'tag', 'value' => 'tr',], |
||
32 | ], |
||
33 | ], |
||
34 | [ |
||
35 | 'group' => 'recursive', |
||
36 | 'parents' => [ |
||
37 | 'attributes' => [ |
||
38 | ['name' => 'id', 'value' => 'f'], |
||
39 | ['name' => 'class', 'value' => 'g'], |
||
40 | ], |
||
41 | ], |
||
42 | 'children' => ['tags' => ['li',],], |
||
43 | ], |
||
44 | [ |
||
45 | 'group' => 'pairs', |
||
46 | [ |
||
47 | 'parent' => ['type' => 'attribute', 'name' => 'class', 'value' => 'h',], |
||
48 | 'a' => ['type' => 'tag', 'value' => 'dt',], |
||
49 | 'b' => ['type' => 'tag', 'value' => 'dd',], |
||
50 | ], |
||
51 | ], |
||
52 | [ |
||
53 | 'group' => 'splits', |
||
54 | 'what' => [ |
||
55 | 'tags' => ['p'], |
||
56 | 'attributes' => [['name' => 'id', 'value' => 'i'], ['name' => 'class', 'value' => 'j'],], |
||
57 | ], |
||
58 | 'on' => ['. ', '? ', '! '], |
||
59 | ], |
||
60 | ]; |
||
61 | |||
62 | /** |
||
63 | * @var Config |
||
64 | */ |
||
65 | private $config; |
||
66 | /** |
||
67 | * @var DOMDocumentFactory |
||
68 | */ |
||
69 | private $docFactory; |
||
70 | |||
71 | /** |
||
72 | * @var string[] |
||
73 | */ |
||
74 | private $samples = [ |
||
75 | '<div>test Div</div><p>One Sentence only.</p>', |
||
76 | '<h1>Sample H1</h1><h2>Sample h2</h2><h3>sample h3</h3><h4>sample h4</h4><h5>sample h5</h5><h6>sample h6</h6>', |
||
77 | '<p>Sample paragraph. Second sentence</p>', |
||
78 | '<ul><li>sample list</li></ul><ol><li>sample ordered item</li></ol>', |
||
79 | '<p><strong>strong thing</strong> <em>emphasized</em> <b>emphasized</b> <i>emphasized</i></p>', |
||
80 | '<p><a href="#">Sample Link</a></p>', |
||
81 | '<div><p>Test P</p></div>', |
||
82 | '<table><tr><td>test</td><td>test</td></tr></table>', |
||
83 | '<dl><dt>sample term</dt><dd>sample def</dd></dl><dl>', |
||
84 | '<div id="a">Test side one</div><div class="b">test side tow</div>', |
||
85 | '<div id="c">Test side one</div><div class="d">test side two</div>', |
||
86 | '<div id="i">Test side one</div><div class="j">test side two</div><div class="e">test e table</div>', |
||
87 | '<div id="f">Test side one</div><div class="g">test side two</div><div class="h">test side three</div>', |
||
88 | ]; |
||
89 | /** |
||
90 | * @var \DOMElement[] |
||
91 | */ |
||
92 | private $samplesDocs = []; |
||
93 | |||
94 | public function __construct(?string $name = null, array $data = [], string $dataName = '') |
||
95 | { |
||
96 | parent::__construct($name, $data, $dataName); |
||
97 | $this->config = new Config($this->testData); |
||
98 | $pureConfig = \HTMLPurifier_Config::createDefault(); |
||
99 | $pureConfig->set('Attr.EnableID', true); |
||
100 | $this->docFactory = new DOMDocumentFactory( |
||
101 | (new DOMDocumentFactoryConfig())->setInputPurifier(new \HTMLPurifier($pureConfig)) |
||
102 | ); |
||
103 | $this->samplesDocs = \array_map(function ($sample) { |
||
104 | return $this->docFactory->getNode($sample); |
||
105 | }, $this->samples); |
||
106 | } |
||
107 | |||
108 | public function testNameGroup() |
||
109 | { |
||
110 | $sort = new NodeCheckChecker($this->config); |
||
0 ignored issues
–
show
|
|||
111 | $this->assertEquals('parent', $sort->nameGroup($this->samplesDocs[9]->firstChild)); |
||
112 | $this->assertEquals('parent', $sort->nameGroup($this->samplesDocs[9]->firstChild->nextSibling)); |
||
113 | $this->assertEquals('special', $sort->nameGroup($this->samplesDocs[10]->firstChild)); |
||
114 | $this->assertEquals('special', $sort->nameGroup($this->samplesDocs[10]->firstChild->nextSibling)); |
||
115 | $this->assertEquals('split', $sort->nameGroup($this->samplesDocs[2]->firstChild)); |
||
116 | $this->assertEquals('split', $sort->nameGroup($this->samplesDocs[11]->firstChild)); |
||
117 | $this->assertEquals('split', $sort->nameGroup($this->samplesDocs[11]->firstChild->nextSibling)); |
||
118 | $this->assertEquals('nest', $sort->nameGroup($this->samplesDocs[12]->firstChild)); |
||
119 | $this->assertEquals('nest', $sort->nameGroup($this->samplesDocs[12]->childNodes->item(1))); |
||
120 | $this->assertEquals('nest', $sort->nameGroup($this->samplesDocs[12]->childNodes->item(2))); |
||
121 | $this->assertEquals('default', $sort->nameGroup($this->samplesDocs[6]->firstChild)); |
||
122 | } |
||
123 | |||
124 | public function testIsParent() |
||
125 | { |
||
126 | $sort = new NodeCheckChecker($this->config); |
||
127 | $this->assertTrue($sort->isParent($this->samplesDocs[9]->firstChild)); |
||
128 | $this->assertTrue($sort->isParent($this->samplesDocs[9]->firstChild->nextSibling)); |
||
129 | } |
||
130 | |||
131 | public function testIsSpecial() |
||
132 | { |
||
133 | $sort = new NodeCheckChecker($this->config); |
||
134 | $this->assertTrue($sort->isSpecial($this->samplesDocs[10]->childNodes->item(0))); |
||
135 | $this->assertTrue($sort->isSpecial($this->samplesDocs[10]->childNodes->item(1))); |
||
136 | $this->assertFalse($sort->isSpecial($this->samplesDocs[9]->childNodes->item(0))); |
||
137 | $this->assertFalse($sort->isSpecial($this->samplesDocs[9]->childNodes->item(1))); |
||
138 | } |
||
139 | |||
140 | public function testIsSplit() |
||
141 | { |
||
142 | $sort = new NodeCheckChecker($this->config); |
||
143 | $this->assertTrue($sort->isSplit($this->samplesDocs[11]->childNodes->item(0))); |
||
144 | $this->assertTrue($sort->isSplit($this->samplesDocs[11]->childNodes->item(1))); |
||
145 | $this->assertTrue($sort->isSplit($this->samplesDocs[2]->childNodes->item(0))); |
||
146 | $this->assertTrue($sort->isSplit($this->samplesDocs[6]->firstChild->firstChild)); |
||
147 | $this->assertFalse($sort->isSplit($this->samplesDocs[6]->firstChild)); |
||
148 | $this->assertFalse($sort->isSplit($this->samplesDocs[5]->firstChild->firstChild)); |
||
149 | } |
||
150 | } |
||
151 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths