Skip to content

Commit

Permalink
Add functional test to AdminExtractor
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu authored and jordisala1991 committed Jul 28, 2020
1 parent 3279324 commit 8bb0c21
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 1 deletion.
43 changes: 43 additions & 0 deletions tests/App/Admin/TranslatedAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?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\AdminBundle\Tests\App\Admin;

use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\AdminBundle\Templating\TemplateRegistry;
use Symfony\Component\Form\Extension\Core\Type\TextType;

final class TranslatedAdmin extends AbstractAdmin
{
protected function configureListFields(ListMapper $list)
{
$list->add('name_list', TemplateRegistry::TYPE_STRING);
}

protected function configureFormFields(FormMapper $form)
{
$form
->add('name_form', TextType::class, ['help' => 'Help me!'])
->ifTrue($this->getSubject()->isPublished)
->add('datePublished')
->ifEnd();
}

protected function configureShowFields(ShowMapper $show)
{
$show->add('name_show', TemplateRegistry::TYPE_STRING);
}
}
3 changes: 3 additions & 0 deletions tests/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ protected function configureContainer(ContainerBuilder $containerBuilder, Loader
'session' => ['handler_id' => 'session.handler.native_file', 'storage_id' => 'session.storage.mock_file', 'name' => 'MOCKSESSID'],
'assets' => null,
'test' => true,
'translator' => [
'default_path' => '%kernel.project_dir%/translations',
],
]);

$containerBuilder->loadFromExtension('security', [
Expand Down
7 changes: 6 additions & 1 deletion tests/App/Model/ModelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ public function getUrlSafeIdentifier($model)

public function getModelInstance($class)
{
return new Foo('test_id', 'foo_name');
switch ($class) {
case Translated::class:
return new Translated();
default:
return new Foo('test_id', 'foo_name');
}
}

public function getModelCollectionInstance($class)
Expand Down
21 changes: 21 additions & 0 deletions tests/App/Model/Translated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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\AdminBundle\Tests\App\Model;

final class Translated
{
public $nameForm;
public $isPublished = true;
public $datePublished;
}
5 changes: 5 additions & 0 deletions tests/App/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ services:
arguments: [~, Sonata\AdminBundle\Tests\App\Model\Foo, ~]
tags:
- {name: sonata.admin, manager_type: test, label: Empty}

Sonata\AdminBundle\Tests\App\Admin\TranslatedAdmin:
arguments: [~, Sonata\AdminBundle\Tests\App\Model\Translated, ~]
tags:
- {name: sonata.admin, manager_type: test, group: 'group_label', label: 'admin_label'}
48 changes: 48 additions & 0 deletions tests/Functional/Translator/Extractor/AdminExtractorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?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\AdminBundle\Tests\Functional\Translator\Extractor;

use Sonata\AdminBundle\Tests\App\AppKernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;

final class AdminExtractorTest extends KernelTestCase
{
public function testDebugMissingMessages(): void
{
$tester = $this->createCommandTester();
$tester->execute(['locale' => 'en']);

$this->assertRegExp('/group_label/', $tester->getDisplay());
$this->assertRegExp('/admin_label/', $tester->getDisplay());
$this->assertRegExp('/Name Show/', $tester->getDisplay());
$this->assertRegExp('/Name List/', $tester->getDisplay());
$this->assertRegExp('/Name Form/', $tester->getDisplay());
$this->assertRegExp('/Date Published/', $tester->getDisplay());
}

protected static function getKernelClass(): string
{
return AppKernel::class;
}

private function createCommandTester(): CommandTester
{
$kernel = static::createKernel();
$application = new Application($kernel);

return new CommandTester($application->find('debug:translation'));
}
}

0 comments on commit 8bb0c21

Please sign in to comment.