PHRAS-2859_tests-do-corrupt-conf_4.1

fix : configuration.yml is not modified by unit-tests anymore
This commit is contained in:
Jean-Yves Gaulier
2019-12-12 16:53:15 +01:00
parent 5a500b2f02
commit 915e7bcd32
12 changed files with 169 additions and 19 deletions

View File

@@ -10,6 +10,26 @@ use Alchemy\Phrasea\Command\Plugin\AddPlugin;
*/ */
class AddPluginTest extends PluginCommandTestCase 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() public function testExecute()
{ {
$source = 'TestPlugin'; $source = 'TestPlugin';

View File

@@ -22,6 +22,8 @@ class DisablePluginTest extends PluginCommandTestCase
->with($this->equalTo('name')) ->with($this->equalTo('name'))
->will($this->returnValue('test-plugin')); ->will($this->returnValue('test-plugin'));
$bkp = self::$DI['cli']['conf']->get('plugins');
self::$DI['cli']['conf']->set(['plugins', 'test-plugin', 'enabled'], $initial); self::$DI['cli']['conf']->set(['plugins', 'test-plugin', 'enabled'], $initial);
$command = new DisablePlugin(); $command = new DisablePlugin();
@@ -29,6 +31,13 @@ class DisablePluginTest extends PluginCommandTestCase
$this->assertSame(0, $command->execute($input, $output)); $this->assertSame(0, $command->execute($input, $output));
$this->assertFalse(self::$DI['cli']['conf']->get(['plugins', 'test-plugin', 'enabled'])); $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() public function provideVariousInitialConfs()

View File

@@ -22,6 +22,8 @@ class EnablePluginTest extends PluginCommandTestCase
->with($this->equalTo('name')) ->with($this->equalTo('name'))
->will($this->returnValue('test-plugin')); ->will($this->returnValue('test-plugin'));
$bkp = self::$DI['cli']['conf']->get('plugins');
self::$DI['cli']['conf']->set(['plugins', 'test-plugin', 'enabled'], $initial); self::$DI['cli']['conf']->set(['plugins', 'test-plugin', 'enabled'], $initial);
$command = new EnablePlugin(); $command = new EnablePlugin();
@@ -29,6 +31,13 @@ class EnablePluginTest extends PluginCommandTestCase
$this->assertSame(0, $command->execute($input, $output)); $this->assertSame(0, $command->execute($input, $output));
$this->assertTrue(self::$DI['cli']['conf']->get(['plugins', 'test-plugin', 'enabled'])); $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() public function provideVariousInitialConfs()

View File

@@ -132,9 +132,11 @@ class ExportTest extends \PhraseanetAuthenticatedWebTestCase
{ {
$app = $this->getApplication(); $app = $this->getApplication();
$bkp = $app['conf']->get('registry');
if (!$app['conf']->get(['registry', 'ftp', 'ftp-enabled'])) { if (!$app['conf']->get(['registry', 'ftp', 'ftp-enabled'])) {
$app['conf']->set(['registry', 'ftp', 'ftp-enabled'], true); $app['conf']->set(['registry', 'ftp', 'ftp-enabled'], true);
self::$GV_activeFTP = true; self::$GV_activeFTP = true;
} }
/** @var User $user */ /** @var User $user */
@@ -158,6 +160,8 @@ class ExportTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertArrayHasKey('message', $datas); $this->assertArrayHasKey('message', $datas);
$this->assertTrue($datas['success']); $this->assertTrue($datas['success']);
unset($response, $datas); unset($response, $datas);
$app['conf']->set('registry', $bkp);
} }
/** /**

View File

@@ -81,16 +81,26 @@ class PluginServiceProviderTest extends ServiceProviderTestCase
} }
$app = self::$DI['cli']; $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()); $app->register(new PluginServiceProvider());
$this->assertInstanceOf('Alchemy\Phrasea\Plugin\Management\ComposerInstaller', $app['plugins.composer-installer']); $this->assertInstanceOf('Alchemy\Phrasea\Plugin\Management\ComposerInstaller', $app['plugins.composer-installer']);
$app['conf']->set(['main', 'binaries'], $bkp);
} }
public function testInstallerCanDetectPhpConf() public function testInstallerCanDetectPhpConf()
{ {
$app = self::$DI['cli']; $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()); $app->register(new PluginServiceProvider());
$this->assertInstanceOf('Alchemy\Phrasea\Plugin\Management\ComposerInstaller', $app['plugins.composer-installer']); $this->assertInstanceOf('Alchemy\Phrasea\Plugin\Management\ComposerInstaller', $app['plugins.composer-installer']);
$app['conf']->set(['main', 'binaries'], $bkp);
} }
} }

View File

@@ -11,33 +11,33 @@ use Doctrine\Common\Collections\ArrayCollection;
*/ */
class DisplaySettingServiceTest extends \PhraseanetTestCase class DisplaySettingServiceTest extends \PhraseanetTestCase
{ {
private static $userSettings; private $userSettings = false;
private static $appSettings; private $appSettings = false;
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
if (null === self::$userSettings) { $this->userSettings = self::$DI['app']['conf']->get(['user-settings']);
self::$userSettings = self::$DI['app']['conf']->get(['user-settings'], []); $this->appSettings = self::$DI['app']['conf']->get(['registry']);
}
if (null === self::$appSettings) {
self::$appSettings = self::$DI['app']['conf']->get(['registry'], []);
}
} }
public static function tearDownAfterClass() public function tearDown()
{ {
if (null !== self::$userSettings) { if (is_null($this->userSettings)) {
self::$DI['app']['conf']->set('user-settings', self::$userSettings); self::$DI['app']['conf']->remove('user-settings');
}
else {
self::$DI['app']['conf']->set('user-settings', $this->userSettings);
} }
if (null !== self::$appSettings) { if (is_null($this->appSettings)) {
self::$DI['app']['conf']->set('registry', self::$appSettings); self::$DI['app']['conf']->remove('registry');
}
else {
self::$DI['app']['conf']->set('registry', $this->appSettings);
} }
self::$userSettings = self::$appSettings = null;
parent::tearDownAfterClass(); parent::tearDownAfterClass();
} }

View File

@@ -35,6 +35,8 @@ class DebuggerSubscriberTest extends \PhraseanetTestCase
unlink($app['phraseanet.configuration.config-compiled-path']); unlink($app['phraseanet.configuration.config-compiled-path']);
} }
$bkp = $app['conf']->get('debugger');
$app['conf']->set(['debugger', 'allowed-ips'], $authorized); $app['conf']->set(['debugger', 'allowed-ips'], $authorized);
$app['dispatcher']->addSubscriber(new DebuggerSubscriber($app)); $app['dispatcher']->addSubscriber(new DebuggerSubscriber($app));
@@ -48,7 +50,14 @@ class DebuggerSubscriberTest extends \PhraseanetTestCase
$this->setExpectedException('Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException'); $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() public function provideIpsAndEnvironments()

