Skip to content

Commit

Permalink
Add functional test for crud
Browse files Browse the repository at this point in the history
  • Loading branch information
jordisala1991 committed Aug 10, 2022
1 parent d660cf8 commit 67fc54d
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"twig/twig": "^2.12.1 || ^3.0"
},
"require-dev": {
"dama/doctrine-test-bundle": "^6.7",
"doctrine/annotations": "^1.13.3",
"friendsofphp/php-cs-fixer": "^3.4",
"matthiasnoback/symfony-dependency-injection-test": "^4.1.1",
Expand Down
4 changes: 4 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ It's auto-generated by sonata-project/dev-kit package.
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>

<extensions>
<extension class="DAMA\DoctrineTestBundle\PHPUnit\PHPUnitExtension" />
</extensions>

<php>
<ini name="precision" value="8" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0" />
Expand Down
2 changes: 2 additions & 0 deletions tests/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Sonata\PageBundle\Tests\App;

use DAMA\DoctrineTestBundle\DAMADoctrineTestBundle;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Knp\Bundle\MenuBundle\KnpMenuBundle;
use Sonata\AdminBundle\SonataAdminBundle;
Expand Down Expand Up @@ -52,6 +53,7 @@ public function __construct()
public function registerBundles(): iterable
{
$bundles = [
new DAMADoctrineTestBundle(),
new FrameworkBundle(),
new TwigBundle(),
new SecurityBundle(),
Expand Down
93 changes: 93 additions & 0 deletions tests/Functional/Admin/PageAdminTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\PageBundle\Tests\Functional\Admin;

use Doctrine\ORM\EntityManagerInterface;
use Sonata\PageBundle\Tests\App\AppKernel;
use Sonata\PageBundle\Tests\App\Entity\SonataPageBlock;
use Sonata\PageBundle\Tests\App\Entity\SonataPagePage;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpKernel\KernelInterface;

final class MediaAdminTest extends WebTestCase
{
/**
* @dataProvider provideCrudUrlsCases
*
* @param array<string, mixed> $parameters
*/
public function testCrudUrls(string $url, array $parameters = []): void
{
$client = self::createClient();

$this->prepareData();

$client->request('GET', $url, $parameters);

self::assertResponseIsSuccessful();
}

/**
* @return iterable<array<string|array<string, mixed>>>
*
* @phpstan-return iterable<array{0: string, 1?: array<string, mixed>}>
*/
public static function provideCrudUrlsCases(): iterable
{
yield 'Tree Page' => ['/admin/tests/app/sonatapagepage/tree'];

yield 'List Page' => ['/admin/tests/app/sonatapagepage/list', ['filter' => [
'name' => ['value' => 'name'],
]]];

yield 'Create Page' => ['/admin/tests/app/sonatapagepage/create'];
yield 'Edit Page' => ['/admin/tests/app/sonatapagepage/1/edit'];
yield 'Remove Page' => ['/admin/tests/app/sonatapagepage/1/delete'];
yield 'Compose Page' => ['/admin/tests/app/sonatapagepage/1/compose'];
yield 'Compose Show Page' => ['/admin/tests/app/sonatapagepage/compose/container/1'];
}

/**
* @return class-string<KernelInterface>
*/
protected static function getKernelClass(): string
{
return AppKernel::class;
}

/**
* @psalm-suppress UndefinedPropertyFetch
*/
private function prepareData(): void
{
// TODO: Simplify this when dropping support for Symfony 4.
// @phpstan-ignore-next-line
$container = method_exists($this, 'getContainer') ? self::getContainer() : self::$container;
$manager = $container->get('doctrine.orm.entity_manager');
\assert($manager instanceof EntityManagerInterface);

$page = new SonataPagePage();
$page->setName('name');
$page->setTemplateCode('default');

$block = new SonataPageBlock();
$block->setType('sonata.page.block.container');
$block->setPage($page);

$manager->persist($page);
$manager->persist($block);

$manager->flush();
}
}

0 comments on commit 67fc54d

Please sign in to comment.