diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 7cbd254..56b321e 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -32,3 +32,7 @@ tools: php_analyzer: enabled: true + # We generate code coverage during tests at travis and will send them here + external_code_coverage: + runs: 2 + timeout: 1200 diff --git a/.travis.yml b/.travis.yml index 3a7ae7b..539e746 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,18 @@ language: php php: - 5.6 - 7.0 + - 7.1 env: + global: + - TYPO3_DATABASE_NAME="typo3_ci" + - TYPO3_DATABASE_HOST="127.0.0.1" + - TYPO3_DATABASE_USERNAME="travis" + - TYPO3_DATABASE_PASSWORD="" + - typo3DatabaseName="typo3_ci" + - typo3DatabaseHost="127.0.0.1" + - typo3DatabaseUsername="travis" + - typo3DatabasePassword="" matrix: - TYPO3_VERSION="~6.2" - TYPO3_VERSION="~7.6" @@ -12,25 +22,32 @@ env: matrix: fast_finish: true - allow_failures: - - env: TYPO3_VERSION="~6.2" - php: 7.0 - - env: TYPO3_VERSION="dev-master" - php: 7.0 exclude: # TYPO3 no longer supports 5.6 - env: TYPO3_VERSION="dev-master" php: 5.6 + # There is some error with 6.2 and 7 not finding the "UnitTestsBootstrap.php" + - env: TYPO3_VERSION="~6.2" + php: 7.0 + - env: TYPO3_VERSION="~6.2" + php: 7.1 + allow_failures: + - env: TYPO3_VERSION="dev-master" + php: 7.0 + - env: TYPO3_VERSION="dev-master" + php: 7.1 -before_install: - - composer self-update - - composer --version +services: + - mysql + - elasticsearch -install: - - make install +install: make install -script: - - make Tests +script: make Tests + +after_script: + - make uploadCodeCoverage + - make clean cache: directories: diff --git a/Classes/Connection/Elasticsearch.php b/Classes/Connection/Elasticsearch.php index 3c518e7..49d169b 100644 --- a/Classes/Connection/Elasticsearch.php +++ b/Classes/Connection/Elasticsearch.php @@ -82,17 +82,32 @@ class Elasticsearch implements Singleton, ConnectionInterface public function add($documentType, array $document) { - throw new \Exception('Implement', 1481190734); + $this->withType( + $documentType, + function ($type) use ($document) { + $type->addDocument($this->documentFactory->getDocument($type->getName(), $document)); + } + ); } public function delete($documentType, $identifier) { - throw new \Exception('Implement', 1481190734); + $this->withType( + $documentType, + function ($type) use($identifier) { + $type->deleteById($identifier); + } + ); } public function update($documentType, array $document) { - throw new \Exception('Implement', 1481190734); + $this->withType( + $documentType, + function ($type) use ($document) { + $type->updateDocument($this->documentFactory->getDocument($type->getName(), $document)); + } + ); } /** @@ -103,24 +118,30 @@ class Elasticsearch implements Singleton, ConnectionInterface */ public function addDocuments($documentType, array $documents) { - $type = $this->typeFactory->getType( - $this->indexFactory->getIndex( - $this->connection, - $documentType - ), - $documentType - ); - - $type->addDocuments( - $this->documentFactory->getDocuments($documentType, $documents) + $this->withType( + $documentType, + function ($type) use ($documents) { + $type->addDocuments($this->documentFactory->getDocuments($type->getName(), $documents)); + } ); + } + /** + * Execute given callback with Elastica Type based on provided documentType + * + * @param string $documentType + * @param callable $callback + */ + protected function withType($documentType, callable $callback) + { + $type = $this->getType($documentType); + $callback($type); $type->getIndex()->refresh(); } /** * @param SearchRequestInterface $searchRequest - * @return SearchResultInterface + * @return \Elastica\ResultSet */ public function search(SearchRequestInterface $searchRequest) { @@ -130,6 +151,23 @@ class Elasticsearch implements Singleton, ConnectionInterface $search->addIndex('typo3content'); // TODO: Return wrapped result to implement our interface. + // Also update php doc to reflect the change. return $search->search($searchRequest->getSearchTerm()); } + + /** + * @param string $documentType + * + * @return \Elastica\Type + */ + protected function getType($documentType) + { + return $this->typeFactory->getType( + $this->indexFactory->getIndex( + $this->connection, + $documentType + ), + $documentType + ); + } } diff --git a/Classes/Domain/Index/IndexerInterface.php b/Classes/Domain/Index/IndexerInterface.php index af5ceca..88972dd 100644 --- a/Classes/Domain/Index/IndexerInterface.php +++ b/Classes/Domain/Index/IndexerInterface.php @@ -31,4 +31,11 @@ interface IndexerInterface * @return void */ public function index(); + + /** + * Index a single record. + * + * @return void + */ + public function indexRecord($identifier); } diff --git a/Classes/Domain/Index/TcaIndexer.php b/Classes/Domain/Index/TcaIndexer.php index 7e6671a..0205836 100644 --- a/Classes/Domain/Index/TcaIndexer.php +++ b/Classes/Domain/Index/TcaIndexer.php @@ -75,6 +75,13 @@ class TcaIndexer implements IndexerInterface $this->logger->info('Finish indexing'); } + public function indexRecord($identifier) + { + $this->logger->info('Start indexing single record.', [$identifier]); + $this->connection->add($this->tcaTableService->getTableName(), $this->getRecord($identifier)); + $this->logger->info('Finish indexing'); + } + /** * @return \Generator */ @@ -114,4 +121,20 @@ class TcaIndexer implements IndexerInterface return $records; } + + /** + * @param int $identifier + * @return array + */ + protected function getRecord($identifier) + { + $record = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow( + $this->tcaTableService->getFields(), + $this->tcaTableService->getTableName(), + $this->tcaTableService->getWhereClause() . ' AND uid = ' . (int) $identifier + ); + $this->tcaTableService->prepareRecord($record); + + return $record; + } } diff --git a/Classes/Domain/Service/DataHandler.php b/Classes/Domain/Service/DataHandler.php index 66913e1..6446979 100644 --- a/Classes/Domain/Service/DataHandler.php +++ b/Classes/Domain/Service/DataHandler.php @@ -36,6 +36,12 @@ class DataHandler implements Singleton */ protected $connection; + /** + * @var \Leonmrni\SearchCore\Domain\Index\IndexerFactory + * @inject + */ + protected $indexerFactory; + /** * @var \TYPO3\CMS\Core\Log\Logger */ @@ -51,16 +57,6 @@ class DataHandler implements Singleton $this->logger = $logManager->getLogger(__CLASS__); } - /** - * @param string $table - * @param int $identifier - */ - public function delete($table, $identifier) - { - $this->logger->debug('Record received for delete.', [$table, $identifier]); - $this->connection->delete($table, $identifier); - } - /** * @param string $table * @param array $record @@ -68,7 +64,7 @@ class DataHandler implements Singleton public function add($table, array $record) { $this->logger->debug('Record received for add.', [$table, $record]); - $this->connection->add($table, $record); + $this->indexerFactory->getIndexer($table)->indexRecord($record['uid']); } /** @@ -77,6 +73,16 @@ class DataHandler implements Singleton public function update($table, array $record) { $this->logger->debug('Record received for update.', [$table, $record]); - $this->connection->update($table, $record); + $this->indexerFactory->getIndexer($table)->indexRecord($record['uid']); + } + + /** + * @param string $table + * @param int $identifier + */ + public function delete($table, $identifier) + { + $this->logger->debug('Record received for delete.', [$table, $identifier]); + $this->connection->delete($table, $identifier); } } diff --git a/Classes/Hook/DataHandler.php b/Classes/Hook/DataHandler.php index a413aa2..a49b454 100644 --- a/Classes/Hook/DataHandler.php +++ b/Classes/Hook/DataHandler.php @@ -74,15 +74,18 @@ class DataHandler implements Singleton * * @param string $table * @param int $uid + * + * @return bool False if hook was not processed. */ public function processCmdmap_deleteAction($table, $uid) { if (! $this->shouldProcessTable($table)) { $this->logger->debug('Delete not processed, cause table is not allowed.', [$table]); - return; + return false; } $this->dataHandler->delete($table, $uid); + return true; } /** @@ -93,18 +96,20 @@ class DataHandler implements Singleton * @param string|int $uid * @param array $fieldArray * @param CoreDataHandler $dataHandler + * + * @return bool False if hook was not processed. */ public function processDatamap_afterDatabaseOperations($status, $table, $uid, array $fieldArray, CoreDataHandler $dataHandler) { if (! $this->shouldProcessTable($table)) { $this->logger->debug('Database update not processed, cause table is not allowed.', [$table]); - return; + return false; } if ($status === 'new') { $fieldArray['uid'] = $dataHandler->substNEWwithIDs[$uid]; $this->dataHandler->add($table, $fieldArray); - return; + return false; } if ($status === 'update') { @@ -112,13 +117,14 @@ class DataHandler implements Singleton if ($record !== null) { $this->dataHandler->update($table, $record); } - return; + return false; } $this->logger->debug( 'Database update not processed, cause status is unhandled.', [$status, $table, $uid, $fieldArray] ); + return true; } /** @@ -149,7 +155,7 @@ class DataHandler implements Singleton * * @param string $table * @param int $uid - * @return null|array + * @return null|array */ protected function getRecord($table, $uid) { diff --git a/Classes/Service/DataHandler.php b/Classes/Service/DataHandler.php deleted file mode 100644 index 0febc5a..0000000 --- a/Classes/Service/DataHandler.php +++ /dev/null @@ -1,80 +0,0 @@ - - * - * 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\SingletonInterface as Singleton; - -/** - * Handles all data related things like updates, deletes and inserts. - * - * This is the place to add mappings of further parts to adjust the data before - * sending ot to connection. - */ -class DataHandler implements Singleton -{ - /** - * @var \TYPO3\CMS\Core\Log\Logger - */ - protected $logger; - - // TODO: Write construct with inject of connection - - /** - * Inject log manager to get concrete logger from it. - * - * @param \TYPO3\CMS\Core\Log\LogManager $logManager - */ - public function injectLogger(\TYPO3\CMS\Core\Log\LogManager $logManager) - { - $this->logger = $logManager->getLogger(__CLASS__); - } - - /** - * @param string $table - * @param int $identifier - */ - public function delete($table, $identifier) - { - $this->logger->debug('Record received for delete.', [$table, $identifier]); - // $this->connection->delete($table, $identifier); - } - - /** - * @param string $table - * @param int $identifier - * @param array $record - */ - public function add($table, $identifier, array $record) - { - $this->logger->debug('Record received for add.', [$table, $identifier, $record]); - // $this->connection->add($table, $identifier, $record); - } - - /** - * @param string $table - * @param int $identifier - */ - public function update($table, $identifier, array $record) - { - $this->logger->debug('Record received for update.', [$table, $identifier, $record]); - // $this->connection->update($table, $identifier, $record); - } -} diff --git a/Makefile b/Makefile index ef9b947..be9f02c 100644 --- a/Makefile +++ b/Makefile @@ -3,18 +3,46 @@ current_dir := $(dir $(mkfile_path)) TYPO3_WEB_DIR := $(current_dir).Build/Web # Allow different versions on travis -TYPO3_VERSION ?= ~6.2 +TYPO3_VERSION ?= ~6.2.19 +typo3DatabaseName ?= "test" +typo3DatabaseUsername ?= "dev" +typo3DatabasePassword ?= "dev" +typo3DatabaseHost ?= "127.0.0.1" .PHONY: install -install: - rm -rf .Build - - composer require --dev --prefer-source typo3/cms="$(TYPO3_VERSION)" - composer update -vv - +install: clean + COMPOSER_PROCESS_TIMEOUT=1000 composer require -vv --dev --prefer-source typo3/cms="$(TYPO3_VERSION)" git checkout composer.json - mkdir -p $(TYPO3_WEB_DIR)/uploads $(TYPO3_WEB_DIR)/typo3temp + +unitTests: + TYPO3_PATH_WEB=$(TYPO3_WEB_DIR) \ + .Build/bin/phpunit --colors --debug -v \ + -c Tests/Unit/UnitTests.xml + +functionalTests: + typo3DatabaseName=$(typo3DatabaseName) \ + typo3DatabaseUsername=$(typo3DatabaseUsername) \ + typo3DatabasePassword=$(typo3DatabasePassword) \ + typo3DatabaseHost=$(typo3DatabaseHost) \ + TYPO3_PATH_WEB=$(TYPO3_WEB_DIR) \ + .Build/bin/phpunit --colors --debug -v \ + -c Tests/Functional/FunctionalTests.xml .PHONY: Tests -Tests: - TYPO3_PATH_WEB=$(TYPO3_WEB_DIR) .Build/bin/phpunit --colors --debug -v -c Tests/Unit/UnitTests.xml +Tests: unitTests functionalTests + +uploadCodeCoverage: uploadCodeCoverageToScrutinizer uploadCodeCoverageToCodacy + +uploadCodeCoverageToScrutinizer: + wget https://scrutinizer-ci.com/ocular.phar && \ + php ocular.phar code-coverage:upload --format=php-clover .Build/report/unit/clover/coverage && \ + php ocular.phar code-coverage:upload --format=php-clover .Build/report/functional/clover/coverage + +uploadCodeCoverageToCodacy: + composer require -vv --dev codacy/coverage && \ + git checkout composer.json && \ + php .Build/bin/codacycoverage clover .Build/report/unit/clover/coverage && \ + php .Build/bin/codacycoverage clover .Build/report/functional/clover/coverage + +clean: + rm -rf .Build composer.lock diff --git a/Tests/Functional/AbstractFunctionalTestCase.php b/Tests/Functional/AbstractFunctionalTestCase.php new file mode 100644 index 0000000..fd90e8e --- /dev/null +++ b/Tests/Functional/AbstractFunctionalTestCase.php @@ -0,0 +1,60 @@ + + * + * 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\Tests\FunctionalTestCase as CoreTestCase; + +/** + * All functional tests should extend this base class. + * + * It will take care of leaving a clean environment for next test. + */ +abstract class AbstractFunctionalTestCase extends CoreTestCase +{ + protected $testExtensionsToLoad = ['typo3conf/ext/search_core']; + + /** + * @var \Elastica\Client + */ + protected $client; + + public function setUp() + { + parent::setUp(); + + // Provide necessary configuration for extension + $this->importDataSet('Tests/Functional/Fixtures/BasicSetup.xml'); + $this->setUpFrontendRootPage(1, ['EXT:search_core/Tests/Functional/Fixtures/BasicSetup.ts']); + + // Create client to make requests and assert something. + $this->client = new \Elastica\Client([ + 'host' => getenv('ES_HOST') ?: \Elastica\Connection::DEFAULT_HOST, + 'port' => getenv('ES_PORT') ?: \Elastica\Connection::DEFAULT_PORT, + ]); + } + + public function tearDown() + { + // Delete everything so next test starts clean. + $this->client->getIndex('_all')->delete(); + $this->client->getIndex('_all')->clearCache(); + } +} diff --git a/Tests/Functional/Fixtures/BasicSetup.ts b/Tests/Functional/Fixtures/BasicSetup.ts new file mode 100644 index 0000000..22c4ed8 --- /dev/null +++ b/Tests/Functional/Fixtures/BasicSetup.ts @@ -0,0 +1,12 @@ +plugin { + tx_searchcore { + settings { + connection { + host = localhost + port = 9200 + } + } + } +} + +module.tx_searchcore < plugin.tx_searchcore diff --git a/Tests/Functional/Fixtures/BasicSetup.xml b/Tests/Functional/Fixtures/BasicSetup.xml new file mode 100644 index 0000000..a85b72a --- /dev/null +++ b/Tests/Functional/Fixtures/BasicSetup.xml @@ -0,0 +1,8 @@ + + + + 1 + 0 + Root page containing necessary TypoScript + + diff --git a/Tests/Functional/Fixtures/Hooks/DataHandler.xml b/Tests/Functional/Fixtures/Hooks/DataHandler.xml new file mode 100644 index 0000000..db3f5ba --- /dev/null +++ b/Tests/Functional/Fixtures/Hooks/DataHandler.xml @@ -0,0 +1,22 @@ + + + + 6 + 1 + 1480686370 + 1480686370 + 0 + 72 + textmedia +
test
+ this is the content of textmedia content element that should get indexed + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 +
+
diff --git a/Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml b/Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml new file mode 100644 index 0000000..14ef723 --- /dev/null +++ b/Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml @@ -0,0 +1,63 @@ + + + + 6 + 1 + 1480686370 + 1480686370 + 0 + 72 + textmedia +
test
+ this is the content of textmedia content element that should get indexed + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 +
+ + + 7 + 1 + 1480686371 + 1480686370 + 0 + 72 + textmedia +
endtime hidden record
+ + 0 + 0 + 0 + 0 + 0 + 1481305963 + 0 + 0 +
+ + + 8 + 1 + 1480686370 + 1480686370 + 1 + 72 + textmedia +
Hidden record
+ + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 +
+ +
diff --git a/Tests/Functional/FunctionalTests.xml b/Tests/Functional/FunctionalTests.xml new file mode 100644 index 0000000..44a3f8f --- /dev/null +++ b/Tests/Functional/FunctionalTests.xml @@ -0,0 +1,34 @@ + + + + + . + + + + + + ../../Classes + + + + + + + + + diff --git a/Tests/Functional/Hooks/DataHandlerTest.php b/Tests/Functional/Hooks/DataHandlerTest.php new file mode 100644 index 0000000..a1a17b7 --- /dev/null +++ b/Tests/Functional/Hooks/DataHandlerTest.php @@ -0,0 +1,111 @@ + + * + * 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\AbstractFunctionalTestCase; +use TYPO3\CMS\Core\DataHandling\DataHandler as CoreDataHandler; +use TYPO3\CMS\Extbase\Object\ObjectManager; + +/** + * + */ +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()); + $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()); + $this->assertSame($response->getData()['hits']['total'], 0, 'Not exactly 0 document was indexed.'); + } + + /** + * @test + * @expectedException \Elastica\Exception\ResponseException + */ + public function someUnkownOperationDoesNotBreakSomething() + { + $dataHandler = new CoreDataHandler(); + $hook = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(Hook::class); + $hook->processDatamap_afterDatabaseOperations('something', 'tt_content', 6, [], $dataHandler); + + // Should trigger Exception + $this->client->request('typo3content/_search?q=*:*'); + } +} diff --git a/Tests/Functional/Indexing/IndexTcaTableTest.php b/Tests/Functional/Indexing/IndexTcaTableTest.php new file mode 100644 index 0000000..cbd195c --- /dev/null +++ b/Tests/Functional/Indexing/IndexTcaTableTest.php @@ -0,0 +1,88 @@ + + * + * 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\Domain\Index\IndexerFactory; +use Leonmrni\SearchCore\Tests\Functional\AbstractFunctionalTestCase; +use TYPO3\CMS\Extbase\Object\ObjectManager; + +/** + * + */ +class IndexTcaTableTest extends AbstractFunctionalTestCase +{ + public function setUp() + { + parent::setUp(); + + $this->importDataSet('Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml'); + } + + /** + * @test + */ + public function indexBasicTtContentWithoutBasicConfiguration() + { + \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class) + ->get(IndexerFactory::class) + ->getIndexer('tt_content') + ->index() + ; + + $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 + * @expectedException \Leonmrni\SearchCore\Domain\Index\IndexingException + */ + public function indexingNonConfiguredTableWillThrowException() + { + \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class) + ->get(IndexerFactory::class) + ->getIndexer('non_existing_table') + ; + } + + /** + * @test + */ + public function canHandleExisingIndex() + { + $indexer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class) + ->get(IndexerFactory::class) + ->getIndexer('tt_content') + ; + + $indexer->index(); + + // Index 2nd time, index already exists in elasticsearch. + $indexer->index(); + + $response = $this->client->request('typo3content/_search?q=*:*'); + + $this->assertTrue($response->isOK()); + $this->assertSame($response->getData()['hits']['total'], 1, 'Not exactly 1 document was indexed.'); + } +} diff --git a/Tests/Unit/UnitTests.xml b/Tests/Unit/UnitTests.xml index 93247f4..67719fc 100644 --- a/Tests/Unit/UnitTests.xml +++ b/Tests/Unit/UnitTests.xml @@ -19,4 +19,16 @@ . + + + + ../../Classes + + + + + + + + diff --git a/composer.json b/composer.json index 8ac7521..be5051e 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,8 @@ }, "require" : { "php": ">=5.6.0", - "typo3/cms": ">=6.2.0", - "ruflin/elastica": "~1.4" + "typo3/cms": "~6.2", + "ruflin/elastica": "~3.2" }, "require-dev": { "phpunit/phpunit": "~4.8.0"