View File

@@ -95,6 +95,8 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase
{ {
$app = $this->loadApp(); $app = $this->loadApp();
$bkp = $app['conf']->get('authentication');
$app['conf']->set(['authentication', 'captcha', 'trials-before-display'], 42); $app['conf']->set(['authentication', 'captcha', 'trials-before-display'], 42);
//$app['orm.em'] = $this->createEntityManagerMock(); //$app['orm.em'] = $this->createEntityManagerMock();
@@ -102,14 +104,21 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase
$manager = $app['auth.native.failure-manager']; $manager = $app['auth.native.failure-manager'];
$this->assertEquals(42, $manager->getTrials()); $this->assertEquals(42, $manager->getTrials());
$app['conf']->set('authentication', $bkp);
} }
public function testFailureAccountCreator() public function testFailureAccountCreator()
{ {
$app = $this->getApplication(); $app = $this->getApplication();
$bkp = $app['conf']->get('authentication');
$app->register(new ConfigurationServiceProvider()); $app->register(new ConfigurationServiceProvider());
$app['conf']->set(['authentication', 'auto-create'], ['templates' => []]); $app['conf']->set(['authentication', 'auto-create'], ['templates' => []]);
$app['authentication.providers.account-creator']; $app['authentication.providers.account-creator'];
$app['conf']->set('authentication', $bkp);
} }
public function testAuthNativeWithCaptchaEnabled() public function testAuthNativeWithCaptchaEnabled()
@@ -121,6 +130,8 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase
$app->register(new RepositoriesServiceProvider()); $app->register(new RepositoriesServiceProvider());
$app['phraseanet.appbox'] = self::$DI['app']['phraseanet.appbox']; $app['phraseanet.appbox'] = self::$DI['app']['phraseanet.appbox'];
$bkp = $app['conf']->get('authentication');
$app['conf']->set(['authentication', 'captcha'], ['enabled' => true]); $app['conf']->set(['authentication', 'captcha'], ['enabled' => true]);
$app['orm.em'] = $this->createEntityManagerMock(); $app['orm.em'] = $this->createEntityManagerMock();
@@ -131,6 +142,8 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase
$app['recaptcha'] = $this->createReCaptchaMock(); $app['recaptcha'] = $this->createReCaptchaMock();
$this->assertInstanceOf(FailureHandledNativeAuthentication::class, $app['auth.native']); $this->assertInstanceOf(FailureHandledNativeAuthentication::class, $app['auth.native']);
$app['conf']->set('authentication', $bkp);
} }
public function testAuthNativeWithCaptchaDisabled() public function testAuthNativeWithCaptchaDisabled()
@@ -141,6 +154,8 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase
$app->register(new ConfigurationServiceProvider()); $app->register(new ConfigurationServiceProvider());
$app['phraseanet.appbox'] = self::$DI['app']['phraseanet.appbox']; $app['phraseanet.appbox'] = self::$DI['app']['phraseanet.appbox'];
$bkp = $app['conf']->get('authentication');
$app['conf']->set(['authentication', 'captcha'], ['enabled' => false]); $app['conf']->set(['authentication', 'captcha'], ['enabled' => false]);
$app['orm.em'] = $this->createEntityManagerMock(); $app['orm.em'] = $this->createEntityManagerMock();
@@ -148,6 +163,8 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase
$app['recaptcha'] = $this->createReCaptchaMock(); $app['recaptcha'] = $this->createReCaptchaMock();
$this->assertInstanceOf(NativeAuthentication::class, $app['auth.native']); $this->assertInstanceOf(NativeAuthentication::class, $app['auth.native']);
$app['conf']->set('authentication', $bkp);
} }
public function testAccountCreator() public function testAccountCreator()
@@ -156,6 +173,8 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase
$template1 = $user = $app['manipulator.user']->createTemplate('template1', self::$DI['user']); $template1 = $user = $app['manipulator.user']->createTemplate('template1', self::$DI['user']);
$template2 = $user = $app['manipulator.user']->createTemplate('template2', 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()]]); $app['conf']->set(['authentication', 'auto-create'], ['templates' => [$template1->getId(), $template2->getId()]]);
$this->assertEquals([$template1->getLogin(), $template2->getLogin()], array_map(function (User $user) { $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, $template1);
$this->removeUser($app, $template2); $this->removeUser($app, $template2);
$app['conf']->set('authentication', $bkp);
} }
private function createUserRepositoryMock() private function createUserRepositoryMock()

