|
| 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\Bundle\AdminUi\Templating\Twig; |
| 10 | + |
| 11 | +use Ibexa\AdminUi\Form\Data\Content\Draft\ContentEditData; |
| 12 | +use Ibexa\AdminUi\Form\Factory\FormFactory; |
| 13 | +use Ibexa\Bundle\AdminUi\Templating\Twig\EmbeddedItemEditFormExtension; |
| 14 | +use Symfony\Component\Form\FormInterface; |
| 15 | +use Symfony\Component\Form\FormView; |
| 16 | +use Symfony\Component\Routing\RouterInterface; |
| 17 | +use Twig\Test\IntegrationTestCase; |
| 18 | + |
| 19 | +/** |
| 20 | + * @covers \Ibexa\Bundle\AdminUi\Templating\Twig\EmbeddedItemEditFormExtension |
| 21 | + */ |
| 22 | +final class EmbeddedItemEditFormExtensionTest extends IntegrationTestCase |
| 23 | +{ |
| 24 | + private const FORM_ACTION = '/admin/content/edit'; |
| 25 | + |
| 26 | + protected function getExtensions(): array |
| 27 | + { |
| 28 | + return [ |
| 29 | + new EmbeddedItemEditFormExtension( |
| 30 | + $this->createFormFactory(), |
| 31 | + $this->createRouter() |
| 32 | + ), |
| 33 | + ]; |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * @dataProvider getLegacyTests |
| 38 | + * @group legacy |
| 39 | + * |
| 40 | + * @param string $file |
| 41 | + * @param string $message |
| 42 | + * @param string $condition |
| 43 | + * @param array<string> $templates |
| 44 | + * @param string $exception |
| 45 | + * @param array<mixed> $outputs |
| 46 | + * @param string $deprecation |
| 47 | + */ |
| 48 | + public function testLegacyIntegration( |
| 49 | + $file, |
| 50 | + $message, |
| 51 | + $condition, |
| 52 | + $templates, |
| 53 | + $exception, |
| 54 | + $outputs, |
| 55 | + $deprecation = '' |
| 56 | + ): void { |
| 57 | + // disable Twig legacy integration test to avoid producing risky warning |
| 58 | + self::markTestSkipped('This package does not contain Twig legacy integration test cases'); |
| 59 | + } |
| 60 | + |
| 61 | + protected function getFixturesDir(): string |
| 62 | + { |
| 63 | + return __DIR__ . '/_fixtures/render_embedded_item_edit_form/'; |
| 64 | + } |
| 65 | + |
| 66 | + private function createEditForm(): FormInterface |
| 67 | + { |
| 68 | + $editForm = $this->createMock(FormInterface::class); |
| 69 | + $editForm |
| 70 | + ->method('createView') |
| 71 | + ->willReturn( |
| 72 | + $this->createMock(FormView::class) |
| 73 | + ); |
| 74 | + |
| 75 | + return $editForm; |
| 76 | + } |
| 77 | + |
| 78 | + private function createFormFactory(): FormFactory |
| 79 | + { |
| 80 | + $formFactory = $this->createMock(FormFactory::class); |
| 81 | + $formFactory |
| 82 | + ->method('contentEdit') |
| 83 | + ->with( |
| 84 | + new ContentEditData(), |
| 85 | + 'embedded_item_edit', |
| 86 | + [ |
| 87 | + 'action' => self::FORM_ACTION, |
| 88 | + 'attr' => [ |
| 89 | + 'class' => 'ibexa-embedded-item-edit', |
| 90 | + ], |
| 91 | + ] |
| 92 | + ) |
| 93 | + ->willReturn($this->createEditForm()); |
| 94 | + |
| 95 | + return $formFactory; |
| 96 | + } |
| 97 | + |
| 98 | + private function createRouter(): RouterInterface |
| 99 | + { |
| 100 | + $router = $this->createMock(RouterInterface::class); |
| 101 | + $router |
| 102 | + ->method('generate') |
| 103 | + ->with('ibexa.content.edit') |
| 104 | + ->willReturn(self::FORM_ACTION); |
| 105 | + |
| 106 | + return $router; |
| 107 | + } |
| 108 | +} |
0 commit comments