From 2fd6e1a6ca2f740a4d5355fa95045dd1ebeb70a2 Mon Sep 17 00:00:00 2001 From: Peter Thaleikis Date: Thu, 10 Nov 2022 11:07:18 +0100 Subject: [PATCH] Improve UrlTests --- tests/UrlTest.php | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/tests/UrlTest.php b/tests/UrlTest.php index 6315a36..d46e6d3 100644 --- a/tests/UrlTest.php +++ b/tests/UrlTest.php @@ -19,13 +19,22 @@ public function validateUriTest() $web->go('https://test-pages.phpscraper.de/content/lists.html'); // Ensure the URL is set correctly. - $this->assertSame('https://test-pages.phpscraper.de/content/lists.html', $web->currentUrl); + $this->assertSame( + 'https://test-pages.phpscraper.de/content/lists.html', + $web->currentUrl + ); // Ensure the host is parsed correctly. - $this->assertSame('test-pages.phpscraper.de', $web->currentHost); + $this->assertSame( + 'test-pages.phpscraper.de', + $web->currentHost + ); // Ensure the host with protocol is parsed correctly. - $this->assertSame('https://test-pages.phpscraper.de', $web->currentBaseHost); + $this->assertSame( + 'https://test-pages.phpscraper.de', + $web->currentBaseHost + ); } /** @@ -43,6 +52,26 @@ public function testNullPassingThrough() /** * @test */ + public function testCurrentBaseHostWithBase() + { + $web = new \spekulatius\phpscraper; + + // Navigate to the test page. + // Contains: + $web->go('https://test-pages.phpscraper.de/meta/image/absolute-path-with-base-href.html'); + + // Check the base href being passed through the current base host. + $this->assertSame( + 'https://test-pages-with-base-href.phpscraper.de', + $web->currentBaseHost + ); + } + + /** + * Basic processing of the URLs. + * + * @test + */ public function testMakeUrlAbsolute() { $web = new \spekulatius\phpscraper; @@ -83,6 +112,8 @@ public function testMakeUrlAbsolute() } /** + * Test if passed in hosts are considered. + * * @test */ public function testMakeUrlAbsoluteWithBaseHost()