mirror of
https://github.com/Codappix/search_core.git
synced 2024-12-23 14:16:10 +01:00
Daniel Siepmann
499b9d0500
* Allow configuration through TypoScript to exclude records for indexing based on their root line position. Page uids can be configured for exclusion and all records beneath will be excluded while indexing.
86 lines
3.1 KiB
PHP
86 lines
3.1 KiB
PHP
<?php
|
|
namespace Leonmrni\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 Leonmrni\SearchCore\Configuration\ConfigurationContainerInterface;
|
|
use Leonmrni\SearchCore\Connection\Elasticsearch;
|
|
use Leonmrni\SearchCore\Domain\Index\TcaIndexer;
|
|
use Leonmrni\SearchCore\Domain\Index\TcaIndexer\RelationResolver;
|
|
use Leonmrni\SearchCore\Domain\Index\TcaIndexer\TcaTableService;
|
|
use Leonmrni\SearchCore\Tests\Functional\AbstractFunctionalTestCase;
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
|
|
|
class TcaIndexerTest extends AbstractFunctionalTestCase
|
|
{
|
|
protected $loadDefaultTs = false;
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function respectRootLineBlacklist()
|
|
{
|
|
$this->importDataSet('Tests/Functional/Fixtures/Indexing/TcaIndexer/RespectRootLineBlacklist.xml');
|
|
$this->setUpFrontendRootPage(
|
|
1,
|
|
array_merge(
|
|
$this->getDefaultPageTs(),
|
|
['EXT:search_core/Tests/Functional/Fixtures/Indexing/TcaIndexer/RespectRootLineBlacklist.ts']
|
|
)
|
|
);
|
|
|
|
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class);
|
|
$tableName = 'tt_content';
|
|
$tableService = $objectManager->get(
|
|
TcaTableService::class,
|
|
$tableName,
|
|
$objectManager->get(RelationResolver::class),
|
|
$objectManager->get(ConfigurationContainerInterface::class)
|
|
);
|
|
$connection = $this->getAccessibleMock(
|
|
Elasticsearch::class,
|
|
[
|
|
'addDocuments',
|
|
],
|
|
[],
|
|
'',
|
|
false
|
|
);
|
|
|
|
$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();
|
|
}
|
|
}
|