diff --git a/src/Symfony/Bundle/FrameworkBundle/Test/BrowserKitAssertionsTrait.php b/src/Symfony/Bundle/FrameworkBundle/Test/BrowserKitAssertionsTrait.php index 7d49aa61d22c6..6086e75ecec4c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Test/BrowserKitAssertionsTrait.php +++ b/src/Symfony/Bundle/FrameworkBundle/Test/BrowserKitAssertionsTrait.php @@ -16,6 +16,7 @@ use PHPUnit\Framework\Constraint\LogicalNot; use PHPUnit\Framework\ExpectationFailedException; use Symfony\Component\BrowserKit\AbstractBrowser; +use Symfony\Component\BrowserKit\History; use Symfony\Component\BrowserKit\Test\Constraint as BrowserKitConstraint; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -122,6 +123,38 @@ public static function assertBrowserNotHasCookie(string $name, string $path = '/ self::assertThatForClient(new LogicalNot(new BrowserKitConstraint\BrowserHasCookie($name, $path, $domain)), $message); } + public static function assertBrowserHistoryIsOnFirstPage(string $message = ''): void + { + if (!method_exists(History::class, 'isFirstPage')) { + throw new \LogicException('The `assertBrowserHistoryIsOnFirstPage` method requires symfony/browser-kit >= 7.4.'); + } + self::assertThatForClient(new BrowserKitConstraint\BrowserHistoryIsOnFirstPage(), $message); + } + + public static function assertBrowserHistoryIsNotOnFirstPage(string $message = ''): void + { + if (!method_exists(History::class, 'isFirstPage')) { + throw new \LogicException('The `assertBrowserHistoryIsNotOnFirstPage` method requires symfony/browser-kit >= 7.4.'); + } + self::assertThatForClient(new LogicalNot(new BrowserKitConstraint\BrowserHistoryIsOnFirstPage()), $message); + } + + public static function assertBrowserHistoryIsOnLastPage(string $message = ''): void + { + if (!method_exists(History::class, 'isLastPage')) { + throw new \LogicException('The `assertBrowserHistoryIsOnLastPage` method requires symfony/browser-kit >= 7.4.'); + } + self::assertThatForClient(new BrowserKitConstraint\BrowserHistoryIsOnLastPage(), $message); + } + + public static function assertBrowserHistoryIsNotOnLastPage(string $message = ''): void + { + if (!method_exists(History::class, 'isLastPage')) { + throw new \LogicException('The `assertBrowserHistoryIsNotOnLastPage` method requires symfony/browser-kit >= 7.4.'); + } + self::assertThatForClient(new LogicalNot(new BrowserKitConstraint\BrowserHistoryIsOnLastPage()), $message); + } + public static function assertBrowserCookieValueSame(string $name, string $expectedValue, bool $raw = false, string $path = '/', ?string $domain = null, string $message = ''): void { self::assertThatForClient(LogicalAnd::fromConstraints( diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Test/WebTestCaseTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Test/WebTestCaseTest.php index 84f2ef0ef31f2..fd65b18d830cf 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Test/WebTestCaseTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Test/WebTestCaseTest.php @@ -13,12 +13,14 @@ use PHPUnit\Framework\AssertionFailedError; use PHPUnit\Framework\ExpectationFailedException; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\Test\WebTestAssertionsTrait; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Component\BrowserKit\Cookie; use Symfony\Component\BrowserKit\CookieJar; +use Symfony\Component\BrowserKit\History; use Symfony\Component\DomCrawler\Crawler; use Symfony\Component\HttpFoundation\Cookie as HttpFoundationCookie; use Symfony\Component\HttpFoundation\Request; @@ -190,6 +192,50 @@ public function testAssertBrowserCookieValueSame() $this->getClientTester()->assertBrowserCookieValueSame('foo', 'babar', false, '/path'); } + /** + * @requires function \Symfony\Component\BrowserKit\History::isFirstPage + */ + public function testAssertBrowserHistoryIsOnFirstPage() + { + $this->createHistoryTester('isFirstPage', true)->assertBrowserHistoryIsOnFirstPage(); + $this->expectException(AssertionFailedError::class); + $this->expectExceptionMessage('Failed asserting that the Browser history is on the first page.'); + $this->createHistoryTester('isFirstPage', false)->assertBrowserHistoryIsOnFirstPage(); + } + + /** + * @requires function \Symfony\Component\BrowserKit\History::isFirstPage + */ + public function testAssertBrowserHistoryIsNotOnFirstPage() + { + $this->createHistoryTester('isFirstPage', false)->assertBrowserHistoryIsNotOnFirstPage(); + $this->expectException(AssertionFailedError::class); + $this->expectExceptionMessage('Failed asserting that the Browser history is not on the first page.'); + $this->createHistoryTester('isFirstPage', true)->assertBrowserHistoryIsNotOnFirstPage(); + } + + /** + * @requires function \Symfony\Component\BrowserKit\History::isLastPage + */ + public function testAssertBrowserHistoryIsOnLastPage() + { + $this->createHistoryTester('isLastPage', true)->assertBrowserHistoryIsOnLastPage(); + $this->expectException(AssertionFailedError::class); + $this->expectExceptionMessage('Failed asserting that the Browser history is on the last page.'); + $this->createHistoryTester('isLastPage', false)->assertBrowserHistoryIsOnLastPage(); + } + + /** + * @requires function \Symfony\Component\BrowserKit\History::isLastPage + */ + public function testAssertBrowserHistoryIsNotOnLastPage() + { + $this->createHistoryTester('isLastPage', false)->assertBrowserHistoryIsNotOnLastPage(); + $this->expectException(AssertionFailedError::class); + $this->expectExceptionMessage('Failed asserting that the Browser history is not on the last page.'); + $this->createHistoryTester('isLastPage', true)->assertBrowserHistoryIsNotOnLastPage(); + } + public function testAssertSelectorExists() { $this->getCrawlerTester(new Crawler('
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: