Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 1c82d21

Browse files
author
anatolii
committed
Xpath for pagination or nextpage can be empty now
1 parent 9f1f577 commit 1c82d21

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/RecursivePagination.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ class RecursivePagination {
3333
*/
3434
public function __construct(Grabber $grabber, $xpath = null) {
3535
$this->grabber = $grabber;
36-
$this->addXpath($xpath);
36+
if (isset($xpath)) {
37+
$this->addXpath($xpath);
38+
}
3739
}
3840

3941

tests/RecursivePaginationTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,25 @@ public function testOneLink() {
5252
}
5353

5454

55+
/**
56+
* Asserts that $allLinks array has 2 elements. Checking only first page, without pagination Xpath
57+
*
58+
*/
59+
public function testOneLinkWithEmptyPaginationXpath() {
60+
$grabber = new TestGrabber();
61+
62+
$paginator = new RecursivePagination($grabber);
63+
$paginator->addToQueue('osmosis/page1.html');
64+
65+
$allLinks = [];
66+
while ($page = $paginator->getNextPage()) {
67+
$adsList = $page->attribute("//h2/a/@href")->getItems();
68+
$allLinks = array_values(array_unique(array_merge($allLinks, $adsList)));
69+
}
70+
$this->assertTrue(count($allLinks) == 2);
71+
}
72+
73+
5574
/**
5675
* Asserts that $allLinks array has 10 elements.
5776
*

0 commit comments

Comments
 (0)