mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-22 14:56:12 +01:00
FEATURE: Allow to switch from search to filter mode
This commit is contained in:
parent
13004e86f2
commit
9a0d73f1c7
3 changed files with 127 additions and 0 deletions
|
@ -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.
|
||||||
*
|
*
|
||||||
|
|
|
@ -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.
|
||||||
|
|
99
Tests/Unit/Controller/SearchControllerTest.php
Normal file
99
Tests/Unit/Controller/SearchControllerTest.php
Normal 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.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue