Fix unit tests when running without phrasea2 extension

This commit is contained in:
Romain Neutron
2014-03-03 19:26:44 +01:00
parent 01a4b97f7a
commit 4695054dcf
28 changed files with 136 additions and 9 deletions

View File

@@ -41,6 +41,10 @@ class PhraseaEngine implements SearchEngineInterface
*/
public function __construct(Application $app)
{
if (!extension_loaded('phrasea2')) {
throw new RuntimeException('Phrasea2 is required to use Phrasea search engine.');
}
$this->app = $app;
}

View File

@@ -11,6 +11,10 @@ class ConsoleAPITest extends \PhraseanetTestCase
*/
public function testThatCommandsExitWithZero($console)
{
if (!extension_loaded('phrasea2')) {
$this->markTestSkipped('Phrasea2 is required');
}
$process = new Process(__DIR__ . '/../../../../../bin/'.$console);
$process->run();

View File

@@ -53,6 +53,7 @@ class OverviewTest extends \PhraseanetAuthenticatedWebTestCase
public function testDatafilesRouteNotAuthenticatedIsOkInPublicFeed()
{
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
self::$DI['record_5']->move_to_collection(self::$DI['collection_no_access'], self::$DI['app']['phraseanet.appbox']);
self::$DI['client']->request('GET', '/datafiles/' . self::$DI['record_5']->get_sbas_id() . '/' . self::$DI['record_5']->get_record_id() . '/preview/');
$this->assertEquals(200, self::$DI['client']->getResponse()->getStatusCode());

View File

@@ -40,6 +40,7 @@ class Sha256Test extends \PhraseanetTestCase
{
$session = self::$DI['app']['EM']->find('Phraseanet:LazaretSession', 1);
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
self::$DI['app']['border-manager']->process($session, File::buildFromPathfile($this->media->getFile()->getPathname(), self::$DI['collection'], self::$DI['app']), null, Manager::FORCE_RECORD);
$mock = $this->getMock('\\Alchemy\\Phrasea\\Border\\File', ['getSha256'], [self::$DI['app'], $this->media, self::$DI['collection']]);

View File

@@ -79,6 +79,7 @@ class ManagerTest extends \PhraseanetAuthenticatedWebTestCase
$records[] = $record;
};
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
$this->assertEquals(Manager::RECORD_CREATED, $this->object->process($this->session, File::buildFromPathfile(self::$file1, self::$DI['collection'], self::$DI['app']), $postProcessRecord));
$shaChecker = new Sha256(self::$DI['app']);
$this->object->registerChecker($shaChecker);
@@ -118,6 +119,7 @@ class ManagerTest extends \PhraseanetAuthenticatedWebTestCase
$postProcessRecord = function ($record) use (&$records) {
$records[] = $record;
};
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
$this->assertEquals(Manager::LAZARET_CREATED, $this->object->process($this->session, File::buildFromPathfile(self::$file1, self::$DI['collection'], self::$DI['app']), NULL, Manager::FORCE_LAZARET));
$this->assertEquals(Manager::RECORD_CREATED, $this->object->process($this->session, File::buildFromPathfile(self::$file1, self::$DI['collection'], self::$DI['app']), $postProcessRecord));
@@ -202,6 +204,7 @@ class ManagerTest extends \PhraseanetAuthenticatedWebTestCase
$file->addAttribute(new Status(self::$DI['app'], strrev($status)));
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
$this->assertEquals(Manager::RECORD_CREATED, $this->object->process($this->session, $file, $postProcessRecord, Manager::FORCE_RECORD));
$record = current($records);
@@ -552,6 +555,7 @@ class ManagerTest extends \PhraseanetAuthenticatedWebTestCase
$records[] = $record;
};
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
$visa = $this->object->getVisa(File::buildFromPathfile(self::$file1, self::$DI['collection'], self::$DI['app']));
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Border\\Visa', $visa);

View File

@@ -11,6 +11,7 @@ class CheckConfigTest extends \PhraseanetTestCase
$input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
self::$DI['cli']['phraseanet.SE'] = $this->createSearchEngineMock();
$command = new CheckConfig('check:config');
$command->setContainer(self::$DI['cli']);
$this->assertLessThan(2, $command->execute($input, $output));

View File

@@ -27,6 +27,7 @@ class AdminDashboardTest extends \PhraseanetAuthenticatedWebTestCase
public function testRouteDashboard()
{
$this->setAdmin(true);
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
self::$DI['app']['phraseanet.configuration-tester']->getRequirements();
self::$DI['client']->request('GET', '/admin/dashboard/', [
'flush_cache' => 'ok',

View File

@@ -2,6 +2,7 @@
namespace Alchemy\Tests\Phrasea\Controller\Admin;
use Alchemy\Phrasea\SearchEngine\Elastic\ElasticSearchEngine;
use Alchemy\Phrasea\SearchEngine\Phrasea\PhraseaEngine;
use Alchemy\Phrasea\SearchEngine\SphinxSearch\SphinxSearchEngine;
@@ -36,10 +37,16 @@ class SearchEngineTest extends \PhraseanetAuthenticatedWebTestCase
{
$app = $this->loadApp();
return [
[new PhraseaEngine($app)],
[new SphinxSearchEngine($app, 'localhost', 9306, 'localhost', 9308)],
];
$SE = [[new SphinxSearchEngine($app, 'localhost', 9306, 'localhost', 9308)]];
if (extension_loaded('phrasea2')) {
$SE[] = [new PhraseaEngine($app)];
}
if (false !== $ret = @file_get_contents('http://localhost:9200')) {
$SE[] = [ElasticSearchEngine::create($app)];
}
return $SE;
}
}

View File

@@ -469,6 +469,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
if (null === self::$adminToken) {
$this->markTestSkipped('there is no user with admin rights');
}
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
$this->setToken(self::$adminToken);
@@ -741,6 +742,10 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
public function testSearchRoute()
{
if (!extension_loaded('phrasea2')) {
$this->markTestSkipped('Phrasea2 extension is required for this test');
}
$this->setToken(self::$token);
self::$DI['client']->request('POST', '/api/v1/search/', $this->getParameters(), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
$content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
@@ -770,6 +775,10 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
public function testSearchRouteWithStories()
{
if (!extension_loaded('phrasea2')) {
$this->markTestSkipped('Phrasea2 extension is required for this test');
}
$this->setToken(self::$token);
self::$DI['record_story_1'];
@@ -802,6 +811,10 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
public function testRecordsSearchRoute()
{
if (!extension_loaded('phrasea2')) {
$this->markTestSkipped('Phrasea2 extension is required for this test');
}
$this->setToken(self::$token);
self::$DI['client']->request('POST', '/api/v1/records/search/', $this->getParameters(), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
$content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
@@ -855,6 +868,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
{
$this->setToken(self::$token);
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
$this->injectMetadatas(self::$DI['record_1']);
$route = '/api/v1/records/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/caption/';
@@ -1029,6 +1043,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
public function testRecordsSetMetadatas()
{
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
$this->setToken(self::$token);
$record = self::$DI['record_1'];
@@ -1086,6 +1101,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
public function testRecordsSetStatus()
{
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
$this->setToken(self::$token);
$route = '/api/v1/records/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/setstatus/';
@@ -1144,6 +1160,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
public function testMoveRecordToCollection()
{
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
$file = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess(__DIR__ . '/../../../../../files/test001.jpg'), self::$DI['collection']);
$record = \record_adapter::createFromFile($file, self::$DI['app']);
@@ -1344,6 +1361,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
public function testAddRecord()
{
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
$this->setToken(self::$token);
$route = '/api/v1/records/add/';
@@ -1363,6 +1381,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
public function testAddRecordForceRecord()
{
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
$this->setToken(self::$token);
$route = '/api/v1/records/add/';

View File

@@ -23,6 +23,10 @@ class RootTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testGetClient()
{
if (!extension_loaded('phrasea2')) {
$this->markTestSkipped('Phrasea2 is required for this test');
}
$this->authenticate(self::$DI['app']);
self::$DI['client']->request("GET", "/client/");
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
@@ -61,6 +65,10 @@ class RootTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testExecuteQuery()
{
if (!extension_loaded('phrasea2')) {
$this->markTestSkipped('Phrasea2 is required for this test');
}
$queryParameters = [];
$queryParameters["mod"] = self::$DI['app']['settings']->getUserSetting(self::$DI['user'], 'client_view', '3X6');
$queryParameters["bas"] = array_keys(self::$DI['app']['acl']->get(self::$DI['user'])->get_granted_base());

View File

@@ -126,6 +126,7 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testAddElement()
{
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
$originalEm = self::$DI['app']['EM'];
$em = $this->createEntityManagerMock();

View File

@@ -14,6 +14,9 @@ class QueryTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testQuery()
{
if (!extension_loaded('phrasea2')) {
$this->markTestSkipped('Phrasea2 is required for this test');
}
$route = '/prod/query/';
self::$DI['client']->request('POST', $route);
@@ -30,6 +33,9 @@ class QueryTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testQueryAnswerTrain()
{
if (!extension_loaded('phrasea2')) {
$this->markTestSkipped('Phrasea2 is required for this test');
}
$this->authenticate(self::$DI['app']);
self::$DI['record_2'];

View File

@@ -120,6 +120,9 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testGetRecordDetailResult()
{
if (!extension_loaded('phrasea2')) {
$this->markTestSkipped('Phrasea2 is required for this test');
}
$this->authenticate(self::$DI['app']);
self::$DI['record_1'];

View File

@@ -9,6 +9,7 @@ class RootTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testRouteSlash()
{
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
self::$DI['client']->request('GET', '/prod/');
$response = self::$DI['client']->getResponse();

View File

@@ -8,6 +8,7 @@ class StoryTest extends \PhraseanetAuthenticatedWebTestCase
{
public function testRootPost()
{
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
$route = "/prod/story/";
$collections = self::$DI['app']['acl']->get(self::$DI['app']['authentication']->getUser())

View File

@@ -26,6 +26,7 @@ class ToolsTest extends \PhraseanetAuthenticatedWebTestCase
public function testRouteChangeDoc()
{
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
$record = self::$DI['record_1'];
$crawler = self::$DI['client']->request('POST', '/prod/tools/hddoc/', [

View File

@@ -293,6 +293,7 @@ class UploadTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testUploadForceRecord()
{
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
$params = [
'base_id' => self::$DI['collection']->get_base_id(),
'forceAction' => Manager::FORCE_RECORD,
@@ -328,6 +329,7 @@ class UploadTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testUploadRecordStatus()
{
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
$params = [
'base_id' => self::$DI['collection']->get_base_id(),
'forceAction' => Manager::FORCE_RECORD,

View File

@@ -1111,6 +1111,8 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testGetLogout()
{
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
$this->assertTrue(self::$DI['app']['authentication']->isAuthenticated());
self::$DI['client']->request('GET', '/login/logout/', ['app' => 'prod']);
$this->assertFalse(self::$DI['app']['authentication']->isAuthenticated());

View File

@@ -7,6 +7,14 @@ namespace Alchemy\Tests\Phrasea\Core\Provider;
*/
class SearchEngineServiceProviderTest extends ServiceProviderTestCase
{
public function setUp()
{
if (!extension_loaded('phrasea2')) {
$this->markTestSkipped('Phrasea2 is required for this test');
}
parent::setUp();
}
public function provideServiceDescription()
{
return [

View File

@@ -9,6 +9,10 @@ class ElasticSearchEngineTest extends SearchEngineAbstractTest
{
public function setUp()
{
if (false === @file_get_contents('http://localhost:9200')) {
$this->markTestSkipped('Unable to connect to elasticsearch.');
}
parent::setUp();
$es = ElasticSearchEngine::create(self::$DI['app']);

View File

@@ -7,6 +7,15 @@ use Alchemy\Phrasea\SearchEngine\Phrasea\ConfigurationPanel;
class PhraseaConfigurationPanelTest extends ConfigurationPanelAbstractTest
{
public function setUp()
{
if (!extension_loaded('phrasea2')) {
$this->markTestSkipped('Phrasea extension is not loaded');
}
parent::setUp();
}
public function getPanel()
{
return new ConfigurationPanel(new PhraseaEngine(self::$DI['app']), self::$DI['app']['conf']);

View File

@@ -12,10 +12,11 @@ class PhraseaEngineTest extends SearchEngineAbstractTest
{
public function setUp()
{
parent::setUp();
if (!extension_loaded('phrasea2')) {
$this->markTestSkipped('Phrasea extension is not loaded');
}
parent::setUp();
}
public function initialize()

View File

@@ -43,6 +43,9 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$this->markTestSkipped('Unable to initialize search Engine');
}
self::$DI['app']['phraseanet.SE'] = self::$searchEngine;
self::$DI['app']['phraseanet.SE.subscriber'] = self::$searchEngine->createSubscriber(self::$DI['app']);
$options = new SearchEngineOptions();
$options->onCollections($databox->get_collections());
@@ -268,11 +271,16 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$record = self::$DI['record_2'];
$query_string = 'boomboklot' . $record->get_record_id() . 'defaultNotIndexed';
$this->editRecord($query_string, $record);
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
$this->assertEquals(0, $results->getTotal());
$this->editRecord($query_string, $record);
self::$searchEngine->resetCache();
$this->updateIndex();
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
$this->assertEquals(1, $results->getTotal());
}
public function testAddRecord()

View File

@@ -149,7 +149,10 @@ class ConfigurationTesterTest extends AbstractSetupTester
public function testGetRequirements()
{
foreach ($this->getTester()->getRequirements() as $requirements) {
$app = new Application('test');
$app['phraseanet.SE'] = $this->createSearchEngineMock();
foreach ($this->getTester($app)->getRequirements() as $requirements) {
$this->assertInstanceOf('Alchemy\Phrasea\Setup\RequirementCollectionInterface', $requirements);
}
}

View File

@@ -4,6 +4,12 @@ namespace Alchemy\Tests\Phrasea\Setup\Probe;
class SearchEngineProbeTest extends ProbeTestCase
{
public function setUp()
{
parent::setUp();
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
}
protected function getClassName()
{
return 'Alchemy\Phrasea\Setup\Probe\SearchEngineProbe';

View File

@@ -670,4 +670,23 @@ abstract class PhraseanetTestCase extends WebTestCase
->disableOriginalConstructor()
->getMock();
}
protected function createSearchEngineMock()
{
$mock = $this->getMock('Alchemy\Phrasea\SearchEngine\SearchEngineInterface');
$mock->expects($this->any())
->method('createSubscriber')
->will($this->returnValue($this->getMock('Symfony\Component\EventDispatcher\EventSubscriberInterface')));
$mock->expects($this->any())
->method('getConfigurationPanel')
->will($this->returnValue($this->getMock('Alchemy\Phrasea\SearchEngine\ConfigurationPanelInterface')));
$mock->expects($this->any())
->method('getStatus')
->will($this->returnValue([]));
$mock->staticExpects($this->any())
->method('createSubscriber')
->will($this->returnValue($this->getMock('Symfony\Component\EventDispatcher\EventSubscriberInterface')));
return $mock;
}
}

View File

@@ -393,6 +393,7 @@ class databox_fieldTest extends \PhraseanetTestCase
{
$AddedValue = 'scalar value';
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
self::$DI['record_1']->set_metadatas([
[
'meta_id' => null,

View File

@@ -339,6 +339,7 @@ class record_adapterTest extends \PhraseanetAuthenticatedTestCase
}
}
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
self::$DI['record_1']->set_metadatas($metadatas, true);
$caption = self::$DI['record_1']->get_caption();