|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\AssertionFailedError;
|
15 | 15 | use PHPUnit\Framework\ExpectationFailedException;
|
| 16 | +use PHPUnit\Framework\MockObject\MockObject; |
16 | 17 | use PHPUnit\Framework\TestCase;
|
17 | 18 | use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
18 | 19 | use Symfony\Bundle\FrameworkBundle\Test\WebTestAssertionsTrait;
|
19 | 20 | use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
20 | 21 | use Symfony\Component\BrowserKit\Cookie;
|
21 | 22 | use Symfony\Component\BrowserKit\CookieJar;
|
| 23 | +use Symfony\Component\BrowserKit\History; |
22 | 24 | use Symfony\Component\DomCrawler\Crawler;
|
23 | 25 | use Symfony\Component\HttpFoundation\Cookie as HttpFoundationCookie;
|
24 | 26 | use Symfony\Component\HttpFoundation\Request;
|
@@ -190,6 +192,50 @@ public function testAssertBrowserCookieValueSame()
|
190 | 192 | $this->getClientTester()->assertBrowserCookieValueSame('foo', 'babar', false, '/path');
|
191 | 193 | }
|
192 | 194 |
|
| 195 | + /** |
| 196 | + * @requires function \Symfony\Component\BrowserKit\History::isFirstPage |
| 197 | + */ |
| 198 | + public function testAssertBrowserHistoryIsOnFirstPage() |
| 199 | + { |
| 200 | + $this->createHistoryTester('isFirstPage', true)->assertBrowserHistoryIsOnFirstPage(); |
| 201 | + $this->expectException(AssertionFailedError::class); |
| 202 | + $this->expectExceptionMessage('Failed asserting that the Browser history is on the first page.'); |
| 203 | + $this->createHistoryTester('isFirstPage', false)->assertBrowserHistoryIsOnFirstPage(); |
| 204 | + } |
| 205 | + |
| 206 | + /** |
| 207 | + * @requires function \Symfony\Component\BrowserKit\History::isFirstPage |
| 208 | + */ |
| 209 | + public function testAssertBrowserHistoryIsNotOnFirstPage() |
| 210 | + { |
| 211 | + $this->createHistoryTester('isFirstPage', false)->assertBrowserHistoryIsNotOnFirstPage(); |
| 212 | + $this->expectException(AssertionFailedError::class); |
| 213 | + $this->expectExceptionMessage('Failed asserting that the Browser history is not on the first page.'); |
| 214 | + $this->createHistoryTester('isFirstPage', true)->assertBrowserHistoryIsNotOnFirstPage(); |
| 215 | + } |
| 216 | + |
| 217 | + /** |
| 218 | + * @requires function \Symfony\Component\BrowserKit\History::isLastPage |
| 219 | + */ |
| 220 | + public function testAssertBrowserHistoryIsOnLastPage() |
| 221 | + { |
| 222 | + $this->createHistoryTester('isLastPage', true)->assertBrowserHistoryIsOnLastPage(); |
| 223 | + $this->expectException(AssertionFailedError::class); |
| 224 | + $this->expectExceptionMessage('Failed asserting that the Browser history is on the last page.'); |
| 225 | + $this->createHistoryTester('isLastPage', false)->assertBrowserHistoryIsOnLastPage(); |
| 226 | + } |
| 227 | + |
| 228 | + /** |
| 229 | + * @requires function \Symfony\Component\BrowserKit\History::isLastPage |
| 230 | + */ |
| 231 | + public function testAssertBrowserHistoryIsNotOnLastPage() |
| 232 | + { |
| 233 | + $this->createHistoryTester('isLastPage', false)->assertBrowserHistoryIsNotOnLastPage(); |
| 234 | + $this->expectException(AssertionFailedError::class); |
| 235 | + $this->expectExceptionMessage('Failed asserting that the Browser history is not on the last page.'); |
| 236 | + $this->createHistoryTester('isLastPage', true)->assertBrowserHistoryIsNotOnLastPage(); |
| 237 | + } |
| 238 | + |
193 | 239 | public function testAssertSelectorExists()
|
194 | 240 | {
|
195 | 241 | $this->getCrawlerTester(new Crawler('<html><body><h1>'))->assertSelectorExists('body > h1');
|
@@ -386,6 +432,19 @@ private function getRequestTester(): WebTestCase
|
386 | 432 | return $this->getTester($client);
|
387 | 433 | }
|
388 | 434 |
|
| 435 | + private function createHistoryTester(string $method, bool $returnValue): WebTestCase |
| 436 | + { |
| 437 | + /** @var KernelBrowser&MockObject $client */ |
| 438 | + $client = $this->createMock(KernelBrowser::class); |
| 439 | + /** @var History&MockObject $history */ |
| 440 | + $history = $this->createMock(History::class); |
| 441 | + |
| 442 | + $history->method($method)->willReturn($returnValue); |
| 443 | + $client->method('getHistory')->willReturn($history); |
| 444 | + |
| 445 | + return $this->getTester($client); |
| 446 | + } |
| 447 | + |
389 | 448 | private function getTester(KernelBrowser $client): WebTestCase
|
390 | 449 | {
|
391 | 450 | $tester = new class(method_exists($this, 'name') ? $this->name() : $this->getName()) extends WebTestCase {
|
|
0 commit comments