Skip to content

Commit

Permalink
[Tests] Added tests coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk committed Sep 5, 2023
1 parent c7fabb1 commit 5f971ef
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
100 changes: 100 additions & 0 deletions tests/bundle/Templating/Twig/EmbeddedItemEditFormExtensionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Tests\Bundle\AdminUi\Templating\Twig;

use Ibexa\AdminUi\Form\Data\Content\Draft\ContentEditData;
use Ibexa\AdminUi\Form\Factory\FormFactory;
use Ibexa\Bundle\AdminUi\Templating\Twig\EmbeddedItemEditFormExtension;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\Routing\RouterInterface;
use Twig\Test\IntegrationTestCase;

/**
* @covers \Ibexa\Bundle\AdminUi\Templating\Twig\EmbeddedItemEditFormExtension
*/
final class EmbeddedItemEditFormExtensionTest extends IntegrationTestCase
{
private const FORM_ACTION = '/admin/content/edit';

protected function getExtensions(): array
{
return [
new EmbeddedItemEditFormExtension(
$this->createFormFactory(),
$this->createRouter()
),
];
}

/**
* @dataProvider getLegacyTests
* @group legacy
*/
public function testLegacyIntegration(
$file,
$message,
$condition,
$templates,
$exception,
$outputs,
$deprecation = ''
): void {
// disable Twig legacy integration test to avoid producing risky warning
self::markTestSkipped('This package does not contain Twig legacy integration test cases');
}

protected function getFixturesDir(): string
{
return __DIR__ . '/_fixtures/render_embedded_item_edit_form/';
}

private function createEditForm(): FormInterface
{
$editForm = $this->createMock(FormInterface::class);
$editForm
->expects(self::once())
->method('createView')
->willReturn(
$this->createMock(FormView::class)
);

return $editForm;
}

private function createFormFactory(): FormFactory
{
$formFactory = $this->createMock(FormFactory::class);
$formFactory
->expects(self::atLeastOnce())
->method('contentEdit')
->with(
new ContentEditData(),
'embedded_item_edit',
[
'action' => self::FORM_ACTION,
]
)
->willReturn($this->createEditForm());

return $formFactory;
}

private function createRouter(): RouterInterface
{
$router = $this->createMock(RouterInterface::class);
$router
->expects(self::once())
->method('generate')
->with('ibexa.content.edit')
->willReturn(self::FORM_ACTION);

return $router;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--TEST--
"ibexa_render_embedded_item_edit_form" function
--TEMPLATE--
{% set form = ibexa_render_embedded_item_edit_form() %}
{% if form is defined %} YES {% else %} NO {% endif %}
--DATA--
return [];
--EXPECT--
YES

0 comments on commit 5f971ef

Please sign in to comment.