FEATURE: Allow to configure tables to be processed

* Add typoscript option which TYPO3 tables should be processed and which
  should not be processed.
* Respect new optiion in hook.
* Also add necessary tests.
* Remove old no longer needed tests for hook.
This commit is contained in:
Daniel Siepmann 2016-12-15 14:02:40 +01:00
parent a02cf9bb96
commit 541c6db53a
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
21 changed files with 496 additions and 351 deletions

View file

@ -41,7 +41,7 @@ services:
install: make install
script: make Tests
script: make functionalTests
after_script:
- make uploadCodeCoverage

View file

@ -59,7 +59,7 @@ class ConfigurationContainer implements ConfigurationContainerInterface
{
if (!isset($this->settings[$section]) || !isset($this->settings[$section][$key])) {
throw new InvalidArgumentException(
'The given configuration option does not exit.',
'The given configuration option does not exist.',
InvalidArgumentException::OPTION_DOES_NOT_EXIST
);
}

View file

@ -20,7 +20,9 @@ namespace Leonmrni\SearchCore\Domain\Service;
* 02110-1301, USA.
*/
use Leonmrni\SearchCore\Configuration\ConfigurationContainerInterface;
use TYPO3\CMS\Core\SingletonInterface as Singleton;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Handles all data related things like updates, deletes and inserts.
@ -30,10 +32,14 @@ use TYPO3\CMS\Core\SingletonInterface as Singleton;
*
* TODO: Probably a candidate for deletion. Currently this class makes use of
* extbase DI. We have to resolve this somehow.
*
* I think we keep it for easier testing and DI.
*/
class DataHandler implements Singleton
{
/**
* TODO: Only inject on first use?!
*
* @var \Leonmrni\SearchCore\Connection\ConnectionInterface
* @inject
*/
@ -45,6 +51,12 @@ class DataHandler implements Singleton
*/
protected $indexerFactory;
/**
* @var ConfigurationContainerInterface
* @inject
*/
protected $configuration;
/**
* @var \TYPO3\CMS\Core\Log\Logger
*/
@ -60,6 +72,24 @@ class DataHandler implements Singleton
$this->logger = $logManager->getLogger(__CLASS__);
}
/**
* @param ConfigurationContainerInterface $configuration
*/
public function __construct(ConfigurationContainerInterface $configuration)
{
$this->configuration = $configuration;
}
/**
* Get all tables that are allowed for indexing.
*
* @return array<String>
*/
public function getAllowedTablesForIndexing()
{
return GeneralUtility::trimExplode(',', $this->configuration->get('index', 'allowedTables'));
}
/**
* @param string $table
* @param array $record

View file

@ -48,9 +48,6 @@ class DataHandler implements Singleton
* Dependency injection as TYPO3 doesn't provide it on it's own.
* Still you can submit your own dataHandler.
*
* TODO: Inject datahandler only on use?! Using getter / setter or something else?
* Otherwise a connection to elastic and whole bootstrapping will be triggered.
*
* @param OwnDataHandler $dataHandler
* @param Logger $logger
*/
@ -109,7 +106,7 @@ class DataHandler implements Singleton
if ($status === 'new') {
$fieldArray['uid'] = $dataHandler->substNEWwithIDs[$uid];
$this->dataHandler->add($table, $fieldArray);
return false;
return true;
}
if ($status === 'update') {
@ -117,28 +114,14 @@ class DataHandler implements Singleton
if ($record !== null) {
$this->dataHandler->update($table, $record);
}
return false;
return true;
}
$this->logger->debug(
'Database update not processed, cause status is unhandled.',
[$status, $table, $uid, $fieldArray]
);
return true;
}
/**
* Returns array containing tables that should be processed by this hook.
*
* TODO: Fetch from config
*
* @return string[]
*/
protected function getTablesToProcess()
{
return [
'tt_content',
];
return false;
}
/**
@ -147,7 +130,7 @@ class DataHandler implements Singleton
*/
protected function shouldProcessTable($table)
{
return in_array($table, $this->getTablesToProcess());
return in_array($table, $this->dataHandler->getAllowedTablesForIndexing());
}
/**

View file

@ -7,6 +7,12 @@ plugin {
}
index {
# Pages are not supported yet, see
# https://github.com/DanielSiepmann/search_core/issues/24 but
# should also be added, together with additionalWhereClause
# based on doktypes
allowedTables = tt_content
tt_content {
additionalWhereClause = tt_content.CType NOT IN ('gridelements_pi1', 'list', 'div', 'menu')
}

View file

@ -14,11 +14,6 @@ install: clean
COMPOSER_PROCESS_TIMEOUT=1000 composer require -vv --dev --prefer-source typo3/cms="$(TYPO3_VERSION)"
git checkout composer.json
unitTests:
TYPO3_PATH_WEB=$(TYPO3_WEB_DIR) \
.Build/bin/phpunit --colors --debug -v \
-c Tests/Unit/UnitTests.xml
functionalTests:
typo3DatabaseName=$(typo3DatabaseName) \
typo3DatabaseUsername=$(typo3DatabaseUsername) \
@ -28,9 +23,6 @@ functionalTests:
.Build/bin/phpunit --colors --debug -v \
-c Tests/Functional/FunctionalTests.xml
.PHONY: Tests
Tests: unitTests functionalTests
uploadCodeCoverage: uploadCodeCoverageToScrutinizer uploadCodeCoverageToCodacy
uploadCodeCoverageToScrutinizer:

View file

@ -29,18 +29,6 @@ abstract class AbstractFunctionalTestCase extends CoreTestCase
{
protected $testExtensionsToLoad = ['typo3conf/ext/search_core'];
/**
* Define whether to setup default typoscript on page 1.
*
* Set to false if you need to add further ts and use getDefaultPageTs to get the default one.
*
* This is necessary as setUpFrontendRootPage will allways add a new record
* and only the first one is used.
*
* @var bool
*/
protected $loadDefaultTs = true;
public function setUp()
{
parent::setUp();
@ -51,12 +39,17 @@ abstract class AbstractFunctionalTestCase extends CoreTestCase
// Provide necessary configuration for extension
$this->importDataSet('Tests/Functional/Fixtures/BasicSetup.xml');
if ($this->loadDefaultTs) {
$this->setUpFrontendRootPage(1, $this->getDefaultPageTs());
}
$this->setUpFrontendRootPage(1, $this->getTypoScriptFilesForFrontendRootPage());
}
protected function getDefaultPageTs()
/**
* Overwrite to import different files.
*
* Defines which TypoScript Files should be imported.
*
* @return array<String>
*/
protected function getTypoScriptFilesForFrontendRootPage()
{
return ['EXT:search_core/Tests/Functional/Fixtures/BasicSetup.ts'];
}

