From 4695054dcf072b04f4ecce98094b43696fe32a35 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Mon, 3 Mar 2014 19:26:44 +0100 Subject: [PATCH] Fix unit tests when running without phrasea2 extension --- .../SearchEngine/Phrasea/PhraseaEngine.php | 4 ++++ .../Phrasea/Application/ConsoleAPITest.php | 4 ++++ .../Phrasea/Application/OverviewTest.php | 1 + .../Phrasea/Border/Checker/Sha256Test.php | 1 + .../Tests/Phrasea/Border/ManagerTest.php | 4 ++++ .../Tests/Phrasea/Command/CheckConfigTest.php | 1 + .../Controller/Admin/AdminDashboardTest.php | 1 + .../Controller/Admin/SearchEngineTest.php | 15 +++++++++++---- .../Phrasea/Controller/Api/ApiTestCase.php | 19 +++++++++++++++++++ .../Phrasea/Controller/Client/RootTest.php | 8 ++++++++ .../Phrasea/Controller/Prod/LazaretTest.php | 1 + .../Phrasea/Controller/Prod/QueryTest.php | 6 ++++++ .../Phrasea/Controller/Prod/RecordsTest.php | 3 +++ .../Phrasea/Controller/Prod/RootTest.php | 1 + .../Phrasea/Controller/Prod/StoryTest.php | 1 + .../Phrasea/Controller/Prod/ToolsTest.php | 1 + .../Phrasea/Controller/Prod/UploadTest.php | 2 ++ .../Phrasea/Controller/Root/LoginTest.php | 2 ++ .../SearchEngineServiceProviderTest.php | 8 ++++++++ .../SearchEngine/ElasticSearchEngineTest.php | 4 ++++ .../PhraseaConfigurationPanelTest.php | 9 +++++++++ .../SearchEngine/PhraseaEngineTest.php | 3 ++- .../SearchEngine/SearchEngineAbstractTest.php | 12 ++++++++++-- .../Phrasea/Setup/ConfigurationTesterTest.php | 7 +++++-- .../Setup/Probe/SearchEngineProbeTest.php | 6 ++++++ tests/classes/PhraseanetTestCase.php | 19 +++++++++++++++++++ tests/classes/databox/fieldTest.php | 1 + tests/classes/record/adapterTest.php | 1 + 28 files changed, 136 insertions(+), 9 deletions(-) diff --git a/lib/Alchemy/Phrasea/SearchEngine/Phrasea/PhraseaEngine.php b/lib/Alchemy/Phrasea/SearchEngine/Phrasea/PhraseaEngine.php index 831b8148f1..17e559645c 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Phrasea/PhraseaEngine.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Phrasea/PhraseaEngine.php @@ -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; } diff --git a/tests/Alchemy/Tests/Phrasea/Application/ConsoleAPITest.php b/tests/Alchemy/Tests/Phrasea/Application/ConsoleAPITest.php index 04916c38e9..b55a2cb58f 100644 --- a/tests/Alchemy/Tests/Phrasea/Application/ConsoleAPITest.php +++ b/tests/Alchemy/Tests/Phrasea/Application/ConsoleAPITest.php @@ -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(); diff --git a/tests/Alchemy/Tests/Phrasea/Application/OverviewTest.php b/tests/Alchemy/Tests/Phrasea/Application/OverviewTest.php index d5feb50855..a3bc29665f 100644 --- a/tests/Alchemy/Tests/Phrasea/Application/OverviewTest.php +++ b/tests/Alchemy/Tests/Phrasea/Application/OverviewTest.php @@ -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()); diff --git a/tests/Alchemy/Tests/Phrasea/Border/Checker/Sha256Test.php b/tests/Alchemy/Tests/Phrasea/Border/Checker/Sha256Test.php index e4f3032c18..7291f24e79 100644 --- a/tests/Alchemy/Tests/Phrasea/Border/Checker/Sha256Test.php +++ b/tests/Alchemy/Tests/Phrasea/Border/Checker/Sha256Test.php @@ -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']]); diff --git a/tests/Alchemy/Tests/Phrasea/Border/ManagerTest.php b/tests/Alchemy/Tests/Phrasea/Border/ManagerTest.php index 7662ec6cd9..648c0bf4b2 100644 --- a/tests/Alchemy/Tests/Phrasea/Border/ManagerTest.php +++ b/tests/Alchemy/Tests/Phrasea/Border/ManagerTest.php @@ -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); diff --git a/tests/Alchemy/Tests/Phrasea/Command/CheckConfigTest.php b/tests/Alchemy/Tests/Phrasea/Command/CheckConfigTest.php index b8afa46df0..44011adf23 100644 --- a/tests/Alchemy/Tests/Phrasea/Command/CheckConfigTest.php +++ b/tests/Alchemy/Tests/Phrasea/Command/CheckConfigTest.php @@ -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)); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminDashboardTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminDashboardTest.php index c5c253470a..2acfe9f155 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminDashboardTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminDashboardTest.php @@ -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', diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Admin/SearchEngineTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Admin/SearchEngineTest.php index 1b543f1627..0b2fe43ba7 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Admin/SearchEngineTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Admin/SearchEngineTest.php @@ -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; } } diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Api/ApiTestCase.php b/tests/Alchemy/Tests/Phrasea/Controller/Api/ApiTestCase.php index a8d33eb4a4..c202ff49ee 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Api/ApiTestCase.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Api/ApiTestCase.php @@ -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/'; diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Client/RootTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Client/RootTest.php index 4728da4ee9..bfa5644a23 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Client/RootTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Client/RootTest.php @@ -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()); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/LazaretTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/LazaretTest.php index 489edd36bb..872a75d94a 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/LazaretTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/LazaretTest.php @@ -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(); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/QueryTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/QueryTest.php index eadce7a996..66cdfea407 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/QueryTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/QueryTest.php @@ -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']; diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/RecordsTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/RecordsTest.php index b98a8b88a2..ac28ffe635 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/RecordsTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/RecordsTest.php @@ -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']; diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/RootTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/RootTest.php index ea0317447e..434fd95753 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/RootTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/RootTest.php @@ -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(); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/StoryTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/StoryTest.php index b9a7e408a8..8ada79b79b 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/StoryTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/StoryTest.php @@ -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()) diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/ToolsTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/ToolsTest.php index 892d8508a2..9b234ea1b1 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/ToolsTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/ToolsTest.php @@ -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/', [ diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/UploadTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/UploadTest.php index 27c741762e..8b375469d8 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/UploadTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/UploadTest.php @@ -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, diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php index b4bd87806a..bd7c8bf6e3 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php @@ -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()); diff --git a/tests/Alchemy/Tests/Phrasea/Core/Provider/SearchEngineServiceProviderTest.php b/tests/Alchemy/Tests/Phrasea/Core/Provider/SearchEngineServiceProviderTest.php index 7350d7f37e..f27ba39de8 100644 --- a/tests/Alchemy/Tests/Phrasea/Core/Provider/SearchEngineServiceProviderTest.php +++ b/tests/Alchemy/Tests/Phrasea/Core/Provider/SearchEngineServiceProviderTest.php @@ -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 [ diff --git a/tests/Alchemy/Tests/Phrasea/SearchEngine/ElasticSearchEngineTest.php b/tests/Alchemy/Tests/Phrasea/SearchEngine/ElasticSearchEngineTest.php index 47e95bf850..0fedbe5221 100644 --- a/tests/Alchemy/Tests/Phrasea/SearchEngine/ElasticSearchEngineTest.php +++ b/tests/Alchemy/Tests/Phrasea/SearchEngine/ElasticSearchEngineTest.php @@ -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']); diff --git a/tests/Alchemy/Tests/Phrasea/SearchEngine/PhraseaConfigurationPanelTest.php b/tests/Alchemy/Tests/Phrasea/SearchEngine/PhraseaConfigurationPanelTest.php index 76e0566f55..00561378dc 100644 --- a/tests/Alchemy/Tests/Phrasea/SearchEngine/PhraseaConfigurationPanelTest.php +++ b/tests/Alchemy/Tests/Phrasea/SearchEngine/PhraseaConfigurationPanelTest.php @@ -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']); diff --git a/tests/Alchemy/Tests/Phrasea/SearchEngine/PhraseaEngineTest.php b/tests/Alchemy/Tests/Phrasea/SearchEngine/PhraseaEngineTest.php index 2bb11d0198..c9b5ce58ff 100644 --- a/tests/Alchemy/Tests/Phrasea/SearchEngine/PhraseaEngineTest.php +++ b/tests/Alchemy/Tests/Phrasea/SearchEngine/PhraseaEngineTest.php @@ -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() diff --git a/tests/Alchemy/Tests/Phrasea/SearchEngine/SearchEngineAbstractTest.php b/tests/Alchemy/Tests/Phrasea/SearchEngine/SearchEngineAbstractTest.php index 1c13b582f0..62bd9d3791 100644 --- a/tests/Alchemy/Tests/Phrasea/SearchEngine/SearchEngineAbstractTest.php +++ b/tests/Alchemy/Tests/Phrasea/SearchEngine/SearchEngineAbstractTest.php @@ -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() diff --git a/tests/Alchemy/Tests/Phrasea/Setup/ConfigurationTesterTest.php b/tests/Alchemy/Tests/Phrasea/Setup/ConfigurationTesterTest.php index 27dc8466dc..c6f2f8341b 100644 --- a/tests/Alchemy/Tests/Phrasea/Setup/ConfigurationTesterTest.php +++ b/tests/Alchemy/Tests/Phrasea/Setup/ConfigurationTesterTest.php @@ -149,14 +149,17 @@ 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); } } private function getTester(Application $app = null) { - $app = $app? : new Application('test'); + $app = $app ? : new Application('test'); return new ConfigurationTester($app); } diff --git a/tests/Alchemy/Tests/Phrasea/Setup/Probe/SearchEngineProbeTest.php b/tests/Alchemy/Tests/Phrasea/Setup/Probe/SearchEngineProbeTest.php index d258e74edc..14cdcad6ab 100644 --- a/tests/Alchemy/Tests/Phrasea/Setup/Probe/SearchEngineProbeTest.php +++ b/tests/Alchemy/Tests/Phrasea/Setup/Probe/SearchEngineProbeTest.php @@ -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'; diff --git a/tests/classes/PhraseanetTestCase.php b/tests/classes/PhraseanetTestCase.php index c10e8d0073..8f2e270a42 100644 --- a/tests/classes/PhraseanetTestCase.php +++ b/tests/classes/PhraseanetTestCase.php @@ -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; + } } diff --git a/tests/classes/databox/fieldTest.php b/tests/classes/databox/fieldTest.php index 09f8927f10..b775e82487 100644 --- a/tests/classes/databox/fieldTest.php +++ b/tests/classes/databox/fieldTest.php @@ -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, diff --git a/tests/classes/record/adapterTest.php b/tests/classes/record/adapterTest.php index 9d409d9ee7..c8315edef3 100644 --- a/tests/classes/record/adapterTest.php +++ b/tests/classes/record/adapterTest.php @@ -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();