From 71705838630ead855daf3f7d1ae637d939b62ce6 Mon Sep 17 00:00:00 2001 From: Jonas Staudenmeir Date: Fri, 8 Mar 2019 15:22:37 +0100 Subject: [PATCH] Fix with() and page assertions --- src/Browser.php | 19 ++++++++++++++++--- tests/BrowserTest.php | 6 ++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Browser.php b/src/Browser.php index ab5eceacd..fc122bc7f 100644 --- a/src/Browser.php +++ b/src/Browser.php @@ -166,6 +166,21 @@ public function visitRoute($route, $parameters = []) * @return $this */ public function on($page) + { + $this->onWithoutAssert($page); + + $page->assert($this); + + return $this; + } + + /** + * Set the current page object without executing the assertions. + * + * @param mixed $page + * @return $this + */ + public function onWithoutAssert($page) { $this->page = $page; @@ -176,8 +191,6 @@ public function on($page) $page::siteElements(), $page->elements() )); - $page->assert($this); - return $this; } @@ -330,7 +343,7 @@ public function with($selector, Closure $callback) ); if ($this->page) { - $browser->on($this->page); + $browser->onWithoutAssert($this->page); } if ($selector instanceof Component) { diff --git a/tests/BrowserTest.php b/tests/BrowserTest.php index 4ce2b154b..06e12048c 100644 --- a/tests/BrowserTest.php +++ b/tests/BrowserTest.php @@ -82,10 +82,13 @@ public function test_with_method_with_page() $browser->visit($page = new BrowserTestPage); + $page->asserted = false; + $browser->with('prefix', function ($browser) use ($page) { $this->assertInstanceof(Browser::class, $browser); $this->assertEquals('body prefix', $browser->resolver->prefix); $this->assertEquals($page, $browser->page); + $this->assertFalse($page->asserted); }); } @@ -109,10 +112,13 @@ public function test_within_method_with_page() $browser->visit($page = new BrowserTestPage); + $page->asserted = false; + $browser->within('prefix', function ($browser) use ($page) { $this->assertInstanceof(Browser::class, $browser); $this->assertEquals('body prefix', $browser->resolver->prefix); $this->assertEquals($page, $browser->page); + $this->assertFalse($page->asserted); }); }