View file

@ -5,6 +5,10 @@ plugin {
host = localhost
port = 9200
}
index {
allowedTables = tt_content
}
}
}
}

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<dataset>
<tt_content>
<uid>6</uid>
<uid>1</uid>
<pid>1</pid>
<tstamp>1480686370</tstamp>
<crdate>1480686370</crdate>
@ -9,7 +9,7 @@
<sorting>72</sorting>
<CType>textmedia</CType>
<header>test</header>
<bodytext>this is the content of textmedia content element that should get indexed</bodytext>
<bodytext>Record that can be processed by hook</bodytext>
<media>0</media>
<layout>0</layout>
<deleted>0</deleted>

View file

@ -0,0 +1,11 @@
plugin {
tx_searchcore {
settings {
index {
allowedTables = tt_content, fe_user
}
}
}
}
module.tx_searchcore < plugin.tx_searchcore

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<dataset>
<sys_category>
<uid>1</uid>
<pid>1</pid>
<tstamp>1480686370</tstamp>
<crdate>1480686370</crdate>
<deleted>0</deleted>
<starttime>0</starttime>
<endtime>0</endtime>
<sorting>1</sorting>
<title>Some Category that should not be indexed as sys_category is not allowed</title>
<description></description>
<parent>0</parent>
<items>0</items>
</sys_category>
</dataset>

View file

