2016-12-15 11:32:41 +01:00
|
|
|
<?php
|
2017-07-06 23:48:47 +02:00
|
|
|
namespace Codappix\SearchCore\Tests\Indexing;
|
2016-12-15 11:32:41 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2017-07-06 23:48:47 +02:00
|
|
|
use Codappix\SearchCore\Configuration\ConfigurationContainerInterface;
|
|
|
|
use Codappix\SearchCore\Connection\Elasticsearch;
|
|
|
|
use Codappix\SearchCore\Domain\Index\TcaIndexer;
|
|
|
|
use Codappix\SearchCore\Domain\Index\TcaIndexer\RelationResolver;
|
2018-03-13 17:28:50 +01:00
|
|
|
use Codappix\SearchCore\Domain\Index\TcaIndexer\TcaTableServiceInterface;
|
2017-07-06 23:48:47 +02:00
|
|
|
use Codappix\SearchCore\Tests\Functional\AbstractFunctionalTestCase;
|
2016-12-15 11:32:41 +01:00
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
|
|
|
|
|
|
|
class TcaIndexerTest extends AbstractFunctionalTestCase
|
|
|
|
{
|
2017-07-13 14:54:37 +02:00
|
|
|
protected function getTypoScriptFilesForFrontendRootPage()
|
|
|
|
{
|
|
|
|
return array_merge(
|
|
|
|
parent::getTypoScriptFilesForFrontendRootPage(),
|
|
|
|
['EXT:search_core/Tests/Functional/Fixtures/Indexing/TcaIndexer/RespectRootLineBlacklist.ts']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-15 11:32:41 +01:00
|
|
|
/**
|
|
|
|
* @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(
|
2018-03-13 17:28:50 +01:00
|
|
|
TcaTableServiceInterface::class,
|
2016-12-15 11:32:41 +01:00
|
|
|
$tableName,
|
|
|
|
$objectManager->get(RelationResolver::class),
|
|
|
|
$objectManager->get(ConfigurationContainerInterface::class)
|
|
|
|
);
|
2017-06-13 15:36:56 +02:00
|
|
|
|
|
|
|
$connection = $this->getMockBuilder(Elasticsearch::class)
|
|
|
|
->setMethods(['addDocuments'])
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2016-12-15 11:32:41 +01:00
|
|
|
|
|
|
|
$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();
|
|
|
|
}
|
2018-03-15 13:59:47 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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) {
|
|
|
|
if ($this->isLegacyVersion()) {
|
|
|
|
return isset($documents[0]['sys_language_uid']) && $documents[0]['sys_language_uid'] === '2';
|
|
|
|
} else {
|
|
|
|
return isset($documents[0]['sys_language_uid']) && $documents[0]['sys_language_uid'] === 2;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
$objectManager->get(TcaIndexer::class, $tableService, $connection)->indexAllDocuments();
|
|
|
|
}
|
2016-12-15 11:32:41 +01:00
|
|
|
}
|