Skip to content

Commit

Permalink
[Testing] Add AdminTestCase (#62)
Browse files Browse the repository at this point in the history
* Add AdminTestCase

* Test

* add missing tests
  • Loading branch information
jordisala1991 committed Jul 7, 2020
1 parent 4cc6c62 commit 6f8d1b5
Show file tree
Hide file tree
Showing 26 changed files with 560 additions and 51 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "MIT",
"require": {
"php": "^7.3",
"a2lix/translation-form-bundle": "^2.4 || ^3.0",
"a2lix/translation-form-bundle": "^3.0",
"doctrine/common": "^2.12 || ^3.0",
"doctrine/data-fixtures": "^1.4",
"doctrine/dbal": "^2.10",
Expand All @@ -15,7 +15,8 @@
"gedmo/doctrine-extensions": "^2.4",
"knplabs/doctrine-behaviors": "^2.0.6",
"phpunit/phpunit": "^9.1.3",
"sonata-project/admin-bundle": "^3.61",
"sonata-project/admin-bundle": "^3.68",
"sonata-project/doctrine-orm-admin-bundle": "^3.20",
"sonata-project/easy-extends-bundle": "^2.5",
"sonata-project/media-bundle": "^3.24",
"symfony/config": "^4.4 || ^5.1",
Expand Down
6 changes: 4 additions & 2 deletions packages/basic-page-bundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@
],
"require": {
"php": "^7.3",
"a2lix/translation-form-bundle": "^2.4 || ^3.0",
"a2lix/translation-form-bundle": "^3.0",
"doctrine/doctrine-bundle": "^2.1",
"doctrine/orm": "^2.7",
"doctrine/persistence": "^1.3 || ^2.0",
"friendsofsymfony/ckeditor-bundle": "^1.2 || ^2.2",
"gedmo/doctrine-extensions": "^2.4",
"knplabs/doctrine-behaviors": "^2.0.6",
"runroom-packages/render-event-bundle": "^0.8",
"runroom-packages/seo-bundle": "^0.8",
"sonata-project/admin-bundle": "^3.61",
"sonata-project/admin-bundle": "^3.68",
"sonata-project/doctrine-orm-admin-bundle": "^3.20",
"symfony/config": "^4.4 || ^5.1",
"symfony/dependency-injection": "^4.4 || ^5.1",
"symfony/event-dispatcher": "^4.4 || ^5.1",
Expand Down
27 changes: 23 additions & 4 deletions packages/basic-page-bundle/tests/App/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@

namespace Runroom\BasicPageBundle\Tests\App;

use A2lix\AutoFormBundle\A2lixAutoFormBundle;
use A2lix\TranslationFormBundle\A2lixTranslationFormBundle;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle;
use FOS\CKEditorBundle\FOSCKEditorBundle;
use Knp\Bundle\MenuBundle\KnpMenuBundle;
use Knp\DoctrineBehaviors\DoctrineBehaviorsBundle;
use Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle;
use Runroom\BasicPageBundle\RunroomBasicPageBundle;
use Runroom\RenderEventBundle\RunroomRenderEventBundle;
use Runroom\SeoBundle\RunroomSeoBundle;
use Sonata\AdminBundle\SonataAdminBundle;
use Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Bundle\SecurityBundle\SecurityBundle;
Expand All @@ -36,16 +42,23 @@ class Kernel extends BaseKernel
public function registerBundles(): iterable
{
return [
new A2lixAutoFormBundle(),
new A2lixTranslationFormBundle(),
new DoctrineBehaviorsBundle(),
new DoctrineBundle(),
new FidryAliceDataFixturesBundle(),
new FOSCKEditorBundle(),
new FrameworkBundle(),
new KnpMenuBundle(),
new NelmioAliceBundle(),
new SecurityBundle(),
new SonataAdminBundle(),
new SonataDoctrineORMAdminBundle(),
new TwigBundle(),

new RunroomBasicPageBundle(),
new RunroomRenderEventBundle(),
new RunroomSeoBundle(),
new SecurityBundle(),
new TwigBundle(),
];
}

Expand All @@ -66,6 +79,8 @@ public function getProjectDir(): string

protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
$container->setParameter('kernel.default_locale', 'en');

$container->loadFromExtension('framework', [
'test' => true,
'router' => ['utf8' => true],
Expand All @@ -77,7 +92,7 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa
]);

$container->loadFromExtension('doctrine', [
'dbal' => ['url' => 'sqlite://:memory:'],
'dbal' => ['url' => 'sqlite://:memory:', 'logging' => false],
'orm' => ['auto_mapping' => true],
]);

Expand All @@ -86,8 +101,12 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa
'strict_variables' => '%kernel.debug%',
]);

