mirror of
https://github.com/Codappix/search_core.git
synced 2024-12-26 12:36:09 +01:00
Daniel Siepmann
82d397c428
Before this change, sys_language_uid was indexed as an empty string, due to internal used TYPO3 API. We now skip the configure field which defines language uid. This way you can build filter based on current language. Resolves #148
112 lines
4.3 KiB
PHP
112 lines
4.3 KiB
PHP
<?php
|
|
namespace Codappix\SearchCore\Tests\Indexing;
|
|
|
|
/*
|
|
* Copyright (C) 2016 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\Configuration\ConfigurationContainerInterface;
|
|
use Codappix\SearchCore\Connection\Elasticsearch;
|
|
use Codappix\SearchCore\Domain\Index\TcaIndexer;
|
|
use Codappix\SearchCore\Domain\Index\TcaIndexer\RelationResolver;
|
|
use Codappix\SearchCore\Domain\Index\TcaIndexer\TcaTableServiceInterface;
|
|
use Codappix\SearchCore\Tests\Functional\AbstractFunctionalTestCase;
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
|
|
|
class TcaIndexerTest extends AbstractFunctionalTestCase
|
|
{
|
|
protected function getTypoScriptFilesForFrontendRootPage()
|
|
{
|
|
return array_merge(
|
|
parent::getTypoScriptFilesForFrontendRootPage(),
|
|
['EXT:search_core/Tests/Functional/Fixtures/Indexing/TcaIndexer/RespectRootLineBlacklist.ts']
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function respectRootLineBlacklist()
|
|
{
|
|
$this->importDataSet('Tests/Functional/Fixtures/Indexing/TcaIndexer/RespectRootLineBlacklist.xml');
|
|
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class);
|
|
$tableName = 'tt_content';
|
|
$tableService = $objectManager->get(
|
|
TcaTableServiceInterface::class,
|
|
$tableName,
|
|
$objectManager->get(RelationResolver::class),
|
|
$objectManager->get(ConfigurationContainerInterface::class)
|
|
);
|
|
|
|
$connection = $this->getMockBuilder(Elasticsearch::class)
|
|
->setMethods(['addDocuments'])
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$connection->expects($this->once())
|
|
->method('addDocuments')
|
|
->with(
|
|
$this->stringContains('tt_content'),
|
|
$this->callback(function ($documents) {
|
|
foreach ($documents as $document) {
|
|
// Page uids 1 and 2 are allowed while 3 and 4 are not allowed.
|
|
// Therefore only documents with page uid 1 and 2 should exist.
|
|
if (! isset($document['pid']) || ! in_array($document['pid'], [1, 2])) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
})
|
|
);
|
|
|
|
$objectManager->get(TcaIndexer::class, $tableService, $connection)->indexAllDocuments();
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function sysLanguageIsKept()
|
|
{
|
|
$this->importDataSet('Tests/Functional/Fixtures/Indexing/TcaIndexer/KeepSysLanguageUid.xml');
|
|
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class);
|
|
$tableName = 'tt_content';
|
|
$tableService = $objectManager->get(
|
|
TcaTableServiceInterface::class,
|
|
$tableName,
|
|
$objectManager->get(RelationResolver::class),
|
|
$objectManager->get(ConfigurationContainerInterface::class)
|
|
);
|
|
|
|
$connection = $this->getMockBuilder(Elasticsearch::class)
|
|
->setMethods(['addDocuments'])
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$connection->expects($this->once())
|
|
->method('addDocuments')
|
|
->with(
|
|
$this->stringContains('tt_content'),
|
|
$this->callback(function ($documents) {
|
|
return isset($documents[0]['sys_language_uid']) && $documents[0]['sys_language_uid'] === 2;
|
|
})
|
|
);
|
|
|
|
$objectManager->get(TcaIndexer::class, $tableService, $connection)->indexAllDocuments();
|
|
}
|
|
}
|