TASK: Restructure tests

* As introduces through review, the tests are working and have huge code
  coverage, but don't test what they say. Therefore we reorder them in
  new structure, to have new tests in clean structure.
This commit is contained in:
Daniel Siepmann 2016-12-15 11:31:48 +01:00
parent b2a300bae1
commit 203b70898b
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
4 changed files with 75 additions and 20 deletions

View file

@ -24,18 +24,22 @@ use TYPO3\CMS\Core\Tests\FunctionalTestCase as CoreTestCase;
/** /**
* All functional tests should extend this base class. * 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 abstract class AbstractFunctionalTestCase extends CoreTestCase
{ {
protected $testExtensionsToLoad = ['typo3conf/ext/search_core']; 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() public function setUp()
{ {
@ -46,19 +50,14 @@ abstract class AbstractFunctionalTestCase extends CoreTestCase
// Provide necessary configuration for extension // Provide necessary configuration for extension
$this->importDataSet('Tests/Functional/Fixtures/BasicSetup.xml'); $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. if ($this->loadDefaultTs) {
$this->client = new \Elastica\Client([ $this->setUpFrontendRootPage(1, $this->getDefaultPageTs());
'host' => getenv('ES_HOST') ?: \Elastica\Connection::DEFAULT_HOST, }
'port' => getenv('ES_PORT') ?: \Elastica\Connection::DEFAULT_PORT,
]);
} }
public function tearDown() protected function getDefaultPageTs()
{ {
// Delete everything so next test starts clean. return ['EXT:search_core/Tests/Functional/Fixtures/BasicSetup.ts'];
$this->client->getIndex('_all')->delete();
$this->client->getIndex('_all')->clearCache();
} }
} }

View file

@ -0,0 +1,54 @@
<?php
namespace Leonmrni\SearchCore\Tests\Functional\Connection\Elasticsearch;
/*
* 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\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();
}
}

View file

@ -1,5 +1,5 @@
<?php <?php
namespace Leonmrni\SearchCore\Tests\Functional\Indexing; namespace Leonmrni\SearchCore\Tests\Functional\Connection\Elasticsearch;
/* /*
* Copyright (C) 2016 Daniel Siepmann <coding@daniel-siepmann.de> * Copyright (C) 2016 Daniel Siepmann <coding@daniel-siepmann.de>
@ -21,11 +21,10 @@ namespace Leonmrni\SearchCore\Tests\Functional\Indexing;
*/ */
use Leonmrni\SearchCore\Domain\Index\IndexerFactory; use Leonmrni\SearchCore\Domain\Index\IndexerFactory;
use Leonmrni\SearchCore\Tests\Functional\AbstractFunctionalTestCase;
use TYPO3\CMS\Extbase\Object\ObjectManager; use TYPO3\CMS\Extbase\Object\ObjectManager;
/** /**
* * TODO: https://github.com/DanielSiepmann/search_core/issues/16
*/ */
class IndexTcaTableTest extends AbstractFunctionalTestCase class IndexTcaTableTest extends AbstractFunctionalTestCase
{ {

View file

@ -21,12 +21,15 @@ namespace Leonmrni\SearchCore\Tests\Functional\Hooks;
*/ */
use Leonmrni\SearchCore\Hook\DataHandler as Hook; 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\Core\DataHandling\DataHandler as CoreDataHandler;
use TYPO3\CMS\Extbase\Object\ObjectManager; 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 class DataHandlerTest extends AbstractFunctionalTestCase
{ {