@ -0,0 +1,78 @@
<?php
namespace Leonmrni\SearchCore\Tests\Functional\Hooks\DataHandler;
/*
* 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\Domain\Service\DataHandler as DataHandlerService;
use Leonmrni\SearchCore\Hook\DataHandler as DataHandlerHook;
use Leonmrni\SearchCore\Tests\Functional\AbstractFunctionalTestCase;
use TYPO3\CMS\Core\DataHandling\DataHandler as Typo3DataHandler;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
class IgnoresUnkownOperationTest extends AbstractFunctionalTestCase
{
/**
* @var DataHandlerService|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface
*/
protected $subject;
public function setUp()
{
parent::setUp();
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->subject = $this->getAccessibleMock(
DataHandlerService::class,
[
'add',
'update',
'delete',
],
[$objectManager->get(ConfigurationContainerInterface::class)]
);
// This way TYPO3 will use our mock instead of a new instance.
$GLOBALS['T3_VAR']['getUserObj']['&' . DataHandlerHook::class] = new DataHandlerHook($this->subject);
}
/**
* @test
*/
public function deletionWillBeTriggeredForTtContent()
{
$this->subject->expects($this->exactly(0))->method('add');
$this->subject->expects($this->exactly(0))->method('update');
$this->subject->expects($this->exactly(0))->method('delete');
$tce = GeneralUtility::makeInstance(Typo3DataHandler::class);
$tce->stripslashes_values = 0;
$tce->start([], [
'tt_content' => [
'1' => [
'something' => 1,
],
],
]);
$tce->process_cmdmap();
}
}

View file

@ -0,0 +1,117 @@
<?php
namespace Leonmrni\SearchCore\Tests\Functional\Hooks\DataHandler;
/*
* 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\Domain\Service\DataHandler as DataHandlerService;
use Leonmrni\SearchCore\Hook\DataHandler as DataHandlerHook;
use Leonmrni\SearchCore\Tests\Functional\AbstractFunctionalTestCase;
use TYPO3\CMS\Core\DataHandling\DataHandler as Typo3DataHandler;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
class NonAllowedTablesTest extends AbstractFunctionalTestCase
{
/**
* @var DataHandlerService|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface
*/
protected $subject;
public function setUp()
{
parent::setUp();
$this->importDataSet('Tests/Functional/Fixtures/Hooks/DataHandler/NonAllowedTables.xml');
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->subject = $this->getAccessibleMock(
DataHandlerService::class,
[
'add',
'update',
'delete',
],
[$objectManager->get(ConfigurationContainerInterface::class)]
);
// This way TYPO3 will use our mock instead of a new instance.
$GLOBALS['T3_VAR']['getUserObj']['&' . DataHandlerHook::class] = new DataHandlerHook($this->subject);
}
/**
* @test
*/
public function deletionWillNotBeTriggeredForSysCategories()
{
$this->subject->expects($this->exactly(0))->method('delete');
$tce = GeneralUtility::makeInstance(Typo3DataHandler::class);
$tce->stripslashes_values = 0;
$tce->start([], [
'sys_category' => [
'1' => [
'delete' => 1,
],
],
]);
$tce->process_cmdmap();
}
/**
* @test
*/
public function updateWillNotBeTriggeredForSysCategory()
{
$this->subject->expects($this->exactly(0))->method('update');
$tce = GeneralUtility::makeInstance(Typo3DataHandler::class);
$tce->stripslashes_values = 0;
$tce->start([
'sys_category' => [
'1' => [
'title' => 'something new',
],
],
], []);
$tce->process_datamap();
}
/**
* @test
*/
public function addWillNotBeTriggeredForSysCategoy()
{
$this->subject->expects($this->exactly(0))->method('add');
$tce = GeneralUtility::makeInstance(Typo3DataHandler::class);
$tce->stripslashes_values = 0;
$tce->start([
'sys_category' => [
'NEW_1' => [
'pid' => 1,
'title' => 'a new record',
],
],
], []);
$tce->process_datamap();
}
}

View file

@ -0,0 +1,32 @@
<?php
namespace Leonmrni\SearchCore\Tests\Functional\Hooks\DataHandler;
/*
* 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.
*/
class NonAllowedTablesWithMultipleTablesConfiguredTest extends NonAllowedTablesTest
{
protected function getTypoScriptFilesForFrontendRootPage()
{
return array_merge(
parent::getTypoScriptFilesForFrontendRootPage(),
['EXT:search_core/ Tests/Functional/Fixtures/Hooks/DataHandler/MultipleAllowedTables.ts']
);
}
}

