|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * @copyright Copyright (C) Ibexa AS. All rights reserved. |
| 5 | + * @license For full copyright and license information view LICENSE file distributed with this source code. |
| 6 | + */ |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Ibexa\Tests\Integration\FieldTypeRichText\REST; |
| 10 | + |
| 11 | +use Ibexa\Contracts\Test\Rest\WebTestCase; |
| 12 | + |
| 13 | +final class RichTextConfigTest extends WebTestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @dataProvider provideForTestConfig |
| 17 | + */ |
| 18 | + public function testConfig( |
| 19 | + string $type, |
| 20 | + string $acceptHeader, |
| 21 | + string $snapshot |
| 22 | + ): void { |
| 23 | + $this->client->request('GET', '/api/ibexa/v2/richtext-config', [], [], [ |
| 24 | + 'HTTP_ACCEPT' => $acceptHeader, |
| 25 | + ]); |
| 26 | + |
| 27 | + $this->assertResponseIsSuccessful(); |
| 28 | + $response = $this->client->getResponse(); |
| 29 | + $content = $response->getContent(); |
| 30 | + self::assertIsString($content); |
| 31 | + |
| 32 | + if ($type === 'xml') { |
| 33 | + self::assertSame('application/vnd.ibexa.api.RichTextConfig+xml', $response->headers->get('Content-Type')); |
| 34 | + self::assertResponseMatchesXmlSnapshot($content, $snapshot); |
| 35 | + } elseif ($type === 'json') { |
| 36 | + self::assertSame('application/vnd.ibexa.api.RichTextConfig+json', $response->headers->get('Content-Type')); |
| 37 | + self::assertResponseMatchesJsonSnapshot($content, $snapshot); |
| 38 | + } else { |
| 39 | + throw new \LogicException(sprintf( |
| 40 | + 'Unknown type: "%s". Expected one of: "%s"', |
| 41 | + $type, |
| 42 | + implode('", "', ['json', 'xml']), |
| 43 | + )); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * @return iterable<array{ |
| 49 | + * 'xml'|'json', |
| 50 | + * non-empty-string, |
| 51 | + * non-empty-string, |
| 52 | + * }> |
| 53 | + */ |
| 54 | + public static function provideForTestConfig(): iterable |
| 55 | + { |
| 56 | + yield 'application/vnd.ibexa.api.RichTextConfig+json' => [ |
| 57 | + 'json', |
| 58 | + 'application/vnd.ibexa.api.RichTextConfig+json', |
| 59 | + __DIR__ . '/_output/RichTextConfig.json', |
| 60 | + ]; |
| 61 | + |
| 62 | + yield 'application/json' => [ |
| 63 | + 'json', |
| 64 | + 'application/json', |
| 65 | + __DIR__ . '/_output/RichTextConfig.json', |
| 66 | + ]; |
| 67 | + |
| 68 | + yield 'application/vnd.ibexa.api.RichTextConfig+xml' => [ |
| 69 | + 'xml', |
| 70 | + 'application/vnd.ibexa.api.RichTextConfig+xml', |
| 71 | + __DIR__ . '/_output/RichTextConfig.xml', |
| 72 | + ]; |
| 73 | + |
| 74 | + yield 'application/xml' => [ |
| 75 | + 'xml', |
| 76 | + 'application/xml', |
| 77 | + __DIR__ . '/_output/RichTextConfig.xml', |
| 78 | + ]; |
| 79 | + } |
| 80 | +} |
0 commit comments