diff --git a/CHANGELOG.md b/CHANGELOG.md index f5182b269..d2b006e3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [3.32.1](https://github.com/sonata-project/SonataDoctrineORMAdminBundle/compare/3.32.0...3.32.1) - 2021-04-06 +### Fixed +- [[#1393](https://github.com/sonata-project/SonataDoctrineORMAdminBundle/pull/1393)] Added missing filter declaration in the config ([@VincentLanglet](https://github.com/VincentLanglet)) + ## [3.32.0](https://github.com/sonata-project/SonataDoctrineORMAdminBundle/compare/3.31.0...3.32.0) - 2021-03-30 ### Added - [[#1355](https://github.com/sonata-project/SonataDoctrineORMAdminBundle/pull/1355)] `ModelManager::reverseTransform()` ([@VincentLanglet](https://github.com/VincentLanglet)) diff --git a/composer.json b/composer.json index 38f62f997..844332e9a 100644 --- a/composer.json +++ b/composer.json @@ -63,6 +63,7 @@ "psalm/plugin-symfony": "^2.0", "sonata-project/block-bundle": "^4.2", "sonata-project/entity-audit-bundle": "^1.1", + "symfony/css-selector": "^4.4 || ^5.2", "symfony/panther": "^1.0", "symfony/phpunit-bridge": "^5.2", "symfony/templating": "^4.4 || ^5.2", diff --git a/tests/App/Admin/SubAdmin.php b/tests/App/Admin/SubAdmin.php new file mode 100644 index 000000000..6ef67ebc2 --- /dev/null +++ b/tests/App/Admin/SubAdmin.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\DoctrineORMAdminBundle\Tests\App\Admin; + +use Sonata\AdminBundle\Admin\AbstractAdmin; +use Sonata\AdminBundle\Datagrid\ListMapper; + +/** + * @phpstan-extends AbstractAdmin<\Sonata\DoctrineORMAdminBundle\Tests\App\Entity\Sub> + */ +final class SubAdmin extends AbstractAdmin +{ + protected function configureListFields(ListMapper $list): void + { + $list->addIdentifier('id'); + $list->add('otherField'); + } +} diff --git a/tests/App/DataFixtures/SubFixtures.php b/tests/App/DataFixtures/SubFixtures.php new file mode 100644 index 000000000..188d1f483 --- /dev/null +++ b/tests/App/DataFixtures/SubFixtures.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\DoctrineORMAdminBundle\Tests\App\DataFixtures; + +use Doctrine\Bundle\FixturesBundle\Fixture; +use Doctrine\Persistence\ObjectManager; +use Sonata\DoctrineORMAdminBundle\Tests\App\Entity\Sub; + +final class SubFixtures extends Fixture +{ + public function load(ObjectManager $manager): void + { + for ($i = 0; $i < 100; ++$i) { + $sub = new Sub(); + $manager->persist($sub); + } + + $manager->flush(); + } +} diff --git a/tests/App/Entity/Base.php b/tests/App/Entity/Base.php new file mode 100644 index 000000000..a02cbad5b --- /dev/null +++ b/tests/App/Entity/Base.php @@ -0,0 +1,46 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\DoctrineORMAdminBundle\Tests\App\Entity; + +use Doctrine\ORM\Mapping as ORM; + +/** + * @ORM\Entity() + * @ORM\InheritanceType("JOINED") + * @ORM\DiscriminatorColumn(name="discr", type="string") + * @ORM\DiscriminatorMap({ + * "sub" = "Sub" + * }) + */ +abstract class Base +{ + /** + * @ORM\Id + * @ORM\Column(type="integer") + * @ORM\GeneratedValue(strategy="AUTO") + * + * @var int|null + */ + private $id = null; + + public function getId(): ?int + { + return $this->id; + } + + public function setId(?int $id): void + { + $this->id = $id; + } +} diff --git a/tests/App/Entity/Sub.php b/tests/App/Entity/Sub.php new file mode 100644 index 000000000..842df6f84 --- /dev/null +++ b/tests/App/Entity/Sub.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\DoctrineORMAdminBundle\Tests\App\Entity; + +use Doctrine\ORM\Mapping as ORM; + +/** + * @ORM\Entity() + */ +class Sub extends Base +{ + /** + * @ORM\Column(options={"default"="HELLO WORLD"}) + * + * @var string + */ + private $otherField = 'HELLO WORLD'; +} diff --git a/tests/App/config/services.php b/tests/App/config/services.php index 653410e6d..2b0feca7d 100644 --- a/tests/App/config/services.php +++ b/tests/App/config/services.php @@ -16,11 +16,13 @@ use Sonata\DoctrineORMAdminBundle\Tests\App\Admin\CarAdmin; use Sonata\DoctrineORMAdminBundle\Tests\App\Admin\CategoryAdmin; use Sonata\DoctrineORMAdminBundle\Tests\App\Admin\ItemAdmin; +use Sonata\DoctrineORMAdminBundle\Tests\App\Admin\SubAdmin; use Sonata\DoctrineORMAdminBundle\Tests\App\Entity\Author; use Sonata\DoctrineORMAdminBundle\Tests\App\Entity\Book; use Sonata\DoctrineORMAdminBundle\Tests\App\Entity\Car; use Sonata\DoctrineORMAdminBundle\Tests\App\Entity\Category; use Sonata\DoctrineORMAdminBundle\Tests\App\Entity\Item; +use Sonata\DoctrineORMAdminBundle\Tests\App\Entity\Sub; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; return static function (ContainerConfigurator $containerConfigurator): void { @@ -31,7 +33,6 @@ ->load('Sonata\\DoctrineORMAdminBundle\\Tests\\App\\DataFixtures\\', dirname(__DIR__).'/DataFixtures') ->set(CategoryAdmin::class) - ->public() ->tag('sonata.admin', [ 'manager_type' => 'orm', 'label' => 'Category', @@ -43,7 +44,6 @@ ]) ->set(BookAdmin::class) - ->public() ->tag('sonata.admin', [ 'manager_type' => 'orm', 'label' => 'Book', @@ -55,7 +55,6 @@ ]) ->set(AuthorAdmin::class) - ->public() ->tag('sonata.admin', [ 'manager_type' => 'orm', 'label' => 'Author', @@ -68,7 +67,6 @@ ->call('setTemplate', ['outer_list_rows_list', 'author/list_outer_list_rows_list.html.twig']) ->set(CarAdmin::class) - ->public() ->tag('sonata.admin', [ 'manager_type' => 'orm', 'label' => 'Car', @@ -80,7 +78,6 @@ ]) ->set(ItemAdmin::class) - ->public() ->tag('sonata.admin', [ 'manager_type' => 'orm', 'label' => 'Command item', @@ -89,5 +86,16 @@ '', Item::class, null, + ]) + + ->set(SubAdmin::class) + ->tag('sonata.admin', [ + 'manager_type' => 'orm', + 'label' => 'Inheritance', + ]) + ->args([ + '', + Sub::class, + null, ]); }; diff --git a/tests/Functional/BaseFunctionalTestCase.php b/tests/Functional/BaseFunctionalTestCase.php new file mode 100644 index 000000000..0ca4611f9 --- /dev/null +++ b/tests/Functional/BaseFunctionalTestCase.php @@ -0,0 +1,37 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\DoctrineORMAdminBundle\Tests\Functional; + +use Sonata\DoctrineORMAdminBundle\Tests\App\AppKernel; +use Symfony\Bundle\FrameworkBundle\KernelBrowser; +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; + +abstract class BaseFunctionalTestCase extends WebTestCase +{ + /** + * @var KernelBrowser + */ + protected $client; + + protected function setUp(): void + { + $this->client = static::createClient(); + $this->client->followRedirects(); + } + + protected static function getKernelClass(): string + { + return AppKernel::class; + } +} diff --git a/tests/Functional/CRUDTest.php b/tests/Functional/CRUDTest.php index 0bd941e55..e0c7690af 100644 --- a/tests/Functional/CRUDTest.php +++ b/tests/Functional/CRUDTest.php @@ -16,22 +16,8 @@ use Sonata\DoctrineORMAdminBundle\Tests\App\Entity\Category; use Symfony\Component\HttpFoundation\Request; -final class CRUDTest extends BasePantherTestCase +final class CRUDTest extends BaseFunctionalTestCase { - public function testFilter(): void - { - $this->client->request(Request::METHOD_GET, '/admin/tests/app/category/list'); - - $this->client->clickLink('Filters'); - $this->client->clickLink('Name'); - - $this->client->submitForm('Filter', [ - 'filter[name][value]' => 'Novel', - ]); - - self::assertSelectorTextContains('.sonata-link-identifier', 'Novel'); - } - public function testList(): void { $this->client->request(Request::METHOD_GET, '/admin/tests/app/category/list'); diff --git a/tests/Functional/DatagridTest.php b/tests/Functional/DatagridTest.php new file mode 100644 index 000000000..2dc73458c --- /dev/null +++ b/tests/Functional/DatagridTest.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\DoctrineORMAdminBundle\Tests\Functional; + +use Symfony\Component\HttpFoundation\Request; + +final class DatagridTest extends BasePantherTestCase +{ + public function testFilter(): void + { + $this->client->request(Request::METHOD_GET, '/admin/tests/app/category/list'); + + $this->client->clickLink('Filters'); + $this->client->clickLink('Name'); + + $this->client->submitForm('Filter', [ + 'filter[name][value]' => 'Dystopian', + ]); + + self::assertSelectorTextContains('.sonata-link-identifier', 'Dystopian'); + } +} diff --git a/tests/Functional/EntityInheritanceTest.php b/tests/Functional/EntityInheritanceTest.php new file mode 100644 index 000000000..af67386b4 --- /dev/null +++ b/tests/Functional/EntityInheritanceTest.php @@ -0,0 +1,26 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\DoctrineORMAdminBundle\Tests\Functional; + +use Symfony\Component\HttpFoundation\Request; + +final class EntityInheritanceTest extends BaseFunctionalTestCase +{ + public function testList(): void + { + $this->client->request(Request::METHOD_GET, '/admin/tests/app/sub/list'); + + self::assertResponseIsSuccessful(); + } +}