View File

@@ -38,10 +38,20 @@ class BorderManagerServiceProviderTest extends ServiceProviderTestCase
$app->register(new PhraseanetServiceProvider()); $app->register(new PhraseanetServiceProvider());
$app['root.path'] = __DIR__ . '/../../../../../..'; $app['root.path'] = __DIR__ . '/../../../../../..';
$app->register(new ConfigurationServiceProvider()); $app->register(new ConfigurationServiceProvider());
$bkp = $app['conf']->get('border-manager');
$app['conf']->set(['border-manager', 'enabled'], false); $app['conf']->set(['border-manager', 'enabled'], false);
$this->assertInstanceOf('Alchemy\Phrasea\Border\Manager', $app['border-manager']); $this->assertInstanceOf('Alchemy\Phrasea\Border\Manager', $app['border-manager']);
$this->assertNull($app['phraseanet.metadata-reader']->getPdfToText()); $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() public function testItLoadsWithXPDF()
@@ -63,9 +73,19 @@ class BorderManagerServiceProviderTest extends ServiceProviderTestCase
$app->register(new BorderManagerServiceProvider()); $app->register(new BorderManagerServiceProvider());
$app['root.path'] = __DIR__ . '/../../../../../..'; $app['root.path'] = __DIR__ . '/../../../../../..';
$app->register(new ConfigurationServiceProvider()); $app->register(new ConfigurationServiceProvider());
$bkp = $app['conf']->get('border-manager');
$app['conf']->set(['border-manager', 'enabled'], false); $app['conf']->set(['border-manager', 'enabled'], false);
$this->assertInstanceOf('Alchemy\Phrasea\Border\Manager', $app['border-manager']); $this->assertInstanceOf('Alchemy\Phrasea\Border\Manager', $app['border-manager']);
$this->assertInstanceOf('XPDF\PdfToText', $app['phraseanet.metadata-reader']->getPdfToText()); $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);
}
} }
} }

