Skip to content

Commit 0157bf8

Browse files
committed
Fixed bug in tag::getIndex() where it was generating the indexes from only the tag objects, meaning that when there were other node types such as text nodes, the index would be out of step, causing nodes to be inserted into the wrong position.
Added tests. Updated workflow configuration to add codecov secret.
1 parent 438f932 commit 0157bf8

File tree

4 files changed

+39
-24
lines changed

4 files changed

+39
-24
lines changed

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
env:
2626
XDEBUG_MODE: coverage
2727

28-
- name: Upload coverage to Codecov
28+
- name: Upload coverage reports to Codecov
2929
uses: codecov/codecov-action@v3
30-
with:
31-
files: ./coverage/result.xml
30+
env:
31+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

composer.lock

Lines changed: 19 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tokens/tag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ public function prepend(array $nodes) : void {
346346
*/
347347
protected function getIndex() : ?int {
348348
if ($this->parent) {
349-
foreach ($this->parent->children() AS $key => $item) {
349+
foreach ($this->parent->children AS $key => $item) {
350350
if ($item === $this) {
351351
return $key;
352352
}

tests/editHtmldocTest.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function testCanPrependHtml() {
9090
}
9191
}
9292

93-
public function testCanInserHtmlBefore() {
93+
public function testCanInsertHtmlBefore() {
9494
$obj = new htmldoc();
9595
$obj->load('Data to <span>insert</span> before');
9696
$tests = [
@@ -133,7 +133,7 @@ public function testCanInserHtmlBefore() {
133133
}
134134
}
135135

136-
public function testCanInserHtmlAfter() {
136+
public function testCanInsertHtmlAfter() {
137137
$obj = new htmldoc();
138138
$obj->load('Data to <span>insert</span> after');
139139
$tests = [
@@ -166,6 +166,20 @@ public function testCanInserHtmlAfter() {
166166
'find' => 'div',
167167
'after' => '<h3>After</h3><p>Test <span>this</span></p>',
168168
'output' => '<body><div><div></div><h3>After</h3><p>Test <span>this</span></p></div><h3>After</h3><p>Test <span>this</span></p></body>',
169+
],
170+
[ // test with text nodes
171+
'input' => '<body>
172+
<div>
173+
<div>Text Node</div>
174+
</div>
175+
</body>',
176+
'find' => 'div',
177+
'after' => '<h3>After</h3><p>Test <span>this</span></p>',
178+
'output' => '<body>
179+
<div>
180+
<div>Text Node</div><h3>After</h3><p>Test <span>this</span></p>
181+
</div><h3>After</h3><p>Test <span>this</span></p>
182+
</body>',
169183
]
170184
];
171185
$doc = new htmldoc();

0 commit comments

Comments
 (0)