|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace PhpList\RestBundle\Tests\Integration\Subscription\Controller; |
| 6 | + |
| 7 | +use PhpList\RestBundle\Subscription\Controller\SubscriberExportController; |
| 8 | +use PhpList\RestBundle\Tests\Integration\Common\AbstractTestController; |
| 9 | +use Symfony\Component\HttpFoundation\Response; |
| 10 | + |
| 11 | +class SubscriberExportControllerTest extends AbstractTestController |
| 12 | +{ |
| 13 | + public function testControllerIsAvailableViaContainer(): void |
| 14 | + { |
| 15 | + self::assertInstanceOf( |
| 16 | + SubscriberExportController::class, |
| 17 | + self::getContainer()->get(SubscriberExportController::class) |
| 18 | + ); |
| 19 | + } |
| 20 | + |
| 21 | + public function testExportSubscribersWithoutSessionKeyReturnsForbiddenStatus(): void |
| 22 | + { |
| 23 | + $this->jsonRequest('POST', '/api/v2/subscribers/export'); |
| 24 | + |
| 25 | + $this->assertHttpForbidden(); |
| 26 | + } |
| 27 | + |
| 28 | + public function testExportSubscribersWithInvalidRequestReturnsUnprocessableEntityStatus(): void |
| 29 | + { |
| 30 | + $this->authenticatedJsonRequest( |
| 31 | + 'POST', |
| 32 | + '/api/v2/subscribers/export', |
| 33 | + [], |
| 34 | + [], |
| 35 | + [], |
| 36 | + json_encode(['dateType' => 'invalid_type']) |
| 37 | + ); |
| 38 | + |
| 39 | + $this->assertHttpUnprocessableEntity(); |
| 40 | + } |
| 41 | + |
| 42 | + public function testExportSubscribersWithValidRequest(): void |
| 43 | + { |
| 44 | + $this->authenticatedJsonRequest( |
| 45 | + 'POST', |
| 46 | + '/api/v2/subscribers/export', |
| 47 | + [], |
| 48 | + [], |
| 49 | + [], |
| 50 | + json_encode([ |
| 51 | + 'dateType' => 'any', |
| 52 | + 'columns' => ['email', 'confirmed', 'blacklisted'] |
| 53 | + ]) |
| 54 | + ); |
| 55 | + |
| 56 | + $response = self::getClient()->getResponse(); |
| 57 | + self::assertSame(Response::HTTP_OK, $response->getStatusCode()); |
| 58 | + self::assertStringContainsString('text/csv', $response->headers->get('Content-Type')); |
| 59 | + self::assertStringContainsString( |
| 60 | + 'attachment; filename=subscribers_export_', |
| 61 | + $response->headers->get('Content-Disposition') |
| 62 | + ); |
| 63 | + } |
| 64 | + |
| 65 | + public function testExportSubscribersWithoutListIdFilter(): void |
| 66 | + { |
| 67 | + $this->authenticatedJsonRequest( |
| 68 | + 'POST', |
| 69 | + '/api/v2/subscribers/export', |
| 70 | + [], |
| 71 | + [], |
| 72 | + [], |
| 73 | + json_encode([ |
| 74 | + 'dateType' => 'any', |
| 75 | + 'columns' => ['email', 'confirmed', 'blacklisted'] |
| 76 | + ]) |
| 77 | + ); |
| 78 | + |
| 79 | + $response = self::getClient()->getResponse(); |
| 80 | + self::assertSame(Response::HTTP_OK, $response->getStatusCode()); |
| 81 | + self::assertStringContainsString('text/csv', $response->headers->get('Content-Type')); |
| 82 | + } |
| 83 | + |
| 84 | + public function testExportSubscribersWithSpecificColumns(): void |
| 85 | + { |
| 86 | + $this->authenticatedJsonRequest( |
| 87 | + 'POST', |
| 88 | + '/api/v2/subscribers/export', |
| 89 | + [], |
| 90 | + [], |
| 91 | + [], |
| 92 | + json_encode([ |
| 93 | + 'dateType' => 'any', |
| 94 | + 'columns' => ['email', 'confirmed'] |
| 95 | + ]) |
| 96 | + ); |
| 97 | + |
| 98 | + $response = self::getClient()->getResponse(); |
| 99 | + self::assertSame(Response::HTTP_OK, $response->getStatusCode()); |
| 100 | + self::assertStringContainsString('text/csv', $response->headers->get('Content-Type')); |
| 101 | + } |
| 102 | + |
| 103 | + public function testGetMethodIsNotAllowed(): void |
| 104 | + { |
| 105 | + $this->authenticatedJsonRequest('GET', '/api/v2/subscribers/export'); |
| 106 | + |
| 107 | + $this->assertHttpMethodNotAllowed(); |
| 108 | + } |
| 109 | +} |
0 commit comments