diff --git a/Tests/Functional/AbstractFunctionalTestCase.php b/Tests/Functional/AbstractFunctionalTestCase.php index b9b6dfb..5c253be 100644 --- a/Tests/Functional/AbstractFunctionalTestCase.php +++ b/Tests/Functional/AbstractFunctionalTestCase.php @@ -24,18 +24,22 @@ 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. - * TODO: this is in reality an "elastica" abstract case - not search_core ;) */ abstract class AbstractFunctionalTestCase extends CoreTestCase { protected $testExtensionsToLoad = ['typo3conf/ext/search_core']; /** - * @var \Elastica\Client + * 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 $client; + protected $loadDefaultTs = true; public function setUp() { @@ -46,19 +50,14 @@ abstract class AbstractFunctionalTestCase extends CoreTestCase // 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, - ]); + if ($this->loadDefaultTs) { + $this->setUpFrontendRootPage(1, $this->getDefaultPageTs()); + } } - public function tearDown() + protected function getDefaultPageTs() { - // Delete everything so next test starts clean. - $this->client->getIndex('_all')->delete(); - $this->client->getIndex('_all')->clearCache(); + return ['EXT:search_core/Tests/Functional/Fixtures/BasicSetup.ts']; } } diff --git a/Tests/Functional/Connection/Elasticsearch/AbstractFunctionalTestCase.php b/Tests/Functional/Connection/Elasticsearch/AbstractFunctionalTestCase.php new file mode 100644 index 0000000..cdd8ddf --- /dev/null +++ b/Tests/Functional/Connection/Elasticsearch/AbstractFunctionalTestCase.php @@ -0,0 +1,54 @@ + + * + * 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\Tests\Functional\AbstractFunctionalTestCase as BaseFunctionalTestCase; + +/** + * All functional tests should extend this base class. + * + * It will take care of leaving a clean environment for next test. + */ +abstract class AbstractFunctionalTestCase extends BaseFunctionalTestCase +{ + /** + * @var \Elastica\Client + */ + protected $client; + + public function setUp() + { + parent::setUp(); + + // 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/Indexing/IndexTcaTableTest.php b/Tests/Functional/Connection/Elasticsearch/IndexTcaTableTest.php similarity index 97% rename from Tests/Functional/Indexing/IndexTcaTableTest.php rename to Tests/Functional/Connection/Elasticsearch/IndexTcaTableTest.php index 6c08a50..30d55f9 100644 --- a/Tests/Functional/Indexing/IndexTcaTableTest.php +++ b/Tests/Functional/Connection/Elasticsearch/IndexTcaTableTest.php @@ -1,5 +1,5 @@ @@ -21,11 +21,10 @@ namespace Leonmrni\SearchCore\Tests\Functional\Indexing; */ use Leonmrni\SearchCore\Domain\Index\IndexerFactory; -use Leonmrni\SearchCore\Tests\Functional\AbstractFunctionalTestCase; use TYPO3\CMS\Extbase\Object\ObjectManager; /** - * + * TODO: https://github.com/DanielSiepmann/search_core/issues/16 */ class IndexTcaTableTest extends AbstractFunctionalTestCase { diff --git a/Tests/Functional/Hooks/DataHandlerTest.php b/Tests/Functional/Hooks/DataHandlerTest.php index 60c0115..7139934 100644 --- a/Tests/Functional/Hooks/DataHandlerTest.php +++ b/Tests/Functional/Hooks/DataHandlerTest.php @@ -21,12 +21,15 @@ namespace Leonmrni\SearchCore\Tests\Functional\Hooks; */ use Leonmrni\SearchCore\Hook\DataHandler as Hook; -use Leonmrni\SearchCore\Tests\Functional\AbstractFunctionalTestCase; +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 {