Skip to content

Commit

Permalink
add empty queryTermConditions tests
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-sainthillier committed Mar 25, 2024
1 parent 260a133 commit a553334
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
51 changes: 51 additions & 0 deletions tests/Controller/Search/IdTermCrudSearchControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace EasyCorp\Bundle\EasyAdminBundle\Tests\Controller\Search;

use EasyCorp\Bundle\EasyAdminBundle\Test\AbstractCrudTestCase;
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Controller\DashboardController;
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Controller\Search\IdTermCrudSearchController;

class IdTermCrudSearchControllerTest extends AbstractCrudTestCase
{
protected function getControllerFqcn(): string
{
return IdTermCrudSearchController::class;
}

protected function getDashboardFqcn(): string
{
return DashboardController::class;
}

protected function setUp(): void
{
parent::setUp();
$this->client->followRedirects();
}

/**
* @dataProvider provideSearchTests
*/
public function testSearch(string $query, int $expectedResultCount)
{
$this->client->request('GET', $this->generateIndexUrl($query));
static::assertResponseIsSuccessful();
static::assertIndexFullEntityCount($expectedResultCount);
}

public static function provideSearchTests(): iterable
{
// the CRUD Controller associated to this test has configured the search
// properties used by the search engine. That's why results are not the default ones
yield 'search by non numeric query yields no results' => [
'blog post',
0,
];

yield 'search by id yield 1 result' => [
'15',
1,
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Controller\Search;

use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\BlogPost;

class IdTermCrudSearchController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return BlogPost::class;
}

public function configureCrud(Crud $crud): Crud
{
return parent::configureCrud($crud)
->setSearchFields(['id']);
}
}

0 comments on commit a553334

Please sign in to comment.