|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Tests; |
| 6 | + |
| 7 | +use Codeception\Module\Symfony\BrowserAssertionsTrait; |
| 8 | +use Symfony\Component\BrowserKit\Cookie; |
| 9 | +use Tests\Support\CodeceptTestCase; |
| 10 | + |
| 11 | +final class BrowserAssertionsTest extends CodeceptTestCase |
| 12 | +{ |
| 13 | + use BrowserAssertionsTrait; |
| 14 | + |
| 15 | + protected function setUp(): void |
| 16 | + { |
| 17 | + parent::setUp(); |
| 18 | + $this->client->followRedirects(false); |
| 19 | + $this->client->getCookieJar()->set(new Cookie('browser_cookie', 'value')); |
| 20 | + } |
| 21 | + |
| 22 | + public function testAssertBrowserCookieValueSame(): void |
| 23 | + { |
| 24 | + $this->assertBrowserCookieValueSame('browser_cookie', 'value'); |
| 25 | + } |
| 26 | + |
| 27 | + public function testAssertBrowserHasCookie(): void |
| 28 | + { |
| 29 | + $this->assertBrowserHasCookie('browser_cookie'); |
| 30 | + } |
| 31 | + |
| 32 | + public function testAssertBrowserNotHasCookie(): void |
| 33 | + { |
| 34 | + $this->client->getCookieJar()->expire('browser_cookie'); |
| 35 | + $this->assertBrowserNotHasCookie('browser_cookie'); |
| 36 | + } |
| 37 | + |
| 38 | + public function testAssertRequestAttributeValueSame(): void |
| 39 | + { |
| 40 | + $this->client->request('GET', '/request_attr'); |
| 41 | + $this->assertRequestAttributeValueSame('page', 'register'); |
| 42 | + } |
| 43 | + |
| 44 | + public function testAssertResponseCookieValueSame(): void |
| 45 | + { |
| 46 | + $this->client->request('GET', '/response_cookie'); |
| 47 | + $this->assertResponseCookieValueSame('TESTCOOKIE', 'codecept'); |
| 48 | + } |
| 49 | + |
| 50 | + public function testAssertResponseFormatSame(): void |
| 51 | + { |
| 52 | + $this->client->request('GET', '/response_json'); |
| 53 | + $this->assertResponseFormatSame('json'); |
| 54 | + } |
| 55 | + |
| 56 | + public function testAssertResponseHasCookie(): void |
| 57 | + { |
| 58 | + $this->client->request('GET', '/response_cookie'); |
| 59 | + $this->assertResponseHasCookie('TESTCOOKIE'); |
| 60 | + } |
| 61 | + |
| 62 | + public function testAssertResponseHasHeader(): void |
| 63 | + { |
| 64 | + $this->client->request('GET', '/response_json'); |
| 65 | + $this->assertResponseHasHeader('content-type'); |
| 66 | + } |
| 67 | + |
| 68 | + public function testAssertResponseHeaderNotSame(): void |
| 69 | + { |
| 70 | + $this->client->request('GET', '/response_json'); |
| 71 | + $this->assertResponseHeaderNotSame('content-type', 'application/octet-stream'); |
| 72 | + } |
| 73 | + |
| 74 | + public function testAssertResponseHeaderSame(): void |
| 75 | + { |
| 76 | + $this->client->request('GET', '/response_json'); |
| 77 | + $this->assertResponseHeaderSame('content-type', 'application/json'); |
| 78 | + } |
| 79 | + |
| 80 | + public function testAssertResponseIsSuccessful(): void |
| 81 | + { |
| 82 | + $this->client->request('GET', '/'); |
| 83 | + $this->assertResponseIsSuccessful(); |
| 84 | + } |
| 85 | + |
| 86 | + public function testAssertResponseIsUnprocessable(): void |
| 87 | + { |
| 88 | + $this->client->request('GET', '/unprocessable_entity'); |
| 89 | + $this->assertResponseIsUnprocessable(); |
| 90 | + } |
| 91 | + |
| 92 | + public function testAssertResponseNotHasCookie(): void |
| 93 | + { |
| 94 | + $this->client->request('GET', '/'); |
| 95 | + $this->assertResponseNotHasCookie('TESTCOOKIE'); |
| 96 | + } |
| 97 | + |
| 98 | + public function testAssertResponseNotHasHeader(): void |
| 99 | + { |
| 100 | + $this->client->request('GET', '/'); |
| 101 | + $this->assertResponseNotHasHeader('accept-charset'); |
| 102 | + } |
| 103 | + |
| 104 | + public function testAssertResponseRedirects(): void |
| 105 | + { |
| 106 | + $this->client->followRedirects(false); |
| 107 | + $this->client->request('GET', '/redirect_home'); |
| 108 | + $this->assertResponseRedirects(); |
| 109 | + $this->assertResponseRedirects('/'); |
| 110 | + } |
| 111 | + |
| 112 | + public function testAssertResponseStatusCodeSame(): void |
| 113 | + { |
| 114 | + $this->client->followRedirects(false); |
| 115 | + $this->client->request('GET', '/redirect_home'); |
| 116 | + $this->assertResponseStatusCodeSame(302); |
| 117 | + } |
| 118 | + |
| 119 | + public function testAssertRouteSame(): void |
| 120 | + { |
| 121 | + $this->client->request('GET', '/'); |
| 122 | + $this->assertRouteSame('index'); |
| 123 | + $this->client->request('GET', '/login'); |
| 124 | + $this->assertRouteSame('app_login'); |
| 125 | + } |
| 126 | + |
| 127 | + public function testRebootClientKernel(): void |
| 128 | + { |
| 129 | + $this->markTestSkipped('This method relies on Codeception\Lib\Connector\Symfony::rebootKernel(), which is not available in KernelBrowser.'); |
| 130 | + } |
| 131 | + |
| 132 | + public function testSeePageIsAvailable(): void |
| 133 | + { |
| 134 | + $this->seePageIsAvailable('/login'); |
| 135 | + $this->client->request('GET', '/register'); |
| 136 | + $this->seePageIsAvailable(); |
| 137 | + } |
| 138 | + |
| 139 | + public function testSeePageRedirectsTo(): void |
| 140 | + { |
| 141 | + $this->seePageRedirectsTo('/dashboard', '/login'); |
| 142 | + } |
| 143 | + |
| 144 | + public function testSubmitSymfonyForm(): void |
| 145 | + { |
| 146 | + $this->client->request('GET', '/register'); |
| 147 | + $this->submitSymfonyForm('registration_form', [ |
| 148 | + '[email]' => 'jane_doe@gmail.com', |
| 149 | + '[password]' => '123456', |
| 150 | + '[agreeTerms]' => true, |
| 151 | + ]); |
| 152 | + $this->assertResponseRedirects('/dashboard'); |
| 153 | + } |
| 154 | +} |
0 commit comments