Skip to content

Commit

Permalink
Fixed bug in tag::getIndex() where it was generating the indexes fr…
Browse files Browse the repository at this point in the history
…om 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.
  • Loading branch information
hexydec committed Aug 7, 2023
1 parent 438f932 commit 0157bf8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 24 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
env:
XDEBUG_MODE: coverage

- name: Upload coverage to Codecov
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
files: ./coverage/result.xml
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
37 changes: 19 additions & 18 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/tokens/tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public function prepend(array $nodes) : void {
*/
protected function getIndex() : ?int {
if ($this->parent) {
foreach ($this->parent->children() AS $key => $item) {
foreach ($this->parent->children AS $key => $item) {
if ($item === $this) {
return $key;
}
Expand Down
18 changes: 16 additions & 2 deletions tests/editHtmldocTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function testCanPrependHtml() {
}
}

public function testCanInserHtmlBefore() {
public function testCanInsertHtmlBefore() {
$obj = new htmldoc();
$obj->load('Data to <span>insert</span> before');
$tests = [
Expand Down Expand Up @@ -133,7 +133,7 @@ public function testCanInserHtmlBefore() {
}
}

public function testCanInserHtmlAfter() {
public function testCanInsertHtmlAfter() {
$obj = new htmldoc();
$obj->load('Data to <span>insert</span> after');
$tests = [
Expand Down Expand Up @@ -166,6 +166,20 @@ public function testCanInserHtmlAfter() {
'find' => 'div',
'after' => '<h3>After</h3><p>Test <span>this</span></p>',
'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>',
],
[ // test with text nodes
'input' => '<body>
<div>
<div>Text Node</div>
</div>
</body>',
'find' => 'div',
'after' => '<h3>After</h3><p>Test <span>this</span></p>',
'output' => '<body>
<div>
<div>Text Node</div><h3>After</h3><p>Test <span>this</span></p>
</div><h3>After</h3><p>Test <span>this</span></p>
</body>',
]
];
$doc = new htmldoc();
Expand Down

0 comments on commit 0157bf8

Please sign in to comment.