FEATURE: Allow to switch from search to filter mode

This commit is contained in:
Daniel Siepmann 2017-09-15 22:26:52 +02:00
parent 13004e86f2
commit 9a0d73f1c7
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
3 changed files with 127 additions and 0 deletions

View file

@ -44,6 +44,17 @@ class SearchController extends ActionController
parent::__construct(); parent::__construct();
} }
public function initializeSearchAction()
{
if (isset($this->settings['searching']['mode']) && $this->settings['searching']['mode'] === 'filter'
&& $this->request->hasArgument('searchRequest') === false
) {
$this->request->setArguments([
'searchRequest' => $this->objectManager->get(SearchRequest::class),
]);
}
}
/** /**
* Process a search and deliver original request and result to view. * Process a search and deliver original request and result to view.
* *

View file

@ -346,3 +346,20 @@ Searching
factor = 2 factor = 2
missing = 1 missing = 1
} }
.. _mode:
``mode``
""""""""
Used by: Controller while preparing action.
Define to switch from search to filter mode.
Example::
plugin.tx_searchcore.settings.searching {
mode = filter
}
Only ``filter`` is allowed as value. Will submit an empty query to switch to filter mode.

View file

@ -0,0 +1,99 @@
<?php
namespace Codappix\Tests\Unit\Controller;
/*
* Copyright (C) 2017 Daniel Siepmann <coding@daniel-siepmann.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
use Codappix\SearchCore\Controller\SearchController;
use Codappix\SearchCore\Domain\Model\SearchRequest;
use Codappix\SearchCore\Domain\Search\SearchService;
use Codappix\SearchCore\Tests\Unit\AbstractUnitTestCase;
use TYPO3\CMS\Extbase\Mvc\Web\Request;
use TYPO3\CMS\Extbase\Object\ObjectManager;
class SearchControllerTest extends AbstractUnitTestCase
{
/**
* @var SearchController
*/
protected $subject;
/**
* @var Request
*/
protected $request;
public function setUp()
{
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
\TYPO3\CMS\Core\Cache\CacheManager::class
)->setCacheConfigurations([
'extbase_object' => [
'backend' => \TYPO3\CMS\Core\Cache\Backend\NullBackend::class,
],
'extbase_datamapfactory_datamap' => [
'backend' => \TYPO3\CMS\Core\Cache\Backend\NullBackend::class,
],
]);
parent::setUp();
$searchService = $this->getMockBuilder(SearchService::class)
->disableOriginalConstructor()
->getMock();
$this->request = new Request();
$this->subject = new SearchController($searchService);
$this->inject($this->subject, 'request', $this->request);
$this->inject($this->subject, 'objectManager', new ObjectManager());
}
/**
* @test
*/
public function searchRequestArgumentIsAddedIfModeIsFilterAndArgumentDoesNotExist()
{
$this->inject($this->subject, 'settings', [
'searching' => [
'mode' => 'filter',
]
]);
$this->subject->initializeSearchAction();
$this->assertInstanceOf(
SearchRequest::class,
$this->request->getArgument('searchRequest'),
'Search request was not created.'
);
}
/**
* @test
*/
public function searchRequestArgumentIsNotAddedIfModeIsNotFilter()
{
$this->inject($this->subject, 'settings', ['searching' => []]);
$this->subject->initializeSearchAction();
$this->assertFalse(
$this->request->hasArgument('searchRequest'),
'Search request should not exist.'
);
}
}