|
9 | 9 | use PhpList\RestBundle\Subscription\Controller\SubscriberController;
|
10 | 10 | use PhpList\RestBundle\Tests\Integration\Common\AbstractTestController;
|
11 | 11 | use PhpList\RestBundle\Tests\Integration\Subscription\Fixtures\SubscriberFixture;
|
| 12 | +use Symfony\Component\HttpFoundation\Response; |
12 | 13 |
|
13 | 14 | /**
|
14 | 15 | * Testcase.
|
@@ -165,4 +166,44 @@ public function testPostSubscribersWithValidSessionKeyAssignsProvidedSubscriberD
|
165 | 166 | static::assertTrue($responseContent['html_email']);
|
166 | 167 | static::assertFalse($responseContent['disabled']);
|
167 | 168 | }
|
| 169 | + public function testSetSubscriberAsConfirmedWithMissingUniqueIdReturnsBadRequestStatus() |
| 170 | + { |
| 171 | + self::getClient()->request('get', '/api/v2/subscribers/confirm'); |
| 172 | + |
| 173 | + $response = self::getClient()->getResponse(); |
| 174 | + self::assertSame(Response::HTTP_BAD_REQUEST, $response->getStatusCode()); |
| 175 | + self::assertStringContainsString('Missing confirmation code', $response->getContent()); |
| 176 | + } |
| 177 | + |
| 178 | + public function testSetSubscriberAsConfirmedWithInvalidUniqueIdReturnsNotFoundStatus() |
| 179 | + { |
| 180 | + self::getClient()->request('get', '/api/v2/subscribers/confirm', ['uniqueId' => 'invalid-unique-id']); |
| 181 | + |
| 182 | + $response = self::getClient()->getResponse(); |
| 183 | + self::assertSame(Response::HTTP_NOT_FOUND, $response->getStatusCode()); |
| 184 | + self::assertStringContainsString('Subscriber isn\'t found', $response->getContent()); |
| 185 | + } |
| 186 | + |
| 187 | + public function testSetSubscriberAsConfirmedWithValidUniqueIdConfirmsSubscriber() |
| 188 | + { |
| 189 | + |
| 190 | + $jsonData = ['email' => $email, 'requestConfirmation' => true]; |
| 191 | + |
| 192 | + $this->authenticatedJsonRequest('post', '/api/v2/subscribers', [], [], [], json_encode($jsonData)); |
| 193 | + $responseContent = $this->getDecodedJsonResponseContent(); |
| 194 | + $uniqueId = $responseContent['unique_id']; |
| 195 | + |
| 196 | + $subscriberId = $responseContent['id']; |
| 197 | + $subscriber = $this->subscriberRepository->find($subscriberId); |
| 198 | + self::assertFalse($subscriber->isConfirmed()); |
| 199 | + |
| 200 | + self::getClient()->request('get', '/api/v2/subscribers/confirm', ['uniqueId' => $uniqueId]); |
| 201 | + |
| 202 | + $response = self::getClient()->getResponse(); |
| 203 | + self::assertSame(Response::HTTP_OK, $response->getStatusCode()); |
| 204 | + self::assertStringContainsString('Thank you, your subscription is confirmed', $response->getContent()); |
| 205 | + |
| 206 | + $subscriber = $this->subscriberRepository->findOneByUniqueId($uniqueId); |
| 207 | + self::assertTrue($subscriber->isConfirmed()); |
| 208 | + } |
168 | 209 | }
|
0 commit comments