From 7933a7e90575d4eb79f52ec7e8f26467fa8ed305 Mon Sep 17 00:00:00 2001 From: JeffreyWay Date: Mon, 20 Apr 2015 19:27:20 -0400 Subject: [PATCH] Fix url issue - closes #46 --- src/Extensions/Goutte.php | 2 +- src/Extensions/IntegrationTrait.php | 16 +++++++++++++--- src/Extensions/Laravel.php | 4 ++-- src/Extensions/Selenium.php | 6 ++++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/Extensions/Goutte.php b/src/Extensions/Goutte.php index 9afd18c..e477af7 100644 --- a/src/Extensions/Goutte.php +++ b/src/Extensions/Goutte.php @@ -60,7 +60,7 @@ public function submitForm($buttonText, $formData = null) $this->currentPage = $this->client()->getHistory()->current()->getUri(); - $this->clearInputs()->assertPageLoaded($this->currentPage); + $this->clearInputs()->assertPageLoaded($this->currentPage()); return $this; } diff --git a/src/Extensions/IntegrationTrait.php b/src/Extensions/IntegrationTrait.php index 430cea1..bd2a27a 100644 --- a/src/Extensions/IntegrationTrait.php +++ b/src/Extensions/IntegrationTrait.php @@ -89,10 +89,10 @@ protected function prepareUrl($url) } if (! Str::startsWith($url, 'http')) { - $url = rtrim(sprintf("%s/%s", $this->baseUrl(), $url), '/'); + $url = sprintf("%s/%s", $this->baseUrl(), $url); } - return $url; + return trim($url, '/'); } /** @@ -130,7 +130,7 @@ public function seePageIs($uri) $message = "Expected to be on the page, {$uri}, but wasn't."; - $this->assertEquals($uri, $this->currentPage, $message); + $this->assertEquals($uri, $this->currentPage(), $message); return $this; } @@ -342,6 +342,16 @@ protected function getForm($button = null) } } + /** + * Get the current URL for the request. + * + * @return string + */ + protected function currentPage() + { + return rtrim($this->currentPage, '/'); + } + /** * Assert that a 200 status code was returned from the last call. * diff --git a/src/Extensions/Laravel.php b/src/Extensions/Laravel.php index 8a3475b..ef137a9 100644 --- a/src/Extensions/Laravel.php +++ b/src/Extensions/Laravel.php @@ -69,7 +69,7 @@ protected function makeRequest($requestType, $uri, $parameters = [], $cookies = $this->currentPage = $this->app['request']->fullUrl(); - $this->crawler = new Crawler($this->response(), $this->currentPage); + $this->crawler = new Crawler($this->response(), $this->currentPage()); return $this; } @@ -142,7 +142,7 @@ protected function statusCode() */ protected function handleInternalError($message = null) { - $crawler = new Crawler($this->response(), $this->currentPage); + $crawler = new Crawler($this->response(), $this->currentPage()); // A little weird, but we need to parse the output HTML to // figure out the specifics of where the error occurred. diff --git a/src/Extensions/Selenium.php b/src/Extensions/Selenium.php index 650b026..d20ecb8 100644 --- a/src/Extensions/Selenium.php +++ b/src/Extensions/Selenium.php @@ -92,6 +92,8 @@ protected function makeRequest($requestType, $uri, $parameters = []) */ public function click($name) { + $page = $this->currentPage(); + try { $link = $this->findByBody($name)->click(); } catch (InvalidArgumentException $e) { @@ -101,9 +103,9 @@ public function click($name) $this->updateCurrentUrl(); $this->assertPageLoaded( - $this->currentPage, + $page, "Successfully clicked on a link with a body, name, or class of '{$name}', " . - "but its destination, {$this->currentPage}, did not produce a 200 status code." + "but its destination, {$page}, did not produce a 200 status code." ); return $this;