-
-
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.
feature #5948 Add mode to search all/any terms
- Loading branch information
Showing
10 changed files
with
174 additions
and
18 deletions.
There are no files selected for viewing
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
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
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,9 @@ | ||
<?php | ||
|
||
namespace EasyCorp\Bundle\EasyAdminBundle\Config\Option; | ||
|
||
final class SearchMode | ||
{ | ||
public const ANY_TERMS = 'any_terms'; | ||
public const ALL_TERMS = 'all_terms'; | ||
} |
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
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
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
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
69 changes: 69 additions & 0 deletions
69
tests/Controller/Search/AllTermsCrudSearchControllerTest.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,69 @@ | ||
<?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\AllTermsCrudSearchController; | ||
|
||
class AllTermsCrudSearchControllerTest extends AbstractCrudTestCase | ||
{ | ||
protected function getControllerFqcn(): string | ||
{ | ||
return AllTermsCrudSearchController::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::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 | ||
$totalNumberOfPosts = 20; | ||
$numOfPostsWrittenByEachAuthor = 4; | ||
$numOfPostsPublishedByEachUser = 2; | ||
|
||
yield 'search by blog post title and author or publisher email no results' => [ | ||
'"Blog Post 10" "user4@"', | ||
0, | ||
]; | ||
|
||
yield 'search by blog post title and author or publisher email' => [ | ||
'Blog Post "user4@"', | ||
$numOfPostsWrittenByEachAuthor + $numOfPostsPublishedByEachUser, | ||
]; | ||
|
||
yield 'search by author and publisher email' => [ | ||
'user1 user2@', | ||
$numOfPostsPublishedByEachUser, | ||
]; | ||
|
||
yield 'search by author and publisher email no results' => [ | ||
'user1 user3@', | ||
0, | ||
]; | ||
|
||
yield 'search by author or publisher email' => [ | ||
'user4', | ||
$numOfPostsWrittenByEachAuthor + $numOfPostsPublishedByEachUser, | ||
]; | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
tests/TestApplication/src/Controller/Search/AllTermsCrudSearchController.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,23 @@ | ||
<?php | ||
|
||
namespace EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Controller\Search; | ||
|
||
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; | ||
use EasyCorp\Bundle\EasyAdminBundle\Config\Option\SearchMode; | ||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController; | ||
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\BlogPost; | ||
|
||
class AllTermsCrudSearchController extends AbstractCrudController | ||
{ | ||
public static function getEntityFqcn(): string | ||
{ | ||
return BlogPost::class; | ||
} | ||
|
||
public function configureCrud(Crud $crud): Crud | ||
{ | ||
return parent::configureCrud($crud) | ||
->setSearchFields(['title', 'author.email', 'publisher.email']) | ||
->setSearchMode(SearchMode::ALL_TERMS); | ||
} | ||
} |