$container->loadFromExtension('a2lix_translation_form', [
'locales' => ['es', 'en', 'ca'],
]);

$container->loadFromExtension('runroom_seo', [
'locales' => ['es'],
'locales' => ['es', 'en', 'ca'],
'xdefault_locale' => 'es',
'class' => ['media' => Media::class],
]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Runroom package.
*
* (c) Runroom <runroom@runroom.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Runroom\BasicPageBundle\Tests\Integration;

use Runroom\BasicPageBundle\Admin\BasicPageAdmin;
use Runroom\Testing\TestCase\SonataAdminTestCase;

class BasicPageAdminTest extends SonataAdminTestCase
{
/** @test */
public function itHasAllListFields(): void
{
$this->assertAdminListContainsField('title');
$this->assertAdminListContainsField('location');
$this->assertAdminListContainsField('publish');
$this->assertAdminListContainsField('_action');
}

/** @test */
public function itHasAllFormFields(): void
{
$this->assertAdminFormContainsField('translations');
$this->assertAdminFormContainsField('publish');
$this->assertAdminFormContainsField('location');
$this->assertAdminFormContainsField('metaInformation');
}

/** @test */
public function itHasAllFilterFields(): void
{
$this->assertAdminFilterContainsField('translations.title');
$this->assertAdminFilterContainsField('publish');
}

protected function getAdminClass(): string
{
return BasicPageAdmin::class;
}
}
2 changes: 1 addition & 1 deletion packages/ckeditor-sonata-media-bundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"require": {
"php": "^7.3",
"sonata-project/admin-bundle": "^3.61",
"sonata-project/admin-bundle": "^3.68",
"sonata-project/media-bundle": "^3.24",
"symfony/config": "^4.4 || ^5.1",
"symfony/dependency-injection": "^4.4 || ^5.1",
Expand Down
5 changes: 3 additions & 2 deletions packages/cookies-bundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@
],
"require": {
"php": "^7.3",
"a2lix/translation-form-bundle": "^2.4 || ^3.0",
"a2lix/translation-form-bundle": "^3.0",
"doctrine/doctrine-bundle": "^2.1",
"doctrine/orm": "^2.7",
"doctrine/persistence": "^1.3 || ^2.0",
"friendsofsymfony/ckeditor-bundle": "^1.2 || ^2.2",
"knplabs/doctrine-behaviors": "^2.0.6",
"runroom-packages/form-handler-bundle": "^0.8",
"runroom-packages/render-event-bundle": "^0.8",
"sonata-project/admin-bundle": "^3.61",
"sonata-project/admin-bundle": "^3.68",
"sonata-project/doctrine-orm-admin-bundle": "^3.20",
"symfony/config": "^4.4 || ^5.1",
"symfony/dependency-injection": "^4.4 || ^5.1",
"symfony/event-dispatcher": "^4.4 || ^5.1",
Expand Down
27 changes: 23 additions & 4 deletions packages/cookies-bundle/tests/App/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@

namespace Runroom\CookiesBundle\Tests\App;

use A2lix\AutoFormBundle\A2lixAutoFormBundle;
use A2lix\TranslationFormBundle\A2lixTranslationFormBundle;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle;
use FOS\CKEditorBundle\FOSCKEditorBundle;
use Knp\Bundle\MenuBundle\KnpMenuBundle;
use Knp\DoctrineBehaviors\DoctrineBehaviorsBundle;
use Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle;
use Runroom\CookiesBundle\RunroomCookiesBundle;
use Runroom\FormHandlerBundle\RunroomFormHandlerBundle;
use Runroom\RenderEventBundle\RunroomRenderEventBundle;
use Sonata\AdminBundle\SonataAdminBundle;
use Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Bundle\SecurityBundle\SecurityBundle;
Expand All @@ -36,16 +42,23 @@ class Kernel extends BaseKernel
public function registerBundles(): iterable
{
return [
new A2lixAutoFormBundle(),
new A2lixTranslationFormBundle(),
new DoctrineBehaviorsBundle(),
new DoctrineBundle(),
new KnpMenuBundle(),
new FidryAliceDataFixturesBundle(),
new FOSCKEditorBundle(),
new FrameworkBundle(),
new NelmioAliceBundle(),
new SecurityBundle(),
new SonataAdminBundle(),
new SonataDoctrineORMAdminBundle(),
new TwigBundle(),

new RunroomFormHandlerBundle(),
new RunroomRenderEventBundle(),
new RunroomCookiesBundle(),
new SecurityBundle(),
new TwigBundle(),
];
}

Expand All @@ -66,19 +79,21 @@ public function getProjectDir(): string

protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
$container->setParameter('kernel.default_locale', 'en');

$container->loadFromExtension('framework', [
'test' => true,
'router' => ['utf8' => true],
'secret' => 'secret',
'session' => null,
'session' => ['storage_id' => 'session.storage.mock_file'],
]);

$container->loadFromExtension('security', [
'firewalls' => ['main' => ['anonymous' => true]],
]);

$container->loadFromExtension('doctrine', [
'dbal' => ['url' => 'sqlite://:memory:'],
'dbal' => ['url' => 'sqlite://:memory:', 'logging' => false],
'orm' => ['auto_mapping' => true],
]);

Expand All @@ -87,6 +102,10 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa
'strict_variables' => '%kernel.debug%',
]);