View file

@ -0,0 +1,136 @@
<?php
namespace Leonmrni\SearchCore\Tests\Functional\Hooks\DataHandler;
/*
* 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\Domain\Service\DataHandler as DataHandlerService;
use Leonmrni\SearchCore\Hook\DataHandler as DataHandlerHook;
use Leonmrni\SearchCore\Tests\Functional\AbstractFunctionalTestCase;
use TYPO3\CMS\Core\DataHandling\DataHandler as Typo3DataHandler;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
class ProcessesAllowedTablesTest extends AbstractFunctionalTestCase
{
/**
* @var DataHandlerService|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface
*/
protected $subject;
public function setUp()
{
parent::setUp();
$this->importDataSet('Tests/Functional/Fixtures/Hooks/DataHandler/AllowedTables.xml');
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->subject = $this->getAccessibleMock(
DataHandlerService::class,
[
'add',
'update',
'delete',
],
[$objectManager->get(ConfigurationContainerInterface::class)]
);
// This way TYPO3 will use our mock instead of a new instance.
$GLOBALS['T3_VAR']['getUserObj']['&' . DataHandlerHook::class] = new DataHandlerHook($this->subject);
}
/**
* @test
*/
public function deletionWillBeTriggeredForTtContent()
{
$this->subject->expects($this->exactly(1))->method('delete')
->with($this->equalTo('tt_content'), $this->equalTo('1'));
$tce = GeneralUtility::makeInstance(Typo3DataHandler::class);
$tce->stripslashes_values = 0;
$tce->start([], [
'tt_content' => [
'1' => [
'delete' => 1,
],
],
]);
$tce->process_cmdmap();
}
/**
* @test
*/
public function updateWillBeTriggeredForTtContent()
{
$this->subject->expects($this->exactly(1))->method('update')
->with(
$this->equalTo('tt_content'),
$this->callback(function ($record) {
return isset($record['uid']) && $record['uid'] === '1'
&& isset($record['pid']) && $record['pid'] === '1'
&& isset($record['colPos']) && $record['colPos'] === '1'
;
})
);
$tce = GeneralUtility::makeInstance(Typo3DataHandler::class);
$tce->stripslashes_values = 0;
$tce->start([
'tt_content' => [
'1' => [
'colPos' => 1,
],
],
], []);
$tce->process_datamap();
}
/**
* @test
*/
public function addWillBeTriggeredForTtContent()
{
$this->subject->expects($this->exactly(1))->method('add')
->with(
$this->equalTo('tt_content'),
$this->callback(function ($record) {
return isset($record['uid']) && $record['uid'] === 2
&& isset($record['pid']) && $record['pid'] === 1
&& isset($record['header']) && $record['header'] === 'a new record'
;
})
);
$tce = GeneralUtility::makeInstance(Typo3DataHandler::class);
$tce->stripslashes_values = 0;
$tce->start([
'tt_content' => [
'NEW_1' => [
'pid' => 1,
'header' => 'a new record',
],
],
], []);
$tce->process_datamap();
}
}

View file

@ -0,0 +1,37 @@
<?php
namespace Leonmrni\SearchCore\Tests\Functional\Hooks\DataHandler;
/*
* 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.
*/
class ProcessesAllowedTablesWithMultipleTablesConfiguredTest extends ProcessesAllowedTablesTest
{
/**
* @var DataHandlerService|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface
*/
protected $subject;
protected function getTypoScriptFilesForFrontendRootPage()
{
return array_merge(
parent::getTypoScriptFilesForFrontendRootPage(),
['EXT:search_core/ Tests/Functional/Fixtures/Hooks/DataHandler/MultipleAllowedTables.ts']
);
}
}

View file

