Skip to content

Commit

Permalink
feature #1111 Updated the behavior of empty searches (javiereguiluz)
Browse files Browse the repository at this point in the history
This PR was merged into the master branch.

Discussion
----------

Updated the behavior of empty searches

New behavior:

  * If the query is really an empty string, redirect to "list"
  * If the query is empty because it just contains white spaces, don't treat it in a special way (before we redirected it to "list" too)

Commits
-------

68a76dc Updated the behavior of empty searches
  • Loading branch information
javiereguiluz committed Apr 26, 2016
2 parents dbba426 + 68a76dc commit 4ebb10e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ protected function searchAction()
$this->dispatch(EasyAdminEvents::PRE_SEARCH);

// if the search query is empty, redirect to the 'list' action
if ('' === trim($this->request->query->get('query'))) {
if ('' === $this->request->query->get('query')) {
$queryParameters = array_replace($this->request->query->all(), array('action' => 'list', 'query' => null));
$queryParameters = array_filter($queryParameters);

Expand Down
23 changes: 11 additions & 12 deletions Tests/Controller/DefaultBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,27 +506,26 @@ public function testSearchViewTitle()
$this->assertEquals('<strong>200</strong> results found', trim($crawler->filter('h1.title')->html()), 'The visible content contains HTML tags.');
}

/**
* @dataProvider provideEmptyQueries
*/
public function testSearchViewEmptyQuery($emptyQuery)
public function testSearchViewEmptyQuery()
{
// empty queries redirect to "list" action
$this->getBackendPage(array(
'action' => 'search',
'entity' => 'Category',
'query' => $emptyQuery,
'query' => '',
));

$this->assertEquals(302, $this->client->getResponse()->getStatusCode());
$this->assertEquals('/admin/?action=list&entity=Category&sortField=id&sortDirection=DESC', $this->client->getResponse()->headers->get('location'));
}

public function provideEmptyQueries()
{
return array(
array(''),
array(' '),
);
// pseudo-empty queries (e.g. strings which only contain white spaces) don't redirect to "list" action
$crawler = $this->getBackendPage(array(
'action' => 'search',
'entity' => 'Category',
'query' => ' ',
));

$this->assertEquals('No results found', $crawler->filter('h1.title')->text());
}

public function testSearchViewTableIdColumn()
Expand Down

0 comments on commit 4ebb10e

Please sign in to comment.