$container->loadFromExtension('a2lix_translation_form', [
'locales' => ['es', 'en', 'ca'],
]);

$container->loadFromExtension('runroom_cookies', [
'cookies' => [
'mandatory_cookies' => [[
Expand Down
42 changes: 42 additions & 0 deletions packages/cookies-bundle/tests/Integration/CookiesPageAdminTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Runroom package.
*
* (c) Runroom <runroom@runroom.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Runroom\CookiesPageBundle\Tests\Integration;

use Runroom\CookiesBundle\Admin\CookiesPageAdmin;
use Runroom\Testing\TestCase\SonataAdminTestCase;

class CookiesPageAdminTest extends SonataAdminTestCase
{
/** @test */
public function itHasAllFormFields(): void
{
$this->assertAdminFormContainsField('translations');
}

/** @test */
public function itDoesNotHaveDisabledRoutes(): void
{
$this->assertAdminRoutesDoesContainRoute('edit');
$this->assertAdminRoutesDoesNotContainRoute('show');
$this->assertAdminRoutesDoesNotContainRoute('delete');
$this->assertAdminRoutesDoesNotContainRoute('list');
$this->assertAdminRoutesDoesNotContainRoute('batch');
$this->assertAdminRoutesDoesNotContainRoute('export');
}

protected function getAdminClass(): string
{
return CookiesPageAdmin::class;
}
}
3 changes: 2 additions & 1 deletion packages/redirection-bundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"doctrine/doctrine-bundle": "^2.1",
"doctrine/orm": "^2.7",
"doctrine/persistence": "^1.3 || ^2.0",
"sonata-project/admin-bundle": "^3.61",
"sonata-project/admin-bundle": "^3.68",
"sonata-project/doctrine-orm-admin-bundle": "^3.20",
"symfony/config": "^4.4 || ^5.1",
"symfony/dependency-injection": "^4.4 || ^5.1",
"symfony/doctrine-bridge": "^4.4 || ^5.1",
Expand Down
22 changes: 21 additions & 1 deletion packages/redirection-bundle/tests/App/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@

use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle;
use Knp\Bundle\MenuBundle\KnpMenuBundle;
use Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle;
use Runroom\RedirectionBundle\RunroomRedirectionBundle;
use Sonata\AdminBundle\SonataAdminBundle;
use Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Bundle\SecurityBundle\SecurityBundle;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
Expand All @@ -34,7 +39,13 @@ public function registerBundles(): iterable
new DoctrineBundle(),
new FidryAliceDataFixturesBundle(),
new FrameworkBundle(),
new KnpMenuBundle(),
new NelmioAliceBundle(),
new SecurityBundle(),
new SonataAdminBundle(),
new SonataDoctrineORMAdminBundle(),
new TwigBundle(),

new RunroomRedirectionBundle(),
];
}
Expand Down Expand Up @@ -62,8 +73,12 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa
'secret' => 'secret',
]);

$container->loadFromExtension('security', [
'firewalls' => ['main' => ['anonymous' => true]],
]);

$container->loadFromExtension('doctrine', [
'dbal' => ['url' => 'sqlite://:memory:'],
'dbal' => ['url' => 'sqlite://:memory:', 'logging' => false],
'orm' => [
'auto_mapping' => true,
'mappings' => [
Expand All @@ -77,6 +92,11 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa
],
]);

$container->loadFromExtension('twig', [
'exception_controller' => null,
'strict_variables' => '%kernel.debug%',
]);

$container->loadFromExtension('runroom_redirection', [
'enable_automatic_redirections' => true,
'automatic_redirections' => [
Expand Down
Loading

0 comments on commit 6f8d1b5

Please sign in to comment.