From d411b0cf8629f8ec38a9ae84e9ced40684020303 Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Sat, 24 Apr 2021 08:36:57 +0200 Subject: [PATCH] Add functional test for simple pager It checks that the number of results from Pager must be the same as using Simple Pager --- tests/App/Admin/AuthorAdmin.php | 2 +- .../App/Admin/AuthorWithSimplePagerAdmin.php | 20 +++++++++++++ tests/App/config/services.php | 16 ++++++++++ tests/Functional/SimplePagerTest.php | 30 +++++++++++++++++++ 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 tests/App/Admin/AuthorWithSimplePagerAdmin.php create mode 100644 tests/Functional/SimplePagerTest.php diff --git a/tests/App/Admin/AuthorAdmin.php b/tests/App/Admin/AuthorAdmin.php index dcaf68f55..56cb5f574 100644 --- a/tests/App/Admin/AuthorAdmin.php +++ b/tests/App/Admin/AuthorAdmin.php @@ -26,7 +26,7 @@ /** * @phpstan-extends AbstractAdmin<\Sonata\DoctrineORMAdminBundle\Tests\App\Entity\Author> */ -final class AuthorAdmin extends AbstractAdmin +class AuthorAdmin extends AbstractAdmin { protected function configureListFields(ListMapper $list): void { diff --git a/tests/App/Admin/AuthorWithSimplePagerAdmin.php b/tests/App/Admin/AuthorWithSimplePagerAdmin.php new file mode 100644 index 000000000..928e5a03a --- /dev/null +++ b/tests/App/Admin/AuthorWithSimplePagerAdmin.php @@ -0,0 +1,20 @@ + + * + * 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; + +final class AuthorWithSimplePagerAdmin extends AuthorAdmin +{ + protected $baseRoutePattern = 'author-with-simple-pager'; + protected $baseRouteName = 'author_with_simple_pager'; +} diff --git a/tests/App/config/services.php b/tests/App/config/services.php index 2b0feca7d..4bc0d9b83 100644 --- a/tests/App/config/services.php +++ b/tests/App/config/services.php @@ -11,7 +11,9 @@ * file that was distributed with this source code. */ +use Sonata\AdminBundle\Datagrid\Pager; use Sonata\DoctrineORMAdminBundle\Tests\App\Admin\AuthorAdmin; +use Sonata\DoctrineORMAdminBundle\Tests\App\Admin\AuthorWithSimplePagerAdmin; use Sonata\DoctrineORMAdminBundle\Tests\App\Admin\BookAdmin; use Sonata\DoctrineORMAdminBundle\Tests\App\Admin\CarAdmin; use Sonata\DoctrineORMAdminBundle\Tests\App\Admin\CategoryAdmin; @@ -58,6 +60,20 @@ ->tag('sonata.admin', [ 'manager_type' => 'orm', 'label' => 'Author', + 'default' => true, + ]) + ->args([ + '', + Author::class, + null, + ]) + ->call('setTemplate', ['outer_list_rows_list', 'author/list_outer_list_rows_list.html.twig']) + + ->set(AuthorWithSimplePagerAdmin::class) + ->tag('sonata.admin', [ + 'manager_type' => 'orm', + 'label' => 'Author with Simple Pager', + 'pager_type' => Pager::TYPE_SIMPLE, ]) ->args([ '', diff --git a/tests/Functional/SimplePagerTest.php b/tests/Functional/SimplePagerTest.php new file mode 100644 index 000000000..de2561ddc --- /dev/null +++ b/tests/Functional/SimplePagerTest.php @@ -0,0 +1,30 @@ + + * + * 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 SimplePagerTest extends BaseFunctionalTestCase +{ + public function testSimplePagerSameResultsAsPager(): void + { + $crawlerWithPager = $this->client->request(Request::METHOD_GET, '/admin/tests/app/author/list'); + + $numberOfAuthors = $crawlerWithPager->filter('.js-author-item')->count(); + + $crawlerWithSimplePager = $this->client->request(Request::METHOD_GET, '/admin/author-with-simple-pager/list'); + + $this->assertSame($numberOfAuthors, $crawlerWithSimplePager->filter('.js-author-item')->count()); + } +}