-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a48f05
commit 4ea1c86
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
tests/Controller/Search/IdTermCrudSearchControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
]; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
tests/TestApplication/src/Controller/Search/IdTermCrudSearchController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
} | ||
} |