@ -1,115 +0,0 @@
<?php
namespace Leonmrni\SearchCore\Tests\Functional\Hooks;
/*
* 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\Hook\DataHandler as Hook;
use Leonmrni\SearchCore\Tests\Functional\Connection\Elasticsearch\AbstractFunctionalTestCase;
use TYPO3\CMS\Core\DataHandling\DataHandler as CoreDataHandler;
use TYPO3\CMS\Extbase\Object\ObjectManager;
/**
* TODO: Rewrite as this test doesn't test what it should do.
* We have to split it up in two tests:
* 1. Test whether TYPO3 DataHandler will our hook as expected.
* 2. Test whether our hook will send the documents to connection as expected.
*/
class DataHandlerTest extends AbstractFunctionalTestCase
{
public function setUp()
{
parent::setUp();
$this->importDataSet('Tests/Functional/Fixtures/Hooks/DataHandler.xml');
}
/**
* @test
*/
public function nonAllowedTablesWillNotBeProcessed()
{
$dataHandler = new CoreDataHandler();
$hook = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(Hook::class);
$this->assertFalse($hook->processDatamap_afterDatabaseOperations('new', 'some_strange_table', 'NEW34', [], $dataHandler));
$this->assertFalse($hook->processDatamap_afterDatabaseOperations('update', 'some_strange_table', 6, [], $dataHandler));
$this->assertFalse($hook->processCmdmap_deleteAction('some_strange_table', 6, [], false, $dataHandler));
}
/**
* @test
*/
public function addNewElement()
{
$dataHandler = new CoreDataHandler();
$dataHandler->substNEWwithIDs = ['NEW34' => 6];
$hook = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(Hook::class);
$hook->processDatamap_afterDatabaseOperations('new', 'tt_content', 'NEW34', [], $dataHandler);
$response = $this->client->request('typo3content/_search?q=*:*');
$this->assertTrue($response->isOK());
$this->assertSame($response->getData()['hits']['total'], 1, 'Not exactly 1 document was indexed.');
}
/**
* @test
* TODO: Make sure the indexed document was updated, e.g. by changing some content.
*/
public function updateExistingElement()
{
$dataHandler = new CoreDataHandler();
$hook = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(Hook::class);
$hook->processDatamap_afterDatabaseOperations('update', 'tt_content', 6, [], $dataHandler);
$response = $this->client->request('typo3content/_search?q=*:*');
$this->assertTrue($response->isOK(), 'Elastica did not answer with ok code.');
$this->assertSame($response->getData()['hits']['total'], 1, 'Not exactly 1 document was indexed.');
}
/**
* @test
*/
public function deleteExistingElement()
{
$this->addNewElement();
$dataHandler = new CoreDataHandler();
$hook = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(Hook::class);
$hook->processCmdmap_deleteAction('tt_content', 6, [], false, $dataHandler);
$response = $this->client->request('typo3content/_search?q=*:*');
$this->assertTrue($response->isOK(), 'Elastica did not answer with ok code.');
$this->assertSame($response->getData()['hits']['total'], 0, 'Not exactly 0 document was indexed.');
}
/**
* @test
* @expectedException \Elastica\Exception\ResponseException
*/
public function someUnknownOperationDoesNotBreakSomething()
{
$dataHandler = new CoreDataHandler();
$hook = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(Hook::class);
//TODO: this test is senseless, checking an exception not correct, this operation should not do anything!
$hook->processDatamap_afterDatabaseOperations('something', 'tt_content', 6, [], $dataHandler);
// Should trigger Exception
$this->client->request('typo3content/_search?q=*:*');
}
}

View file

@ -30,22 +30,12 @@ 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(
@ -83,4 +73,12 @@ class TcaIndexerTest extends AbstractFunctionalTestCase
$objectManager->get(TcaIndexer::class, $tableService, $connection)->indexAllDocuments();
}
protected function getTypoScriptFilesForFrontendRootPage()
{
return array_merge(
parent::getTypoScriptFilesForFrontendRootPage(),
['EXT:search_core/Tests/Functional/Fixtures/Indexing/TcaIndexer/RespectRootLineBlacklist.ts']
);
}
}

View file

