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 | |||
10 | final class NodeCheckerDefaultDataTest extends \PHPUnit\Framework\TestCase |
||
11 | { |
||
12 | /** |
||
13 | * @var array |
||
14 | */ |
||
15 | private $testData = [ |
||
16 | ['group' => 'parents', 'tags' => ['div'],], |
||
17 | ['group' => 'specials', 'tags' => ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'strong', 'em', 'b', 'i', 'a'],], |
||
18 | [ |
||
19 | 'group' => 'rowCol', |
||
20 | [ |
||
21 | 'parent' => ['type' => 'tag', 'value' => 'table',], |
||
22 | 'colDefs' => ['type' => 'tag', 'value' => 'thead',], |
||
23 | 'rowsGroup' => ['type' => 'tag', 'value' => 'tbody',], |
||
24 | 'row' => ['type' => 'tag', 'value' => 'tr',], |
||
25 | ], |
||
26 | ], |
||
27 | ['group' => 'recursive', 'parents' => ['tags' => ['ul', 'ol',]], 'children' => ['tags' => ['li',],],], |
||
28 | [ |
||
29 | 'group' => 'pairs', |
||
30 | [ |
||
31 | 'parent' => ['type' => 'tag', 'value' => 'dl',], |
||
32 | 'a' => ['type' => 'tag', 'value' => 'dt',], |
||
33 | 'b' => ['type' => 'tag', 'value' => 'dd',], |
||
34 | ], |
||
35 | ], |
||
36 | ['group' => 'splits', 'what' => ['tags' => ['p'],], 'on' => ['. ', '? ', '! ']], |
||
37 | ]; |
||
38 | |||
39 | /** |
||
40 | * @var Config |
||
41 | */ |
||
42 | private $config; |
||
43 | /** |
||
44 | * @var DOMDocumentFactory |
||
45 | */ |
||
46 | private $docFactory; |
||
47 | |||
48 | /** |
||
49 | * @var string[] |
||
50 | */ |
||
51 | private $samples = [ |
||
52 | '<div>test Div</div><p>One Sentence only.</p>', |
||
53 | '<h1>Sample H1</h1><h2>Sample h2</h2><h3>sample h3</h3><h4>sample h4</h4><h5>sample h5</h5><h6>sample h6</h6>', |
||
54 | '<p>Sample paragraph. Second sentence</p>', |
||
55 | '<ul><li>sample list</li></ul><ol><li>sample ordered item</li></ol>', |
||
56 | '<p><strong>strong thing</strong> <em>emphasized</em> <b>emphasized</b> <i>emphasized</i></p>', |
||
57 | '<p><a href="#">Sample Link</a></p>', |
||
58 | '<div><p>Test P</p></div>', |
||
59 | '<table><tr><td>test</td><td>test</td></tr></table>', |
||
60 | '<dl><dt>sample term</dt><dd>sample def</dd></dl><dl>', |
||
61 | ]; |
||
62 | /** |
||
63 | * @var \DOMElement[] |
||
64 | */ |
||
65 | private $samplesDocs = []; |
||
66 | |||
67 | public function __construct(?string $name = null, array $data = [], string $dataName = '') |
||
68 | { |
||
69 | parent::__construct($name, $data, $dataName); |
||
70 | $this->config = new Config($this->testData); |
||
71 | $this->docFactory = new DOMDocumentFactory(); |
||
72 | $this->samplesDocs = \array_map(function ($sample) { |
||
73 | return $this->docFactory->getNode($sample); |
||
74 | }, $this->samples); |
||
75 | } |
||
76 | |||
77 | public function testNameGroup() |
||
78 | { |
||
79 | $this->assertEquals( |
||
80 | 'parent', |
||
81 | (new NodeCheckChecker($this->config))->nameGroup($this->samplesDocs[0]->firstChild) |
||
0 ignored issues
–
show
|
|||
82 | ); |
||
83 | $this->assertEquals( |
||
84 | 'special', |
||
85 | (new NodeCheckChecker($this->config))->nameGroup($this->samplesDocs[1]->firstChild) |
||
86 | ); |
||
87 | $this->assertEquals( |
||
88 | 'split', |
||
89 | (new NodeCheckChecker($this->config))->nameGroup($this->samplesDocs[2]->firstChild) |
||
90 | ); |
||
91 | $this->assertEquals( |
||
92 | 'nest', |
||
93 | (new NodeCheckChecker($this->config))->nameGroup($this->samplesDocs[3]->firstChild) |
||
94 | ); |
||
95 | $this->assertEquals( |
||
96 | 'default', |
||
97 | (new NodeCheckChecker($this->config))->nameGroup($this->samplesDocs[3]->firstChild->firstChild) |
||
98 | ); |
||
99 | } |
||
100 | |||
101 | public function testIsParent() |
||
102 | { |
||
103 | $this->assertTrue((new NodeCheckChecker($this->config)) |
||
104 | ->isParent($this->samplesDocs[0]->firstChild)); |
||
105 | $this->assertFalse((new NodeCheckChecker($this->config)) |
||
106 | ->isParent($this->samplesDocs[0]->childNodes->item(1))); |
||
107 | } |
||
108 | |||
109 | public function testIsSpecial() |
||
110 | { |
||
111 | $this->assertTrue((new NodeCheckChecker($this->config)) |
||
112 | ->isSpecial($this->samplesDocs[1]->childNodes->item(0))); |
||
113 | $this->assertTrue((new NodeCheckChecker($this->config)) |
||
114 | ->isSpecial($this->samplesDocs[1]->childNodes->item(1))); |
||
115 | $this->assertTrue((new NodeCheckChecker($this->config)) |
||
116 | ->isSpecial($this->samplesDocs[1]->childNodes->item(2))); |
||
117 | $this->assertTrue((new NodeCheckChecker($this->config)) |
||
118 | ->isSpecial($this->samplesDocs[1]->childNodes->item(3))); |
||
119 | $this->assertTrue((new NodeCheckChecker($this->config)) |
||
120 | ->isSpecial($this->samplesDocs[1]->childNodes->item(4))); |
||
121 | $this->assertTrue((new NodeCheckChecker($this->config)) |
||
122 | ->isSpecial($this->samplesDocs[1]->childNodes->item(5))); |
||
123 | $this->assertTrue((new NodeCheckChecker($this->config)) |
||
124 | ->isSpecial($this->samplesDocs[4]->firstChild->childNodes->item(0))); |
||
125 | $this->assertTrue((new NodeCheckChecker($this->config)) |
||
126 | ->isSpecial($this->samplesDocs[4]->firstChild->childNodes->item(2))); |
||
127 | $this->assertTrue((new NodeCheckChecker($this->config)) |
||
128 | ->isSpecial($this->samplesDocs[4]->firstChild->childNodes->item(4))); |
||
129 | $this->assertTrue((new NodeCheckChecker($this->config)) |
||
130 | ->isSpecial($this->samplesDocs[4]->firstChild->childNodes->item(6))); |
||
131 | $this->assertTrue((new NodeCheckChecker($this->config)) |
||
132 | ->isSpecial($this->samplesDocs[5]->firstChild->firstChild)); |
||
133 | $this->assertFalse((new NodeCheckChecker($this->config)) |
||
134 | ->isSpecial($this->samplesDocs[5]->firstChild)); |
||
135 | $this->assertFalse((new NodeCheckChecker($this->config)) |
||
136 | ->isSpecial($this->samplesDocs[4]->firstChild)); |
||
137 | } |
||
138 | |||
139 | public function testIsSplit() |
||
140 | { |
||
141 | $this->assertTrue((new NodeCheckChecker($this->config)) |
||
142 | ->isSplit($this->samplesDocs[0]->childNodes->item(1))); |
||
143 | $this->assertTrue((new NodeCheckChecker($this->config)) |
||
144 | ->isSplit($this->samplesDocs[2]->childNodes->item(0))); |
||
145 | $this->assertTrue((new NodeCheckChecker($this->config)) |
||
146 | ->isSplit($this->samplesDocs[6]->firstChild->firstChild)); |
||
147 | $this->assertFalse((new NodeCheckChecker($this->config)) |
||
148 | ->isSplit($this->samplesDocs[6]->firstChild)); |
||
149 | $this->assertFalse((new NodeCheckChecker($this->config)) |
||
150 | ->isSplit($this->samplesDocs[5]->firstChild->firstChild)); |
||
151 | } |
||
152 | |||
153 | public function testGetSplitDelimiters() |
||
154 | { |
||
155 | $this->assertEquals($this->testData[5]['on'], (new NodeCheckChecker($this->config))->getSplitDelimiters(false)); |
||
156 | $this->assertEquals(['.', '?', '!'], (new NodeCheckChecker($this->config))->getSplitDelimiters(true)); |
||
157 | $this->assertNotEquals($this->testData[5]['on'], (new NodeCheckChecker($this->config))->getSplitDelimiters(true)); |
||
158 | } |
||
159 | } |
||
160 |
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