diff --git a/src/Symfony/Component/BrowserKit/CHANGELOG.md b/src/Symfony/Component/BrowserKit/CHANGELOG.md index b05e3079e7a5..2437bbc7ddfc 100644 --- a/src/Symfony/Component/BrowserKit/CHANGELOG.md +++ b/src/Symfony/Component/BrowserKit/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +7.4 +--- + + * Add `isFirstPage()` and `isLastPage()` methods to the History class for checking navigation boundaries + 6.4 --- diff --git a/src/Symfony/Component/BrowserKit/History.php b/src/Symfony/Component/BrowserKit/History.php index 8fe4f2bbcced..5926b4076bf1 100644 --- a/src/Symfony/Component/BrowserKit/History.php +++ b/src/Symfony/Component/BrowserKit/History.php @@ -50,6 +50,22 @@ public function isEmpty(): bool return 0 === \count($this->stack); } + /** + * Returns true if the stack is on the first page. + */ + public function isFirstPage(): bool + { + return $this->position < 1; + } + + /** + * Returns true if the stack is on the last page. + */ + public function isLastPage(): bool + { + return $this->position > \count($this->stack) - 2; + } + /** * Goes back in the history. * @@ -57,7 +73,7 @@ public function isEmpty(): bool */ public function back(): Request { - if ($this->position < 1) { + if ($this->isFirstPage()) { throw new LogicException('You are already on the first page.'); } @@ -71,7 +87,7 @@ public function back(): Request */ public function forward(): Request { - if ($this->position > \count($this->stack) - 2) { + if ($this->isLastPage()) { throw new LogicException('You are already on the last page.'); } diff --git a/src/Symfony/Component/BrowserKit/Tests/AbstractBrowserTest.php b/src/Symfony/Component/BrowserKit/Tests/AbstractBrowserTest.php index dd7f8e4615f2..096c07c701d3 100644 --- a/src/Symfony/Component/BrowserKit/Tests/AbstractBrowserTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/AbstractBrowserTest.php @@ -701,6 +701,8 @@ public function testBack() $this->assertArrayHasKey('myfile.foo', $client->getRequest()->getFiles(), '->back() keeps files'); $this->assertArrayHasKey('X_TEST_FOO', $client->getRequest()->getServer(), '->back() keeps $_SERVER'); $this->assertSame($content, $client->getRequest()->getContent(), '->back() keeps content'); + $this->assertTrue($client->getHistory()->isFirstPage()); + $this->assertFalse($client->getHistory()->isLastPage()); } public function testForward() @@ -741,6 +743,8 @@ public function testBackAndFrowardWithRedirects() $client->forward(); $this->assertSame('http://www.example.com/redirected', $client->getRequest()->getUri(), '->forward() goes forward in the history skipping redirects'); + $this->assertTrue($client->getHistory()->isLastPage()); + $this->assertFalse($client->getHistory()->isFirstPage()); } public function testReload() diff --git a/src/Symfony/Component/BrowserKit/Tests/HistoryTest.php b/src/Symfony/Component/BrowserKit/Tests/HistoryTest.php index 8f3cfae16b0d..1e1acb2c5a02 100644 --- a/src/Symfony/Component/BrowserKit/Tests/HistoryTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/HistoryTest.php @@ -99,4 +99,34 @@ public function testForward() $this->assertSame('http://www.example1.com/', $history->current()->getUri(), '->forward() returns the next request in the history'); } + + public function testIsFirstPage() + { + $history = new History(); + $history->add(new Request('http://www.example.com/', 'get')); + $history->add(new Request('http://www.example1.com/', 'get')); + $history->back(); + + $this->assertFalse($history->isLastPage()); + $this->assertTrue($history->isFirstPage()); + } + + public function testIsLastPage() + { + $history = new History(); + $history->add(new Request('http://www.example.com/', 'get')); + $history->add(new Request('http://www.example1.com/', 'get')); + + $this->assertTrue($history->isLastPage()); + $this->assertFalse($history->isFirstPage()); + } + + public function testIsFirstAndLastPage() + { + $history = new History(); + $history->add(new Request('http://www.example.com/', 'get')); + + $this->assertTrue($history->isLastPage()); + $this->assertTrue($history->isFirstPage()); + } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy