diff --git a/tests/Alchemy/Tests/Phrasea/Command/Plugin/AddPluginTest.php b/tests/Alchemy/Tests/Phrasea/Command/Plugin/AddPluginTest.php index e1784cfcbf..523b4c00da 100644 --- a/tests/Alchemy/Tests/Phrasea/Command/Plugin/AddPluginTest.php +++ b/tests/Alchemy/Tests/Phrasea/Command/Plugin/AddPluginTest.php @@ -10,6 +10,26 @@ use Alchemy\Phrasea\Command\Plugin\AddPlugin; */ class AddPluginTest extends PluginCommandTestCase { + private $bkp = null; + + public function setUp() + { + parent::setUp(); + $this->bkp = self::$DI['app']['conf']->get('plugins'); + } + + public function tearDown() + { + if(is_null($this->bkp)) { + self::$DI['app']['conf']->remove('plugins'); + } + else { + self::$DI['app']['conf']->set('plugins', $this->bkp); + } + parent::tearDown(); + } + + public function testExecute() { $source = 'TestPlugin'; diff --git a/tests/Alchemy/Tests/Phrasea/Command/Plugin/DisablePluginTest.php b/tests/Alchemy/Tests/Phrasea/Command/Plugin/DisablePluginTest.php index 06029140c2..09a1b52c03 100644 --- a/tests/Alchemy/Tests/Phrasea/Command/Plugin/DisablePluginTest.php +++ b/tests/Alchemy/Tests/Phrasea/Command/Plugin/DisablePluginTest.php @@ -22,6 +22,8 @@ class DisablePluginTest extends PluginCommandTestCase ->with($this->equalTo('name')) ->will($this->returnValue('test-plugin')); + $bkp = self::$DI['cli']['conf']->get('plugins'); + self::$DI['cli']['conf']->set(['plugins', 'test-plugin', 'enabled'], $initial); $command = new DisablePlugin(); @@ -29,6 +31,13 @@ class DisablePluginTest extends PluginCommandTestCase $this->assertSame(0, $command->execute($input, $output)); $this->assertFalse(self::$DI['cli']['conf']->get(['plugins', 'test-plugin', 'enabled'])); + + if(is_null($bkp)) { + self::$DI['cli']['conf']->remove('plugins'); + } + else { + self::$DI['cli']['conf']->set('plugins', $bkp); + } } public function provideVariousInitialConfs() diff --git a/tests/Alchemy/Tests/Phrasea/Command/Plugin/EnablePluginTest.php b/tests/Alchemy/Tests/Phrasea/Command/Plugin/EnablePluginTest.php index d5f8c22ba8..9408489b55 100644 --- a/tests/Alchemy/Tests/Phrasea/Command/Plugin/EnablePluginTest.php +++ b/tests/Alchemy/Tests/Phrasea/Command/Plugin/EnablePluginTest.php @@ -22,6 +22,8 @@ class EnablePluginTest extends PluginCommandTestCase ->with($this->equalTo('name')) ->will($this->returnValue('test-plugin')); + $bkp = self::$DI['cli']['conf']->get('plugins'); + self::$DI['cli']['conf']->set(['plugins', 'test-plugin', 'enabled'], $initial); $command = new EnablePlugin(); @@ -29,6 +31,13 @@ class EnablePluginTest extends PluginCommandTestCase $this->assertSame(0, $command->execute($input, $output)); $this->assertTrue(self::$DI['cli']['conf']->get(['plugins', 'test-plugin', 'enabled'])); + + if(is_null($bkp)) { + self::$DI['cli']['conf']->remove('plugins'); + } + else { + self::$DI['cli']['conf']->set('plugins', $bkp); + } } public function provideVariousInitialConfs() diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/ExportTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/ExportTest.php index da278639c2..886df13e81 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/ExportTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/ExportTest.php @@ -132,9 +132,11 @@ class ExportTest extends \PhraseanetAuthenticatedWebTestCase { $app = $this->getApplication(); + $bkp = $app['conf']->get('registry'); + if (!$app['conf']->get(['registry', 'ftp', 'ftp-enabled'])) { $app['conf']->set(['registry', 'ftp', 'ftp-enabled'], true); - self::$GV_activeFTP = true; + self::$GV_activeFTP = true; } /** @var User $user */ @@ -158,6 +160,8 @@ class ExportTest extends \PhraseanetAuthenticatedWebTestCase $this->assertArrayHasKey('message', $datas); $this->assertTrue($datas['success']); unset($response, $datas); + + $app['conf']->set('registry', $bkp); } /** diff --git a/tests/Alchemy/Tests/Phrasea/Core/CLIProvider/PluginServiceProviderTest.php b/tests/Alchemy/Tests/Phrasea/Core/CLIProvider/PluginServiceProviderTest.php index ad07999d04..8af589cd4a 100644 --- a/tests/Alchemy/Tests/Phrasea/Core/CLIProvider/PluginServiceProviderTest.php +++ b/tests/Alchemy/Tests/Phrasea/Core/CLIProvider/PluginServiceProviderTest.php @@ -81,16 +81,26 @@ class PluginServiceProviderTest extends ServiceProviderTestCase } $app = self::$DI['cli']; - $app['conf']->set(['binaries', 'php_binary'], null); + + $bkp = $app['conf']->get(['main', 'binaries']); + + $app['conf']->set(['main', 'binaries', 'php_binary'], null); $app->register(new PluginServiceProvider()); $this->assertInstanceOf('Alchemy\Phrasea\Plugin\Management\ComposerInstaller', $app['plugins.composer-installer']); + + $app['conf']->set(['main', 'binaries'], $bkp); } public function testInstallerCanDetectPhpConf() { $app = self::$DI['cli']; - $app['conf']->set(['binaries', 'php_binary'], null); + + $bkp = $app['conf']->get(['main', 'binaries']); + + $app['conf']->set(['main', 'binaries', 'php_binary'], null); $app->register(new PluginServiceProvider()); $this->assertInstanceOf('Alchemy\Phrasea\Plugin\Management\ComposerInstaller', $app['plugins.composer-installer']); + + $app['conf']->set(['main', 'binaries'], $bkp); } } diff --git a/tests/Alchemy/Tests/Phrasea/Core/Configuration/DisplaySettingServiceTest.php b/tests/Alchemy/Tests/Phrasea/Core/Configuration/DisplaySettingServiceTest.php index 3cc753a6be..71269e4755 100644 --- a/tests/Alchemy/Tests/Phrasea/Core/Configuration/DisplaySettingServiceTest.php +++ b/tests/Alchemy/Tests/Phrasea/Core/Configuration/DisplaySettingServiceTest.php @@ -11,33 +11,33 @@ use Doctrine\Common\Collections\ArrayCollection; */ class DisplaySettingServiceTest extends \PhraseanetTestCase { - private static $userSettings; - private static $appSettings; + private $userSettings = false; + private $appSettings = false; public function setUp() { parent::setUp(); - if (null === self::$userSettings) { - self::$userSettings = self::$DI['app']['conf']->get(['user-settings'], []); - } - - if (null === self::$appSettings) { - self::$appSettings = self::$DI['app']['conf']->get(['registry'], []); - } + $this->userSettings = self::$DI['app']['conf']->get(['user-settings']); + $this->appSettings = self::$DI['app']['conf']->get(['registry']); } - public static function tearDownAfterClass() + public function tearDown() { - if (null !== self::$userSettings) { - self::$DI['app']['conf']->set('user-settings', self::$userSettings); + if (is_null($this->userSettings)) { + self::$DI['app']['conf']->remove('user-settings'); + } + else { + self::$DI['app']['conf']->set('user-settings', $this->userSettings); } - if (null !== self::$appSettings) { - self::$DI['app']['conf']->set('registry', self::$appSettings); + if (is_null($this->appSettings)) { + self::$DI['app']['conf']->remove('registry'); + } + else { + self::$DI['app']['conf']->set('registry', $this->appSettings); } - self::$userSettings = self::$appSettings = null; parent::tearDownAfterClass(); } diff --git a/tests/Alchemy/Tests/Phrasea/Core/Event/Subscriber/DebuggerSubscriberTest.php b/tests/Alchemy/Tests/Phrasea/Core/Event/Subscriber/DebuggerSubscriberTest.php index 938207cdf1..308d0a9ced 100644 --- a/tests/Alchemy/Tests/Phrasea/Core/Event/Subscriber/DebuggerSubscriberTest.php +++ b/tests/Alchemy/Tests/Phrasea/Core/Event/Subscriber/DebuggerSubscriberTest.php @@ -35,6 +35,8 @@ class DebuggerSubscriberTest extends \PhraseanetTestCase unlink($app['phraseanet.configuration.config-compiled-path']); } + $bkp = $app['conf']->get('debugger'); + $app['conf']->set(['debugger', 'allowed-ips'], $authorized); $app['dispatcher']->addSubscriber(new DebuggerSubscriber($app)); @@ -48,7 +50,14 @@ class DebuggerSubscriberTest extends \PhraseanetTestCase $this->setExpectedException('Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException'); } - $app->handle(new Request([], [], [], [], [], ['REMOTE_ADDR' => $incomingIp])); + try { + $app->handle(new Request([], [], [], [], [], ['REMOTE_ADDR' => $incomingIp])); + } + catch (\Exception $e) { + // no-op + } + + $app['conf']->set('debugger', $bkp); } public function provideIpsAndEnvironments() diff --git a/tests/Alchemy/Tests/Phrasea/Core/Provider/AuthenticationManagerServiceProviderTest.php b/tests/Alchemy/Tests/Phrasea/Core/Provider/AuthenticationManagerServiceProviderTest.php index fb128260f8..c28a005f72 100644 --- a/tests/Alchemy/Tests/Phrasea/Core/Provider/AuthenticationManagerServiceProviderTest.php +++ b/tests/Alchemy/Tests/Phrasea/Core/Provider/AuthenticationManagerServiceProviderTest.php @@ -95,6 +95,8 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase { $app = $this->loadApp(); + $bkp = $app['conf']->get('authentication'); + $app['conf']->set(['authentication', 'captcha', 'trials-before-display'], 42); //$app['orm.em'] = $this->createEntityManagerMock(); @@ -102,14 +104,21 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase $manager = $app['auth.native.failure-manager']; $this->assertEquals(42, $manager->getTrials()); + + $app['conf']->set('authentication', $bkp); } public function testFailureAccountCreator() { $app = $this->getApplication(); + + $bkp = $app['conf']->get('authentication'); + $app->register(new ConfigurationServiceProvider()); $app['conf']->set(['authentication', 'auto-create'], ['templates' => []]); $app['authentication.providers.account-creator']; + + $app['conf']->set('authentication', $bkp); } public function testAuthNativeWithCaptchaEnabled() @@ -121,6 +130,8 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase $app->register(new RepositoriesServiceProvider()); $app['phraseanet.appbox'] = self::$DI['app']['phraseanet.appbox']; + $bkp = $app['conf']->get('authentication'); + $app['conf']->set(['authentication', 'captcha'], ['enabled' => true]); $app['orm.em'] = $this->createEntityManagerMock(); @@ -131,6 +142,8 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase $app['recaptcha'] = $this->createReCaptchaMock(); $this->assertInstanceOf(FailureHandledNativeAuthentication::class, $app['auth.native']); + + $app['conf']->set('authentication', $bkp); } public function testAuthNativeWithCaptchaDisabled() @@ -141,6 +154,8 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase $app->register(new ConfigurationServiceProvider()); $app['phraseanet.appbox'] = self::$DI['app']['phraseanet.appbox']; + $bkp = $app['conf']->get('authentication'); + $app['conf']->set(['authentication', 'captcha'], ['enabled' => false]); $app['orm.em'] = $this->createEntityManagerMock(); @@ -148,6 +163,8 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase $app['recaptcha'] = $this->createReCaptchaMock(); $this->assertInstanceOf(NativeAuthentication::class, $app['auth.native']); + + $app['conf']->set('authentication', $bkp); } public function testAccountCreator() @@ -156,6 +173,8 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase $template1 = $user = $app['manipulator.user']->createTemplate('template1', self::$DI['user']); $template2 = $user = $app['manipulator.user']->createTemplate('template2', self::$DI['user']); + $bkp = $app['conf']->get('authentication'); + $app['conf']->set(['authentication', 'auto-create'], ['templates' => [$template1->getId(), $template2->getId()]]); $this->assertEquals([$template1->getLogin(), $template2->getLogin()], array_map(function (User $user) { @@ -164,6 +183,8 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase $this->removeUser($app, $template1); $this->removeUser($app, $template2); + + $app['conf']->set('authentication', $bkp); } private function createUserRepositoryMock() diff --git a/tests/Alchemy/Tests/Phrasea/Core/Provider/BorderManagerServiceProviderTest.php b/tests/Alchemy/Tests/Phrasea/Core/Provider/BorderManagerServiceProviderTest.php index 3ebca4a7f5..14f16bb8d4 100644 --- a/tests/Alchemy/Tests/Phrasea/Core/Provider/BorderManagerServiceProviderTest.php +++ b/tests/Alchemy/Tests/Phrasea/Core/Provider/BorderManagerServiceProviderTest.php @@ -38,10 +38,20 @@ class BorderManagerServiceProviderTest extends ServiceProviderTestCase $app->register(new PhraseanetServiceProvider()); $app['root.path'] = __DIR__ . '/../../../../../..'; $app->register(new ConfigurationServiceProvider()); + + $bkp = $app['conf']->get('border-manager'); + $app['conf']->set(['border-manager', 'enabled'], false); $this->assertInstanceOf('Alchemy\Phrasea\Border\Manager', $app['border-manager']); $this->assertNull($app['phraseanet.metadata-reader']->getPdfToText()); + + if(is_null($bkp)) { + $app['conf']->remove('border-manager'); + } + else { + $app['conf']->set('border-manager', $bkp); + } } public function testItLoadsWithXPDF() @@ -63,9 +73,19 @@ class BorderManagerServiceProviderTest extends ServiceProviderTestCase $app->register(new BorderManagerServiceProvider()); $app['root.path'] = __DIR__ . '/../../../../../..'; $app->register(new ConfigurationServiceProvider()); + + $bkp = $app['conf']->get('border-manager'); + $app['conf']->set(['border-manager', 'enabled'], false); $this->assertInstanceOf('Alchemy\Phrasea\Border\Manager', $app['border-manager']); $this->assertInstanceOf('XPDF\PdfToText', $app['phraseanet.metadata-reader']->getPdfToText()); + + if(is_null($bkp)) { + $app['conf']->remove('border-manager'); + } + else { + $app['conf']->set('border-manager', $bkp); + } } } diff --git a/tests/Alchemy/Tests/Phrasea/Core/Provider/LocaleServiceProviderTest.php b/tests/Alchemy/Tests/Phrasea/Core/Provider/LocaleServiceProviderTest.php index 49d0d54fc8..db97e02e07 100644 --- a/tests/Alchemy/Tests/Phrasea/Core/Provider/LocaleServiceProviderTest.php +++ b/tests/Alchemy/Tests/Phrasea/Core/Provider/LocaleServiceProviderTest.php @@ -27,6 +27,9 @@ class LocaleServiceProviderTest extends \PhraseanetTestCase $app->register(new LocaleServiceProvider()); $app['root.path'] = __DIR__ . '/../../../../../..'; $app->register(new ConfigurationServiceProvider()); + + $bkp = $app['conf']->get('languages'); + $app['conf']->set(['languages', 'available'], ['fr', 'zh', 'de']); $original = Application::getAvailableLanguages(); @@ -34,6 +37,8 @@ class LocaleServiceProviderTest extends \PhraseanetTestCase unset($original['nl']); $this->assertEquals($original, $app['locales.available']); + + $app['conf']->set('languages', $bkp); } public function testLocalesCustomizedWithError() @@ -43,6 +48,8 @@ class LocaleServiceProviderTest extends \PhraseanetTestCase $app['root.path'] = __DIR__ . '/../../../../../..'; $app->register(new ConfigurationServiceProvider()); + $bkp = $app['conf']->get('languages'); + $app['conf']->set(['languages', 'available'], ['en_US']); $app['monolog'] = $this->getMock('Psr\Log\LoggerInterface'); @@ -52,6 +59,8 @@ class LocaleServiceProviderTest extends \PhraseanetTestCase $original = Application::getAvailableLanguages(); $this->assertEquals($original, $app['locales.available']); + + $app['conf']->set('languages', $bkp); } public function testLocaleBeforeBoot() diff --git a/tests/Alchemy/Tests/Phrasea/Plugin/Management/AutoloaderGeneratorTest.php b/tests/Alchemy/Tests/Phrasea/Plugin/Management/AutoloaderGeneratorTest.php index 49bfc79340..42f6d2ea9d 100644 --- a/tests/Alchemy/Tests/Phrasea/Plugin/Management/AutoloaderGeneratorTest.php +++ b/tests/Alchemy/Tests/Phrasea/Plugin/Management/AutoloaderGeneratorTest.php @@ -15,6 +15,25 @@ use Symfony\Component\Process\ExecutableFinder; */ class AutoloaderGeneratorTest extends \PhraseanetTestCase { + private $bkp = null; + + public function setUp() + { + parent::setUp(); + $this->bkp = self::$DI['app']['conf']->get('plugins'); + } + + public function tearDown() + { + if(is_null($this->bkp)) { + self::$DI['app']['conf']->remove('plugins'); + } + else { + self::$DI['app']['conf']->set('plugins', $this->bkp); + } + parent::tearDown(); + } + public function testGeneratedFileAfterInstall() { $pluginDir = __DIR__ . '/../Fixtures/PluginDirInstalled/test-plugin'; diff --git a/tests/Alchemy/Tests/Phrasea/Plugin/PluginManagerTest.php b/tests/Alchemy/Tests/Phrasea/Plugin/PluginManagerTest.php index af439bdf15..39f676e4d1 100644 --- a/tests/Alchemy/Tests/Phrasea/Plugin/PluginManagerTest.php +++ b/tests/Alchemy/Tests/Phrasea/Plugin/PluginManagerTest.php @@ -11,6 +11,26 @@ use Alchemy\Phrasea\Plugin\Schema\PluginValidator; */ class PluginManagerTest extends PluginTestCase { + private $bkp; + + public function setUp() + { + parent::setUp(); + $this->bkp = self::$DI['app']['conf']->get('plugins'); + } + + public function tearDown() + { + if(is_null($this->bkp)) { + self::$DI['app']['conf']->remove('plugins'); + } + else { + self::$DI['app']['conf']->set('plugins', $this->bkp); + } + parent::tearDown(); + } + + public function testListGoodPlugins() { $prevPlugins = self::$DI['cli']['conf']->get('plugins');