@ -1,142 +0,0 @@
<?php
namespace Leonmrni\SearchCore\Tests\Unit\Hook;
/*
* Copyright (C) 2016 Daniel Siepmann <daniel.siepmann@typo3.org>
*
* 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 TYPO3\CMS\Core\DataHandling\DataHandler as CoreDataHandler;
use TYPO3\CMS\Core\Tests\UnitTestCase;
use Leonmrni\SearchCore\Domain\Service\DataHandler;
use Leonmrni\SearchCore\Hook\DataHandler as Hook;
/**
*
*/
class DataHandlerTest extends UnitTestCase
{
/**
* @var DataHandler|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface
*/
protected $subject;
/**
* @var Hook|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface
*/
protected $hook;
/**
* Set up the tests
*/
protected function setUp()
{
$this->subject = $this->getAccessibleMock(DataHandler::class);
$this->hook = $this->getAccessibleMock(
Hook::class,
[
'getTablesToProcess',
'getRecord'
],
[$this->subject]
);
$this->hook->method('getTablesToProcess')
->willReturn(['table']);
$this->hook->method('getRecord')
->willReturn([
'title' => 'some title',
'bodytext' => 'some text',
]);
}
/**
* @test
*/
public function notConfiguredTablesWillNotBeProcessed()
{
$table = 'noneConfiguredTable';
$recordUid = 1;
$this->subject->expects($this->exactly(0))->method('delete');
$this->subject->expects($this->exactly(0))->method('add');
$this->subject->expects($this->exactly(0))->method('update');
$dataHandler = new CoreDataHandler();
$dataHandler->substNEWwithIDs = ['NEW34' => $recordUid];
$this->hook->processCmdmap_deleteAction($table, $recordUid, [], false, $dataHandler);
$this->hook->processDatamap_afterDatabaseOperations('new', $table, 'NEW34', [], $dataHandler);
$this->hook->processDatamap_afterDatabaseOperations('update', $table, $recordUid, [], $dataHandler);
}
/**
* @test
*/
public function configuredTablesWillBeProcessed()
{
$table = 'table';
$recordUid = 1;
$this->subject->expects($this->once())->method('delete');
$this->subject->expects($this->once())->method('add');
$this->subject->expects($this->once())->method('update');
$dataHandler = new CoreDataHandler();
$dataHandler->substNEWwithIDs = ['NEW34' => $recordUid];
$this->hook->processCmdmap_deleteAction($table, $recordUid, [], false, $dataHandler);
$this->hook->processDatamap_afterDatabaseOperations('new', $table, 'NEW34', [], $dataHandler);
$this->hook->processDatamap_afterDatabaseOperations('update', $table, $recordUid, [], $dataHandler);
}
/**
* @test
*/
public function deletionWillBeTriggered()
{
$table = 'table';
$recordUid = 1;
$this->subject->expects($this->once())
->method('delete')
->with(
$this->equalTo($table),
$this->equalTo($recordUid)
);
$this->hook->processCmdmap_deleteAction($table, $recordUid, [], false, new CoreDataHandler());
}
/**
* @test
*/
public function updateWillBeTriggered()
{
$table = 'table';
$recordUid = 1;
$record = [
'title' => 'some title',
'bodytext' => 'some text',
];
$this->subject->expects($this->once())
->method('update')
->with(
$this->equalTo($table),
$this->equalTo($record)
);
$this->hook->processDatamap_afterDatabaseOperations('update', $table, $recordUid, $record, new CoreDataHandler);
}
}

View file

@ -1,33 +0,0 @@
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="../../.Build/vendor/typo3/cms/typo3/sysext/core/Build/UnitTestsBootstrap.php"
colors="true"
convertErrorsToExceptions="false"
convertWarningsToExceptions="false"
forceCoversAnnotation="false"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
verbose="false">
<testsuites>
<testsuite name="unit-tests">
<directory>.</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">../../Classes</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="../../.Build/report/unit/html" lowUpperBound="35" highLowerBound="70"/>
<log type="coverage-clover" target="../../.Build/report/unit/clover/coverage"/>
</logging>
</phpunit>

View file

@ -16,10 +16,10 @@ call_user_func(
],
't3lib/class.t3lib_tcemain.php' => [
'processCmdmapClass' => [
$extensionKey => \Leonmrni\SearchCore\Hook\DataHandler::class,
$extensionKey => '&' . \Leonmrni\SearchCore\Hook\DataHandler::class,
],
'processDatamapClass' => [
$extensionKey => \Leonmrni\SearchCore\Hook\DataHandler::class,
$extensionKey => '&' . \Leonmrni\SearchCore\Hook\DataHandler::class,
],
],
],