Skip to content

Commit 4bb7098

Browse files
committed
Fixes paquettg#203
1 parent 0127b9e commit 4bb7098

File tree

4 files changed

+18
-54
lines changed

4 files changed

+18
-54
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2525
### Removed
2626
- Curl interface and curl implementation has been removed.
2727
- Removed support for the depth first search option.
28+
- findById() method removed from Dom object.
2829

2930
## 2.2.0
3031

src/PHPHtmlParser/Dom.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ public function __get($name)
150150
*/
151151
public function load(string $str, array $options = []): Dom
152152
{
153-
AbstractNode::resetCount();
154153
// check if it's a file
155154
if (\strpos($str, "\n") === false && \is_file($str)) {
156155
return $this->loadFromFile($str, $options);
@@ -264,22 +263,6 @@ public function find(string $selector, int $nth = null)
264263
return $result;
265264
}
266265

267-
/**
268-
* Find element by Id on the root node.
269-
*
270-
* @throws ChildNotFoundException
271-
* @throws NotLoadedException
272-
* @throws ParentNotFoundException
273-
*
274-
* @return bool|AbstractNode
275-
*/
276-
public function findById(int $id)
277-
{
278-
$this->isLoaded();
279-
280-
return $this->root->findById($id);
281-
}
282-
283266
/**
284267
* Adds the tag (or tags in an array) to the list of tags that will always
285268
* be self closing.

src/PHPHtmlParser/Dom/AbstractNode.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,6 @@ public function setHtmlSpecialCharsDecode($htmlSpecialCharsDecode = false): void
140140
$this->htmlSpecialCharsDecode = $htmlSpecialCharsDecode;
141141
}
142142

143-
/**
144-
* Reset node counter.
145-
*
146-
* @return void
147-
*/
148-
public static function resetCount()
149-
{
150-
self::$count = 0;
151-
}
152-
153143
/**
154144
* Returns the id of this object.
155145
*/

tests/DomTest.php

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -394,33 +394,6 @@ public function testHasChildren()
394394
$this->assertTrue($dom->hasChildren());
395395
}
396396

397-
public function testFindByIdVar1()
398-
{
399-
$dom = new Dom();
400-
$dom->load('<div class="all"><p>Hey bro, <a href="google.com">click here</a><br /> :)</p></div>');
401-
/** @var Dom\AbstractNode $result */
402-
$result = $dom->findById(4);
403-
$this->assertEquals(4, $result->id());
404-
}
405-
406-
public function testFindByIdVar2()
407-
{
408-
$dom = new Dom();
409-
$dom->load('<div class="all"><p>Hey bro, <a href="google.com">click here</a><br /> :)</p></div>');
410-
/** @var Dom\AbstractNode $result */
411-
$result = $dom->findById(5);
412-
$this->assertEquals(5, $result->id());
413-
}
414-
415-
public function testFindByIdNotFountEleement()
416-
{
417-
$dom = new Dom();
418-
$dom->load('<div class="all"><p>Hey bro, <a href="google.com">click here</a><br /> :)</p></div>');
419-
/** @var Dom\AbstractNode $result */
420-
$result = $dom->findById(8);
421-
$this->assertFalse($result);
422-
}
423-
424397
public function testWhitespaceInText()
425398
{
426399
$dom = new Dom();
@@ -629,4 +602,21 @@ public function testLessThanCharacterInJavascript()
629602
])->find('body');
630603
$this->assertCount(1, $results);
631604
}
605+
606+
public function testUniqueIdForAllObjects()
607+
{
608+
// Create a dom which will be used as a parent/container for a paragraph
609+
$dom1 = new \PHPHtmlParser\Dom;
610+
$dom1->load('<div>A container div</div>'); // Resets the counter (doesn't matter here as the counter was 0 even without resetting)
611+
$div = $dom1->firstChild();
612+
613+
// Create a paragraph outside of the first dom
614+
$dom2 = new \PHPHtmlParser\Dom;
615+
$dom2->load('<p>Our new paragraph.</p>'); // Resets the counter
616+
$paragraph = $dom2->firstChild();
617+
618+
$div->addChild($paragraph);
619+
620+
$this->assertEquals('A container div<p>Our new paragraph.</p>', $div->innerhtml);
621+
}
632622
}

0 commit comments

Comments
 (0)