View File

@@ -27,6 +27,9 @@ class LocaleServiceProviderTest extends \PhraseanetTestCase
$app->register(new LocaleServiceProvider()); $app->register(new LocaleServiceProvider());
$app['root.path'] = __DIR__ . '/../../../../../..'; $app['root.path'] = __DIR__ . '/../../../../../..';
$app->register(new ConfigurationServiceProvider()); $app->register(new ConfigurationServiceProvider());
$bkp = $app['conf']->get('languages');
$app['conf']->set(['languages', 'available'], ['fr', 'zh', 'de']); $app['conf']->set(['languages', 'available'], ['fr', 'zh', 'de']);
$original = Application::getAvailableLanguages(); $original = Application::getAvailableLanguages();
@@ -34,6 +37,8 @@ class LocaleServiceProviderTest extends \PhraseanetTestCase
unset($original['nl']); unset($original['nl']);
$this->assertEquals($original, $app['locales.available']); $this->assertEquals($original, $app['locales.available']);
$app['conf']->set('languages', $bkp);
} }
public function testLocalesCustomizedWithError() public function testLocalesCustomizedWithError()
@@ -43,6 +48,8 @@ class LocaleServiceProviderTest extends \PhraseanetTestCase
$app['root.path'] = __DIR__ . '/../../../../../..'; $app['root.path'] = __DIR__ . '/../../../../../..';
$app->register(new ConfigurationServiceProvider()); $app->register(new ConfigurationServiceProvider());
$bkp = $app['conf']->get('languages');
$app['conf']->set(['languages', 'available'], ['en_US']); $app['conf']->set(['languages', 'available'], ['en_US']);
$app['monolog'] = $this->getMock('Psr\Log\LoggerInterface'); $app['monolog'] = $this->getMock('Psr\Log\LoggerInterface');
@@ -52,6 +59,8 @@ class LocaleServiceProviderTest extends \PhraseanetTestCase
$original = Application::getAvailableLanguages(); $original = Application::getAvailableLanguages();
$this->assertEquals($original, $app['locales.available']); $this->assertEquals($original, $app['locales.available']);
$app['conf']->set('languages', $bkp);
} }
public function testLocaleBeforeBoot() public function testLocaleBeforeBoot()

View File

@@ -15,6 +15,25 @@ use Symfony\Component\Process\ExecutableFinder;
*/ */
class AutoloaderGeneratorTest extends \PhraseanetTestCase 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() public function testGeneratedFileAfterInstall()
{ {
$pluginDir = __DIR__ . '/../Fixtures/PluginDirInstalled/test-plugin'; $pluginDir = __DIR__ . '/../Fixtures/PluginDirInstalled/test-plugin';

View File

@@ -11,6 +11,26 @@ use Alchemy\Phrasea\Plugin\Schema\PluginValidator;
*/ */
class PluginManagerTest extends PluginTestCase 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() public function testListGoodPlugins()
{ {
$prevPlugins = self::$DI['cli']['conf']->get('plugins'); $prevPlugins = self::$DI['cli']['conf']->get('plugins');