diff --git a/tests/Alchemy/Tests/Phrasea/Cache/FactoryTest.php b/tests/Alchemy/Tests/Phrasea/Cache/FactoryTest.php new file mode 100644 index 0000000000..93fd5bb108 --- /dev/null +++ b/tests/Alchemy/Tests/Phrasea/Cache/FactoryTest.php @@ -0,0 +1,39 @@ +markTestSkipped(sprintf('Extension %s is not loaded', $extension)); + } + + $factory = new Factory(); + $this->assertInstanceOf($expected, $factory->create($name, array())); + } + + public function provideCacheTypes() + { + return array( + array('apc', 'apc', 'Alchemy\Phrasea\Cache\ApcCache'), + array('apccache', 'apc', 'Alchemy\Phrasea\Cache\ApcCache'), + array('array', null, 'Alchemy\Phrasea\Cache\ArrayCache'), + array('arraycache', null, 'Alchemy\Phrasea\Cache\ArrayCache'), + array('memcache', 'memcache', 'Alchemy\Phrasea\Cache\MemcacheCache'), + array('memcachecache', 'memcache', 'Alchemy\Phrasea\Cache\MemcacheCache'), + array('redis', 'redis', 'Alchemy\Phrasea\Cache\RedisCache'), + array('rediscache', 'redis', 'Alchemy\Phrasea\Cache\RedisCache'), + array('wincache', 'wincache', 'Alchemy\Phrasea\Cache\WincacheCache'), + array('wincachecache', 'wincache', 'Alchemy\Phrasea\Cache\WincacheCache'), + array('xcache', 'xcache', 'Alchemy\Phrasea\Cache\XcacheCache'), + array('xcachecache', 'xcache', 'Alchemy\Phrasea\Cache\XcacheCache'), + ); + } +} diff --git a/tests/Alchemy/Tests/Phrasea/Cache/ManagerTest.php b/tests/Alchemy/Tests/Phrasea/Cache/ManagerTest.php new file mode 100644 index 0000000000..a5f39f66ce --- /dev/null +++ b/tests/Alchemy/Tests/Phrasea/Cache/ManagerTest.php @@ -0,0 +1,187 @@ +file = __DIR__ . '/tmp-file.php'; + $this->compiler = new Compiler(); + $this->clean(); + } + + public function tearDown() + { + $this->clean(); + parent::tearDown(); + } + + private function clean() + { + if (is_file($this->file)) { + unlink($this->file); + } + } + + private function createEmptyRegistry() + { + file_put_contents($this->file, $this->compiler->compile(array())); + } + + public function testFactoryCreateOne() + { + $compiler = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration\Compiler') + ->disableOriginalConstructor() + ->getMock(); + $logger = $this->getMockBuilder('Monolog\Logger') + ->disableOriginalConstructor() + ->getMock(); + $factory = $this->getMockBuilder('Alchemy\Phrasea\Cache\Factory') + ->disableOriginalConstructor() + ->getMock(); + + $compiler->expects($this->once()) + ->method('compile'); + + $cache = $this->getMock('Alchemy\Phrasea\Cache\Cache'); + + $name = 'array'; + $values = array('option', 'value'); + + $factory->expects($this->once()) + ->method('create') + ->with($name, $values) + ->will($this->returnValue($cache)); + + $this->createEmptyRegistry(); + + $manager = new Manager($compiler, $this->file, $logger, $factory); + $this->assertSame($cache, $manager->factory('custom-type', $name, $values)); + $this->assertSame($cache, $manager->factory('custom-type', $name, $values)); + $this->assertSame($cache, $manager->factory('custom-type', $name, $values)); + $this->assertSame($cache, $manager->factory('custom-type', $name, $values)); + } + + public function testNoCompilationIfNoChange() + { + file_put_contents($this->file, $this->compiler->compile(array("custom-type" => "array"))); + + $compiler = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration\Compiler') + ->disableOriginalConstructor() + ->getMock(); + $logger = $this->getMockBuilder('Monolog\Logger') + ->disableOriginalConstructor() + ->getMock(); + $factory = $this->getMockBuilder('Alchemy\Phrasea\Cache\Factory') + ->disableOriginalConstructor() + ->getMock(); + + $compiler->expects($this->never()) + ->method('compile'); + + $cache = $this->getMock('Alchemy\Phrasea\Cache\Cache'); + + $name = 'array'; + $values = array('option', 'value'); + + $factory->expects($this->once()) + ->method('create') + ->with($name, $values) + ->will($this->returnValue($cache)); + + $manager = new Manager($compiler, $this->file, $logger, $factory); + $this->assertSame($cache, $manager->factory('custom-type', $name, $values)); + } + + public function testNoCompilationIfNoChangeWithMultiple() + { + file_put_contents($this->file, $this->compiler->compile(array( + "custom-type" => "array", + "another-type" => "array", + "yet-another-type" => "array", + ))); + + $compiler = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration\Compiler') + ->disableOriginalConstructor() + ->getMock(); + $logger = $this->getMockBuilder('Monolog\Logger') + ->disableOriginalConstructor() + ->getMock(); + $factory = $this->getMockBuilder('Alchemy\Phrasea\Cache\Factory') + ->disableOriginalConstructor() + ->getMock(); + + $compiler->expects($this->never()) + ->method('compile'); + + $cache = $this->getMock('Alchemy\Phrasea\Cache\Cache'); + + $name = 'array'; + $values = array('option', 'value'); + + $factory->expects($this->exactly(3)) + ->method('create') + ->with($name, $values) + ->will($this->returnValue($cache)); + + $manager = new Manager($compiler, $this->file, $logger, $factory); + $this->assertSame($cache, $manager->factory('custom-type', $name, $values)); + $this->assertSame($cache, $manager->factory('another-type', $name, $values)); + $this->assertSame($cache, $manager->factory('yet-another-type', $name, $values)); + $this->assertSame($cache, $manager->factory('custom-type', $name, $values)); + $this->assertSame($cache, $manager->factory('another-type', $name, $values)); + $this->assertSame($cache, $manager->factory('yet-another-type', $name, $values)); + $this->assertSame($cache, $manager->factory('custom-type', $name, $values)); + $this->assertSame($cache, $manager->factory('another-type', $name, $values)); + $this->assertSame($cache, $manager->factory('yet-another-type', $name, $values)); + } + + public function testUnknownCacheReturnsArrayCacheAndLogs() + { + file_put_contents($this->file, $this->compiler->compile(array( + "custom-type" => "unknown", + ))); + + $compiler = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration\Compiler') + ->disableOriginalConstructor() + ->getMock(); + $logger = $this->getMockBuilder('Monolog\Logger') + ->disableOriginalConstructor() + ->getMock(); + $factory = $this->getMockBuilder('Alchemy\Phrasea\Cache\Factory') + ->disableOriginalConstructor() + ->getMock(); + + $compiler->expects($this->never()) + ->method('compile'); + + $logger->expects($this->once()) + ->method('error'); + + $cache = $this->getMock('Alchemy\Phrasea\Cache\Cache'); + + $name = 'unknown'; + $values = array('option', 'value'); + + $factory->expects($this->at(0)) + ->method('create') + ->with($name, $values) + ->will($this->throwException(new RuntimeException('Unknown cache type'))); + + $factory->expects($this->at(1)) + ->method('create') + ->with('array', array()) + ->will($this->returnValue($cache)); + + $manager = new Manager($compiler, $this->file, $logger, $factory); + $this->assertSame($cache, $manager->factory('custom-type', $name, $values)); + } +} diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/MustacheLoaderTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/MustacheLoaderTest.php index 907f409c98..deb6ca4543 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/MustacheLoaderTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/MustacheLoaderTest.php @@ -15,7 +15,7 @@ class MustacheLoaderTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testRouteSlashWrongUrl() { - self::$DI['client']->request('GET', '/prod/MustacheLoader/', array('template' => '/../../../../config/config.yml')); + self::$DI['client']->request('GET', '/prod/MustacheLoader/', array('template' => '/../../../../config/configuration.yml')); $this->assertBadResponse(self::$DI['client']->getResponse()); } diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/UploadTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/UploadTest.php index 7f90130732..11b2f42056 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/UploadTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/UploadTest.php @@ -100,7 +100,7 @@ class UploadTest extends \PhraseanetWebTestCaseAuthenticatedAbstract if ($datas['element'] == 'record') { $id = explode('_', $datas['id']); - $record = new \record_adapter($id[0], $id[1]); + $record = new \record_adapter(self::$DI['app'], $id[0], $id[1]); } } diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Utils/ConnectionTestTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Utils/ConnectionTestTest.php index 00ddfcdc42..c7594c1b1f 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Utils/ConnectionTestTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Utils/ConnectionTestTest.php @@ -2,8 +2,6 @@ namespace Alchemy\Tests\Phrasea\Controller\Utils; -use Alchemy\Phrasea\Core\Configuration; - class ControllerConnectionTestTest extends \PhraseanetWebTestCaseAbstract { /** @@ -11,18 +9,14 @@ class ControllerConnectionTestTest extends \PhraseanetWebTestCaseAbstract */ public function testRouteMysql() { - $configuration = Configuration::build(); - - $chooseConnexion = $configuration->getPhraseanet()->get('database'); - - $connexion = $configuration->getConnexion($chooseConnexion); + $connexion = self::$DI['app']['phraseanet.configuration']['main']['database']; $params = array( - "hostname" => $connexion->get('host'), - "port" => $connexion->get('port'), - "user" => $connexion->get('user'), - "password" => $connexion->get('password'), - "dbname" => $connexion->get('dbname') + "hostname" => $connexion['host'], + "port" => $connexion['port'], + "user" => $connexion['user'], + "password" => $connexion['password'], + "dbname" => $connexion['dbname'], ); self::$DI['client']->request("GET", "/admin/tests/connection/mysql/", $params); @@ -32,18 +26,14 @@ class ControllerConnectionTestTest extends \PhraseanetWebTestCaseAbstract public function testRouteMysqlFailed() { - $configuration = Configuration::build(); - - $chooseConnexion = $configuration->getPhraseanet()->get('database'); - - $connexion = $configuration->getConnexion($chooseConnexion); + $connexion = self::$DI['app']['phraseanet.configuration']['main']['database']; $params = array( - "hostname" => $connexion->get('host'), - "port" => $connexion->get('port'), - "user" => $connexion->get('user'), + "hostname" => $connexion['host'], + "port" => $connexion['port'], + "user" => $connexion['user'], "password" => "fakepassword", - "dbname" => $connexion->get('dbname') + "dbname" => $connexion['dbname'], ); self::$DI['client']->request("GET", "/admin/tests/connection/mysql/", $params); @@ -62,17 +52,13 @@ class ControllerConnectionTestTest extends \PhraseanetWebTestCaseAbstract public function testRouteMysqlDbFailed() { - $configuration = Configuration::build(); - - $chooseConnexion = $configuration->getPhraseanet()->get('database'); - - $connexion = $configuration->getConnexion($chooseConnexion); + $connexion = self::$DI['app']['phraseanet.configuration']['main']['database']; $params = array( - "hostname" => $connexion->get('host'), - "port" => $connexion->get('port'), - "user" => $connexion->get('user'), - "password" => $connexion->get('password'), + "hostname" => $connexion['host'], + "port" => $connexion['port'], + "user" => $connexion['user'], + "password" => $connexion['password'], "dbname" => "fake-DTABASE-name" ); diff --git a/tests/Alchemy/Tests/Phrasea/Core/Configuration/CompilerTest.php b/tests/Alchemy/Tests/Phrasea/Core/Configuration/CompilerTest.php new file mode 100644 index 0000000000..d937845ea2 --- /dev/null +++ b/tests/Alchemy/Tests/Phrasea/Core/Configuration/CompilerTest.php @@ -0,0 +1,54 @@ +compile($data); + $this->assertInternalType("string", $compiled); + $this->assertSame(0, strpos($compiled, "'.$compiled); + + $this->assertSame($data, $result); + } + + public function testCompileWithObject() + { + $compiler = new Compiler(); + + $class = new \stdClass(); + $class->key = 'value'; + + $data = array( + 'key' => $class, + 'key2' => 'boum', + ); + + $compiled = $compiler->compile($data); + $this->assertInternalType("string", $compiled); + $this->assertSame(0, strpos($compiled, "'.$compiled); + + $this->assertSame(array('key' => array('key' => 'value'), 'key2' => 'boum'), $result); + } + + public function provideDataToCompile() + { + return array( + array(array()), + array(array('key' => array('value1', 'value2', 'booleantrue' => true, 'booleanfalse' => false), array('gizmo'))), + array(array(array(array()))), + array(array('key' => 'value', "associativeint" => 12345, 34567)), + ); + } +} + diff --git a/tests/Alchemy/Tests/Phrasea/Core/Configuration/ConfigurationTest.php b/tests/Alchemy/Tests/Phrasea/Core/Configuration/ConfigurationTest.php new file mode 100644 index 0000000000..44f2db492b --- /dev/null +++ b/tests/Alchemy/Tests/Phrasea/Core/Configuration/ConfigurationTest.php @@ -0,0 +1,316 @@ +compiled = __DIR__ . '/Fixtures/configuration-compiled.php'; + $this->clean(); + copy(__DIR__ . '/..' . Configuration::CONFIG_REF, __DIR__ . '/Fixtures/configuration.yml'); + } + + public function tearDown() + { + $this->clean(); + parent::tearDown(); + } + + private function clean() + { + if (is_file($this->compiled)) { + unlink($this->compiled); + } + } + + /** + * @expectedException Alchemy\Phrasea\Exception\RuntimeException + */ + public function testGetConfigInvalidConfig() + { + $config = __DIR__ . '/Fixtures/configuration-unknown.yml'; + $compiled = $this->compiled; + + $yaml = new Yaml(); + $compiler = new Compiler(); + + $conf = new Configuration($yaml, $compiler, $config, $compiled, false); + $conf->getConfig(); + } + + public function testInitialize() + { + $configFile = __DIR__ . '/Fixtures/configuration-unknown.yml'; + + if (is_file($configFile)) { + unlink($configFile); + } + + $compiled = $this->compiled; + + $yaml = new Yaml(); + $compiler = new Compiler(); + + $conf = new Configuration($yaml, $compiler, $configFile, $compiled, false); + $config = $conf->initialize(); + + $this->assertArrayHasKey('main', $config); + $this->assertFileExists($compiled); + $this->assertFileExists($configFile); + + unlink($configFile); + } + + /** + * @expectedException Alchemy\Phrasea\Exception\RuntimeException + */ + public function testInitializeWrongPath() + { + $configFile = __DIR__ . '/Fixtures/configuration.yml'; + $compiled = __DIR__ . '/path/to/unknwon/folder/file.php'; + + $yaml = new Yaml(); + $compiler = new Compiler(); + + $conf = new Configuration($yaml, $compiler, $configFile, $compiled, false); + $conf->initialize(); + } + + public function testArrayAccess() + { + $config = __DIR__ . '/Fixtures/configuration.yml'; + $compiled = $this->compiled; + + $compiler = new Compiler(); + $yaml = new Yaml(); + + $conf = new Configuration($yaml, $compiler, $config, $compiled, false); + $this->assertEquals('127.0.0.1', $conf['main']['database']['host']); + + $conf['extra-key'] = 'extra-value'; + $this->assertEquals('extra-value', $conf['extra-key']); + + $updated = $yaml->parse($config); + $this->assertEquals('extra-value', $updated['extra-key']); + + $this->assertTrue(isset($conf['extra-key'])); + unset($conf['extra-key']); + $this->assertFalse(isset($conf['extra-key'])); + + $updated = $yaml->parse($config); + $this->assertFalse(isset($updated['extra-key'])); + } + + public function testDelete() + { + $config = __DIR__ . '/Fixtures/configuration.yml'; + $compiled = $this->compiled; + + $yaml = new Yaml(); + $compiler = new Compiler(); + + $conf = new Configuration($yaml, $compiler, $config, $compiled, false); + $conf->initialize(); + $conf->delete(); + $this->assertFileNotExists($compiled); + } + + public function testIsSetup() + { + $config = __DIR__ . '/Fixtures/configuration-setup.yml'; + $compiled = $this->compiled; + + @unlink($config); + + $compiler = new Compiler(); + $yaml = new Yaml(); + + $conf = new Configuration($yaml, $compiler, $config, $compiled, false); + $this->assertFalse($conf->isSetup()); + $conf->initialize(); + $this->assertTrue($conf->isSetup()); + } + + public function testSetdefault() + { + $configFile = __DIR__ . '/Fixtures/configuration.yml'; + $compiled = $this->compiled; + + $compiler = new Compiler(); + $yaml = new Yaml(); + + $conf = new Configuration($yaml, $compiler, $configFile, $compiled, false); + $conf->initialize(); + $config = $conf->getConfig(); + unset($config['main']); + $conf->setConfig($config); + + $updated = $yaml->parse($configFile); + $this->assertFalse(isset($updated['main'])); + + $conf->setDefault('main'); + + $updated = $yaml->parse($configFile); + $this->assertTrue(isset($updated['main'])); + } + + public function testSetdefaultRecursive() + { + $configFile = __DIR__ . '/Fixtures/configuration.yml'; + $compiled = $this->compiled; + + $compiler = new Compiler(); + $yaml = new Yaml(); + + $conf = new Configuration($yaml, $compiler, $configFile, $compiled, false); + $conf->initialize(); + $config = $conf->getConfig(); + unset($config['main']['cache']); + $conf->setConfig($config); + + $updated = $yaml->parse($configFile); + $this->assertFalse(isset($updated['main']['cache'])); + + $conf->setDefault('main', 'cache'); + + $updated = $yaml->parse($configFile); + $this->assertTrue(isset($updated['main']['cache'])); + } + + /** + * @expectedException Alchemy\Phrasea\Exception\InvalidArgumentException + */ + public function testSetdefaultInvalidKey() + { + $configFile = __DIR__ . '/Fixtures/configuration.yml'; + $compiled = $this->compiled; + + $compiler = new Compiler(); + $yaml = new Yaml(); + + $conf = new Configuration($yaml, $compiler, $configFile, $compiled, false); + $conf->setDefault('unexistant key'); + } + + public function testGetConfig() + { + $configFile = __DIR__ . '/Fixtures/configuration.yml'; + $compiled = $this->compiled; + + $compiler = new Compiler(); + $yaml = new Yaml(); + + $conf = new Configuration($yaml, $compiler, $configFile, $compiled, false); + $conf->initialize(); + + $updated = $yaml->parse(file_get_contents($configFile)); + $this->assertEquals($updated, $conf->getConfig()); + } + + public function testSetConfig() + { + $configFile = __DIR__ . '/Fixtures/configuration.yml'; + $compiled = $this->compiled; + + $compiler = new Compiler(); + $yaml = new Yaml(); + + $conf = new Configuration($yaml, $compiler, $configFile, $compiled, false); + $conf->setConfig(array('main' => 'boule')); + + $updated = $yaml->parse(file_get_contents($configFile)); + $this->assertEquals(array('main' => 'boule'), $conf->getConfig()); + } + + public function testCompilNever() + { + $configFile = __DIR__ . '/Fixtures/configuration.yml'; + $compiled = $this->compiled; + + $yaml = new Yaml(); + $compiler = new Compiler(); + file_put_contents($this->compiled, $compiler->compile($yaml->parse($configFile))); + + $compiler = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration\Compiler') + ->disableOriginalConstructor() + ->getMock(); + $compiler->expects($this->never()) + ->method('compile'); + + $yaml = $this->getMockBuilder('Symfony\Component\Yaml\Yaml') + ->disableOriginalConstructor() + ->getMock(); + $yaml::staticExpects($this->never()) + ->method('parse'); + + $conf = new Configuration($yaml, $compiler, $configFile, $compiled, false); + $conf->getConfig(); + $conf->getConfig(); + $conf->getConfig(); + $conf['main']; + $conf['main']; + $conf['main']; + } + + public function testCompilInDebugMode() + { + $configFile = __DIR__ . '/Fixtures/configuration.yml'; + $compiled = $this->compiled; + + $yaml = new Yaml(); + $compiler = new Compiler(); + file_put_contents($this->compiled, $compiler->compile($yaml->parse($configFile))); + + // compilation is older than config + touch($this->compiled, time()-2); + touch($configFile, time()-1); + clearstatcache(); + + $compiler = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration\Compiler') + ->disableOriginalConstructor() + ->getMock(); + $compiler->expects($this->once()) + ->method('compile') + ->with(array('main' => 'tiptop')) + ->will($this->returnValue(' "tiptop");')); + + $yaml = $this->getMockBuilder('Symfony\Component\Yaml\Yaml') + ->disableOriginalConstructor() + ->getMock(); + $yaml::staticExpects($this->once()) + ->method('parse') + ->will($this->returnValue(array('main' => 'tiptop'))); + + $conf = new Configuration($yaml, $compiler, $configFile, $compiled, true); + $this->assertSame(array('main' => 'tiptop'), $conf->getConfig()); + $this->assertSame(array('main' => 'tiptop'), $conf->getConfig()); + $this->assertSame(array('main' => 'tiptop'), $conf->getConfig()); + $this->assertSame('tiptop', $conf['main']); + $this->assertSame('tiptop', $conf['main']); + $this->assertSame('tiptop', $conf['main']); + } + + public function testGetTestConnectionConf() + { + $configFile = __DIR__ . '/Fixtures/configuration.yml'; + $compiled = $this->compiled; + + $yaml = new Yaml(); + $compiler = new Compiler(); + + $conf = new Configuration($yaml, $compiler, $configFile, $compiled, true); + $data = $conf->getTestConnectionParameters(); + + $this->assertArrayHasKey('driver', $data); + $this->assertArrayHasKey('path', $data); + $this->assertArrayHasKey('charset', $data); + } +} diff --git a/tests/Alchemy/Tests/Phrasea/Core/Configuration/Fixtures/configuration-setup.yml b/tests/Alchemy/Tests/Phrasea/Core/Configuration/Fixtures/configuration-setup.yml new file mode 100644 index 0000000000..a2fc7a07b3 --- /dev/null +++ b/tests/Alchemy/Tests/Phrasea/Core/Configuration/Fixtures/configuration-setup.yml @@ -0,0 +1,113 @@ +main: + servername: 'http://local.phrasea/' + maintenance: false + database: + host: 127.0.0.1 + port: '3306' + user: root + password: '' + dbname: ab_test + driver: pdo_mysql + charset: UTF8 + database-test: + driver: pdo_sqlite + path: '/tmp/db.sqlite' + charset: UTF8 + api-timers: true + cache: + type: MemcacheCache + options: + host: localhost + port: 11211 + opcodecache: + type: ArrayCache + options: [] + search-engine: + type: Alchemy\Phrasea\SearchEngine\Phrasea\PhraseaEngine + options: [] + task-manager: + options: null +binaries: [] +border-manager: + enabled: true + checkers: + - + type: Checker\Sha256 + enabled: true + - + type: Checker\UUID + enabled: true + - + type: Checker\Colorspace + enabled: false + options: + colorspaces: [cmyk, grayscale, rgb] + - + type: Checker\Dimension + enabled: false + options: + width: 80 + height: 160 + - + type: Checker\Extension + enabled: false + options: + extensions: [jpg, jpeg, bmp, tif, gif, png, pdf, doc, odt, mpg, mpeg, mov, avi, xls, flv, mp3, mp2] + - + type: Checker\Filename + enabled: false + options: + sensitive: true + - + type: Checker\MediaType + enabled: false + options: + mediatypes: [Audio, Document, Flash, Image, Video] +authentication: + auto-create: + enabled: false + templates: { } + captcha: + enabled: true + trials-before-failure: 9 + providers: + facebook: + enabled: false + options: + app-id: '' + secret: '' + twitter: + enabled: false + options: + consumer-key: '' + consumer-secret: '' + google-plus: + enabled: false + options: + client-id: '' + client-secret: '' + github: + enabled: false + options: + client-id: '' + client-secret: '' + viadeo: + enabled: false + options: + client-id: '' + client-secret: '' + linkedin: + enabled: false + options: + client-id: '' + client-secret: '' +registration-fields: + - + name: company + required: true + - + name: firstname + required: true + - + name: geonameid + required: true \ No newline at end of file diff --git a/tests/Alchemy/Tests/Phrasea/Core/Configuration/Fixtures/configuration.yml b/tests/Alchemy/Tests/Phrasea/Core/Configuration/Fixtures/configuration.yml new file mode 100644 index 0000000000..a2fc7a07b3 --- /dev/null +++ b/tests/Alchemy/Tests/Phrasea/Core/Configuration/Fixtures/configuration.yml @@ -0,0 +1,113 @@ +main: + servername: 'http://local.phrasea/' + maintenance: false + database: + host: 127.0.0.1 + port: '3306' + user: root + password: '' + dbname: ab_test + driver: pdo_mysql + charset: UTF8 + database-test: + driver: pdo_sqlite + path: '/tmp/db.sqlite' + charset: UTF8 + api-timers: true + cache: + type: MemcacheCache + options: + host: localhost + port: 11211 + opcodecache: + type: ArrayCache + options: [] + search-engine: + type: Alchemy\Phrasea\SearchEngine\Phrasea\PhraseaEngine + options: [] + task-manager: + options: null +binaries: [] +border-manager: + enabled: true + checkers: + - + type: Checker\Sha256 + enabled: true + - + type: Checker\UUID + enabled: true + - + type: Checker\Colorspace + enabled: false + options: + colorspaces: [cmyk, grayscale, rgb] + - + type: Checker\Dimension + enabled: false + options: + width: 80 + height: 160 + - + type: Checker\Extension + enabled: false + options: + extensions: [jpg, jpeg, bmp, tif, gif, png, pdf, doc, odt, mpg, mpeg, mov, avi, xls, flv, mp3, mp2] + - + type: Checker\Filename + enabled: false + options: + sensitive: true + - + type: Checker\MediaType + enabled: false + options: + mediatypes: [Audio, Document, Flash, Image, Video] +authentication: + auto-create: + enabled: false + templates: { } + captcha: + enabled: true + trials-before-failure: 9 + providers: + facebook: + enabled: false + options: + app-id: '' + secret: '' + twitter: + enabled: false + options: + consumer-key: '' + consumer-secret: '' + google-plus: + enabled: false + options: + client-id: '' + client-secret: '' + github: + enabled: false + options: + client-id: '' + client-secret: '' + viadeo: + enabled: false + options: + client-id: '' + client-secret: '' + linkedin: + enabled: false + options: + client-id: '' + client-secret: '' +registration-fields: + - + name: company + required: true + - + name: firstname + required: true + - + name: geonameid + required: true \ No newline at end of file diff --git a/tests/Alchemy/Tests/Phrasea/Core/ConfigurationTest.php b/tests/Alchemy/Tests/Phrasea/Core/ConfigurationTest.php deleted file mode 100644 index 36eb937ec9..0000000000 --- a/tests/Alchemy/Tests/Phrasea/Core/ConfigurationTest.php +++ /dev/null @@ -1,702 +0,0 @@ -getSetupedSpecifications(array('dev' => array())); - - $configuration = Configuration::build($specifications, 'dev'); - - $this->assertEquals('dev', $configuration->getEnvironnement()); - $this->assertEquals($specifications, $configuration->getSpecifications()); - } - - /** - * @test - * @covers Alchemy\Phrasea\Core\Configuration::build - */ - public function buildShouldFailIfTheRequiredEnvironmentDoesNotExist() - { - $specifications = $this->getSetupedSpecifications(array('prod' => array())); - - try { - Configuration::build($specifications, 'dev'); - $this->fail('Should have raised an exception'); - } catch (InvalidArgumentException $e) { - - } - } - - /** - * @test - * @covers Alchemy\Phrasea\Core\Configuration::build - */ - public function environmentShouldBeNullIsTheSpecsAreNotSetup() - { - $specifications = $this->getNotSetupedSpecifications(); - $configuration = Configuration::build($specifications, 'dev'); - - $this->assertNull($configuration->getEnvironnement()); - $this->assertEquals($specifications, $configuration->getSpecifications()); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::get - */ - public function testGet() - { - $specifications = $this->getSetupedSpecifications(array('dev' => array('pif' => 'pouf'))); - $configuration = Configuration::build($specifications, 'dev'); - - $this->assertEquals('pouf', $configuration->get('pif')); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::get - */ - public function testGetOnNonExistentParameterShouldFail() - { - $specifications = $this->getSetupedSpecifications(array('dev' => array('pif' => 'pouf'))); - $configuration = Configuration::build($specifications, 'dev'); - - try { - $configuration->get('paf'); - $this->fail('Should have raised an exception'); - } catch (ParameterNotFoundException $e) { - - } - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::has - */ - public function testHas() - { - $specifications = $this->getSetupedSpecifications(array('dev' => array('pif' => 'pouf'))); - $configuration = Configuration::build($specifications, 'dev'); - - $this->assertTrue($configuration->has('pif')); - $this->assertFalse($configuration->has('paf')); - } - - /** - * @test - * @covers Alchemy\Phrasea\Core\Configuration::build - */ - public function defaultEnvironmentShouldBeTheOneInTheEnvironmentKey() - { - $specifications = $this->getSetupedSpecifications(array('environment' => 'dave', 'dave' => array('pif' => 'pouf'))); - $configuration = Configuration::build($specifications); - - $this->assertEquals('dave', $configuration->getEnvironnement()); - $this->assertEquals($specifications, $configuration->getSpecifications()); - } - - /** - * @test - * @covers Alchemy\Phrasea\Core\Configuration::build - */ - public function anErrorShouldBeThrownIfNoEnvironmentProvided() - { - $specifications = $this->getSetupedSpecifications(array('dave' => array('pif' => 'pouf'))); - - try { - Configuration::build($specifications); - $this->fail('Should have raised an exception'); - } catch (RuntimeException $e) { - - } - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::setEnvironnement - * @covers Alchemy\Phrasea\Core\Configuration::getEnvironnement - */ - public function testSetEnvironnementShouldSetTheEnvironment() - { - $specifications = $this->getSetupedSpecifications(array('dev' => array('pif' => 'pouf'), 'prod' => array('bim' => 'bame'))); - $configuration = Configuration::build($specifications, 'dev'); - - $this->assertEquals('dev', $configuration->getEnvironnement()); - $this->assertTrue($configuration->has('pif')); - $this->assertFalse($configuration->has('bim')); - - $configuration->setEnvironnement('prod'); - $this->assertEquals('prod', $configuration->getEnvironnement()); - $this->assertFalse($configuration->has('pif')); - $this->assertTrue($configuration->has('bim')); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::setEnvironnement - * @covers Alchemy\Phrasea\Core\Configuration::getEnvironnement - */ - public function testSetEnvironnementShouldThrowAnExceptionIfEnvironmentDoesNotExists() - { - $specifications = $this->getSetupedSpecifications(array('dev' => array('pif' => 'pouf'), 'prod' => array('bim' => 'bame'))); - $configuration = Configuration::build($specifications, 'dev'); - - try { - $configuration->setEnvironnement('test'); - $this->fail('Should have raised an exception'); - } catch (InvalidArgumentException $e) { - - } - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::getEnvironnement - * @covers Alchemy\Phrasea\Core\Configuration::setEnvironnement - */ - public function testSetEnvironnementWhenSetupNotReadyShouldAlwaysWork() - { - $specifications = $this->getNotSetupedSpecifications(); - $configuration = Configuration::build($specifications, 'dev'); - - $configuration->setEnvironnement('prout'); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::isDebug - */ - public function testIsDebugIsFalseWhileSetup() - { - $specifications = $this->getNotSetupedSpecifications(); - $configuration = Configuration::build($specifications); - - $this->assertFalse($configuration->isDebug()); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::isDebug - */ - public function testIsDebugIsFalseByDefault() - { - $specifications = $this->getSetupedSpecifications(array('dev' => array())); - $configuration = Configuration::build($specifications, 'dev'); - - $this->assertFalse($configuration->isDebug()); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::isDebug - */ - public function testIsDebug() - { - $specifications = $this->getSetupedSpecifications(array('dev' => array('phraseanet' => array('debug' => true)))); - $configuration = Configuration::build($specifications, 'dev'); - - $this->assertTrue($configuration->isDebug()); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::isMaintained - */ - public function testIsMaintainedIsFalseWhileSetup() - { - $specifications = $this->getNotSetupedSpecifications(); - $configuration = Configuration::build($specifications); - - $this->assertFalse($configuration->isMaintained()); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::isMaintained - */ - public function testIsMaintainedIsFalseByDefault() - { - $specifications = $this->getSetupedSpecifications(array('dev' => array())); - $configuration = Configuration::build($specifications, 'dev'); - - $this->assertFalse($configuration->isMaintained()); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::isMaintained - */ - public function testIsMaintained() - { - $specifications = $this->getSetupedSpecifications(array('dev' => array('phraseanet' => array('maintenance' => true)))); - $configuration = Configuration::build($specifications, 'dev'); - - $this->assertTrue($configuration->isMaintained()); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::isDisplayingErrors - */ - public function testIsDisplayingErrorsIsFalseWhileSetup() - { - $specifications = $this->getNotSetupedSpecifications(); - $configuration = Configuration::build($specifications); - - $this->assertFalse($configuration->isDisplayingErrors()); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::isDisplayingErrors - */ - public function testIsDisplayingErrorsIsFalseByDefault() - { - $specifications = $this->getSetupedSpecifications(array('dev' => array())); - $configuration = Configuration::build($specifications, 'dev'); - - $this->assertFalse($configuration->isDisplayingErrors()); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::isDisplayingErrors - */ - public function testIsDisplayingErrors() - { - $specifications = $this->getSetupedSpecifications(array('dev' => array('phraseanet' => array('display_errors' => true)))); - $configuration = Configuration::build($specifications, 'dev'); - - $this->assertTrue($configuration->isDisplayingErrors()); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::getPhraseanet - */ - public function testGetPhraseanet() - { - $phraseanet = array('display_errors' => true); - - $specifications = $this->getSetupedSpecifications(array('dev' => array('phraseanet' => $phraseanet))); - $configuration = Configuration::build($specifications, 'dev'); - - $this->assertInstanceOf('Symfony\Component\DependencyInjection\ParameterBag\ParameterBag', $configuration->getPhraseanet()); - $this->assertEquals($phraseanet, $configuration->getPhraseanet()->all()); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::initialize - */ - public function testInitialize() - { - $specifications = $this->getNotSetupedSpecifications(); - $specifications->expects($this->once()) - ->method('initialize'); - - $configuration = Configuration::build($specifications); - $configuration->initialize(); - - $this->assertEquals('prod', $configuration->getEnvironnement()); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::delete - */ - public function testDelete() - { - $specifications = $this->getSetupedSpecifications(array('prod' => array())); - $specifications->expects($this->once()) - ->method('delete'); - - $configuration = Configuration::build($specifications, 'prod'); - $configuration->delete(); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::setConfigurations - */ - public function testSetConfigurations() - { - $conf = array('prod' => array('bim' => 'boum')); - - $specifications = $this->getSetupedSpecifications(array('prod' => array())); - $specifications->expects($this->once()) - ->method('setConfigurations') - ->with($this->equalTo($conf)); - - $configuration = Configuration::build($specifications, 'prod'); - $configuration->setConfigurations($conf); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::setServices - */ - public function testSetServices() - { - $services = array('Template' => array()); - - $specifications = $this->getSetupedSpecifications(array('prod' => array())); - $specifications->expects($this->once()) - ->method('setServices') - ->with($this->equalTo($services)); - - $configuration = Configuration::build($specifications, 'prod'); - $configuration->setServices($services); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::resetServices - */ - public function testResetAllServices() - { - $specifications = $this->getSetupedSpecifications(array('prod' => array())); - $specifications->expects($this->once()) - ->method('resetServices') - ->with($this->equalTo(null)); - - $configuration = Configuration::build($specifications, 'prod'); - $configuration->resetServices(); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::resetServices - */ - public function testResetByName() - { - $name = 'coool-service'; - - $specifications = $this->getSetupedSpecifications(array('prod' => array())); - $specifications->expects($this->once()) - ->method('resetServices') - ->with($this->equalTo($name)); - - $configuration = Configuration::build($specifications, 'prod'); - $configuration->resetServices($name); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::setBinaries - */ - public function testSetBinaries() - { - $binaries = array('binarie' => array('php' => '/usr/local/bin/php')); - - $specifications = $this->getSetupedSpecifications(array('prod' => array())); - $specifications->expects($this->once()) - ->method('setBinaries') - ->with($this->equalTo($binaries)); - - $configuration = Configuration::build($specifications, 'prod'); - $configuration->setBinaries($binaries); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::setConnexions - */ - public function testSetConnexions() - { - $connexions = array('main' => array('path' => '/usr/local/db')); - - $specifications = $this->getSetupedSpecifications(array('prod' => array())); - $specifications->expects($this->once()) - ->method('setConnexions') - ->with($this->equalTo($connexions)); - - $configuration = Configuration::build($specifications, 'prod'); - $configuration->setConnexions($connexions); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::getConfigurations - */ - public function testGetConfigurations() - { - $specifications = $this->getNotSetupedSpecifications(); - $specifications->expects($this->once()) - ->method('getConfigurations'); - - $configuration = Configuration::build($specifications, 'prod'); - $configuration->getConfigurations(); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::getServices - */ - public function testGetServices() - { - $specifications = $this->getSetupedSpecifications(array('prod' => array())); - $specifications->expects($this->once()) - ->method('getServices'); - - $configuration = Configuration::build($specifications, 'prod'); - $configuration->getServices(); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::getBinaries - */ - public function testGetBinaries() - { - $specifications = $this->getSetupedSpecifications(array('prod' => array())); - $specifications->expects($this->once()) - ->method('getBinaries'); - - $configuration = Configuration::build($specifications, 'prod'); - $configuration->getBinaries(); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::getConnexions - */ - public function testGetConnexions() - { - $specifications = $this->getSetupedSpecifications(array('prod' => array())); - $specifications->expects($this->once()) - ->method('getConnexions'); - - $configuration = Configuration::build($specifications, 'prod'); - $configuration->getConnexions(); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::getConnexion - */ - public function testGetConnexion() - { - $testConnexion = array('path' => '/tmp/db'); - - $specifications = $this->getSetupedSpecifications(array('prod' => array())); - $specifications->expects($this->once()) - ->method('getConnexions') - ->will($this->returnValue(array('test' => $testConnexion))); - - $configuration = Configuration::build($specifications, 'prod'); - - $conn = $configuration->getConnexion('test'); - - $this->assertInstanceOf('Symfony\Component\DependencyInjection\ParameterBag\ParameterBag', $conn); - $this->assertEquals($testConnexion, $conn->all()); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::getConnexion - */ - public function testGetConnexionThatDoesNotExist() - { - $testConnexion = array('path' => '/tmp/db'); - - $specifications = $this->getSetupedSpecifications(array('prod' => array())); - $specifications->expects($this->once()) - ->method('getConnexions') - ->will($this->returnValue(array('test' => $testConnexion))); - - $configuration = Configuration::build($specifications, 'prod'); - - try { - $configuration->getConnexion('not-exists'); - $this->fail('Should have raised an exception'); - } catch (InvalidArgumentException $e) { - - } - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::getTemplating - */ - public function testGetTemplating() - { - $specifications = $this->getSetupedSpecifications(array( - 'prod' => array('template_engine' => 'ObjectTwig') - )); - - $configuration = Configuration::build($specifications, 'prod'); - $this->assertEquals('TemplateEngine\\ObjectTwig', $configuration->getTemplating()); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::getCache - */ - public function testGetCache() - { - $specifications = $this->getSetupedSpecifications(array( - 'prod' => array('cache' => 'ObjectCache') - )); - - $configuration = Configuration::build($specifications, 'prod'); - $this->assertEquals('Cache\\ObjectCache', $configuration->getCache()); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::getOpcodeCache - */ - public function testGetOpcodeCache() - { - $specifications = $this->getSetupedSpecifications(array( - 'prod' => array('opcodecache' => 'ObjectOpcodeCache') - )); - - $configuration = Configuration::build($specifications, 'prod'); - $this->assertEquals('Cache\\ObjectOpcodeCache', $configuration->getOpcodeCache()); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::getOrm - */ - public function testGetOrm() - { - $specifications = $this->getSetupedSpecifications(array( - 'prod' => array('orm' => 'ObjectORM') - )); - - $configuration = Configuration::build($specifications, 'prod'); - $this->assertEquals('Orm\\ObjectORM', $configuration->getOrm()); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::getSearchEngine - */ - public function testGetSearchEngine() - { - $specifications = $this->getSetupedSpecifications(array( - 'prod' => array('search-engine' => 'ObjectPhrasea') - )); - - $configuration = Configuration::build($specifications, 'prod'); - $this->assertEquals('SearchEngine\\ObjectPhrasea', $configuration->getSearchEngine()); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::getBorder - */ - public function testGetBorder() - { - $specifications = $this->getSetupedSpecifications(array( - 'prod' => array('border-manager' => 'ObjectBorder') - )); - - $configuration = Configuration::build($specifications, 'prod'); - $this->assertEquals('Border\\ObjectBorder', $configuration->getBorder()); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::getTaskManager - */ - public function testGetTaskManager() - { - $specifications = $this->getSetupedSpecifications(array( - 'prod' => array('task-manager' => 'ObjectTask') - )); - - $configuration = Configuration::build($specifications, 'prod'); - $this->assertEquals('TaskManager\\ObjectTask', $configuration->getTaskManager()); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::getService - * @dataProvider provideServices - */ - public function testGetService($services, $name, $expected) - { - $specifications = $this->getSetupedSpecifications(array( - 'prod' => array('task-manager' => 'ObjectTask') - )); - - $specifications->expects($this->once()) - ->method('getServices') - ->will($this->returnValue($services)); - - $configuration = Configuration::build($specifications, 'prod'); - $service = $configuration->getService($name); - - $this->assertInstanceOf('Symfony\Component\DependencyInjection\ParameterBag\ParameterBag', $service); - $this->assertEquals($expected, $service->all()); - } - - /** - * @covers Alchemy\Phrasea\Core\Configuration::getService - * @dataProvider provideFailingServiceData - */ - public function testGetServiceFail($services, $name) - { - $specifications = $this->getSetupedSpecifications(array( - 'prod' => array('task-manager' => 'ObjectTask') - )); - - $specifications->expects($this->once()) - ->method('getServices') - ->will($this->returnValue($services)); - - $configuration = Configuration::build($specifications, 'prod'); - - try { - $configuration->getService($name); - $this->fail('Should have raised an exception'); - } catch (InvalidArgumentException $e) { - - } - } - - public function provideServices() - { - $services = array( - 'servicetld' => array( - 'sub' => array('data'), - 'anothersub' => array('datalevel1' => array( - 'datalevel2' => array('lowleveldata') - )), - ), - 'anothertop' => array('pif' => 'paf') - ); - - return array( - array($services, 'servicetld\\sub', array('data')), - array($services, 'servicetld\\anothersub\\datalevel1', array('datalevel2' => array('lowleveldata'))), - array($services, 'anothertop', array('pif' => 'paf')), - ); - } - - public function provideFailingServiceData() - { - $services = array( - 'servicetld' => array( - 'sub' => array('data'), - 'anothersub' => array('datalevel1' => array( - 'datalevel2' => array('lowleveldata') - )), - ), - 'anothertop' => array('pif' => 'paf') - ); - - return array( - array($services, 'servicetld\\sub\\data'), - array($services, 'servicetld\\data'), - array($services, 'servicetld\\anothersub\\datalevel2'), - array($services, 'anotherothertop'), - ); - } - - private function getNotSetupedSpecifications() - { - $specifications = $this->getMock('Alchemy\Phrasea\Core\Configuration\SpecificationInterface'); - - $specifications->expects($this->any()) - ->method('isSetup') - ->will($this->returnValue(false)); - - return $specifications; - } - - private function getSetupedSpecifications($configuration = array()) - { - $specifications = $this->getMock('Alchemy\Phrasea\Core\Configuration\SpecificationInterface'); - - $specifications->expects($this->any()) - ->method('isSetup') - ->will($this->returnValue(true)); - - if ($configuration) { - $specifications->expects($this->any()) - ->method('getConfigurations') - ->will($this->returnValue($configuration)); - } - - return $specifications; - } -} diff --git a/tests/Alchemy/Tests/Phrasea/Core/Provider/AuthenticationManagerServiceProviderTest.php b/tests/Alchemy/Tests/Phrasea/Core/Provider/AuthenticationManagerServiceProviderTest.php index a27c015269..140493f0b4 100644 --- a/tests/Alchemy/Tests/Phrasea/Core/Provider/AuthenticationManagerServiceProviderTest.php +++ b/tests/Alchemy/Tests/Phrasea/Core/Provider/AuthenticationManagerServiceProviderTest.php @@ -5,8 +5,8 @@ namespace Alchemy\Tests\Phrasea\Core\Provider; use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Core\Provider\TokensServiceProvider; use Alchemy\Phrasea\Core\Provider\AuthenticationManagerServiceProvider; +use Alchemy\Phrasea\Core\Provider\ConfigurationServiceProvider; use Silex\Application; -use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; /** * @covers Alchemy\Phrasea\Core\Provider\AuthenticationManagerServiceProvider @@ -19,7 +19,7 @@ class AuthenticationManagerServiceProvidertest extends ServiceProviderTestCase array( 'Alchemy\Phrasea\Core\Provider\AuthenticationManagerServiceProvider', 'authentication', - 'Alchemy\\Phrasea\\Authentication\\Authenticator' + 'Alchemy\\Phrasea\\Authentication\\Authenticator', ), array( 'Alchemy\Phrasea\Core\Provider\AuthenticationManagerServiceProvider', @@ -69,7 +69,7 @@ class AuthenticationManagerServiceProvidertest extends ServiceProviderTestCase array( 'Alchemy\Phrasea\Core\Provider\AuthenticationManagerServiceProvider', 'auth.native', - 'Alchemy\Phrasea\Authentication\Phrasea\FailureHandledNativeAuthentication' + 'Alchemy\Phrasea\Authentication\Phrasea\PasswordAuthenticationInterface' ), array( 'Alchemy\Phrasea\Core\Provider\AuthenticationManagerServiceProvider', @@ -84,15 +84,11 @@ class AuthenticationManagerServiceProvidertest extends ServiceProviderTestCase $app = new Application(); $app->register(new TokensServiceProvider()); $app->register(new AuthenticationManagerServiceProvider()); + $app->register(new ConfigurationServiceProvider()); - $app['phraseanet.configuration'] = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration') - ->disableOriginalConstructor() - ->getMock(); - - $app['phraseanet.configuration']->expects($this->once()) - ->method('get') - ->with('authentication') - ->will($this->returnValue(array('trials-before-failure' => 42))); + $app['phraseanet.configuration'] = $conf = $app['phraseanet.configuration']->getConfig(); + $conf['authentication']['captcha']['trials-before-failure'] = 42; + $app['phraseanet.configuration'] = $conf; $app['EM'] = $this->getMockBuilder('Doctrine\Orm\EntityManager') ->disableOriginalConstructor() @@ -108,36 +104,14 @@ class AuthenticationManagerServiceProvidertest extends ServiceProviderTestCase public function testFailureAccountCreator() { $app = new PhraseaApplication(); + $app->register(new ConfigurationServiceProvider()); - $conf = $app['phraseanet.configuration']; - - $app['phraseanet.configuration'] = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration') - ->disableOriginalConstructor() - ->getMock(); - - $app['phraseanet.configuration']->expects($this->any()) - ->method('get') - ->will($this->returnCallback(function ($key) use ($conf) { - if ($key === 'authentication') { - return array( - 'auto-create' => array( - 'enabled' => true, - 'templates' => array() - ) - ); - } else { - return $conf->get($key); - } - })); - $app['phraseanet.configuration']->expects($this->any()) - ->method('getPhraseanet') - ->will($this->returnValue(new ParameterBag($conf->get('phraseanet')))); - - $conn = $conf->getSpecifications()->getConnexions(); - - $app['phraseanet.configuration']->expects($this->any()) - ->method('getConnexion') - ->will($this->returnValue(new ParameterBag($conn['main_connexion']))); + $app['phraseanet.configuration'] = $conf = $app['phraseanet.configuration']->getConfig(); + $conf['authentication']['auto-create'] = array( + 'enabled' => true, + 'templates' => array(), + ); + $app['phraseanet.configuration'] = $conf; $app['authentication.providers.account-creator']; } @@ -146,6 +120,7 @@ class AuthenticationManagerServiceProvidertest extends ServiceProviderTestCase { $app = new Application(); $app->register(new AuthenticationManagerServiceProvider()); + $app->register(new ConfigurationServiceProvider()); $app['phraseanet.registry'] = $this->getMockBuilder('registry') ->disableOriginalConstructor() ->getMock(); @@ -162,14 +137,11 @@ class AuthenticationManagerServiceProvidertest extends ServiceProviderTestCase })); $app['phraseanet.appbox'] = self::$DI['app']['phraseanet.appbox']; - $app['phraseanet.configuration'] = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration') - ->disableOriginalConstructor() - ->getMock(); - - $app['phraseanet.configuration']->expects($this->any()) - ->method('get') - ->with('authentication') - ->will($this->returnValue(array('captcha' => array('enabled' => true)))); + $app['phraseanet.configuration'] = $conf = $app['phraseanet.configuration']->getConfig(); + $conf['authentication']['captcha'] = array( + 'enabled' => true, + ); + $app['phraseanet.configuration'] = $conf; $app['EM'] = $this->getMockBuilder('Doctrine\Orm\EntityManager') ->disableOriginalConstructor() @@ -185,6 +157,7 @@ class AuthenticationManagerServiceProvidertest extends ServiceProviderTestCase { $app = new Application(); $app->register(new AuthenticationManagerServiceProvider()); + $app->register(new ConfigurationServiceProvider()); $app['phraseanet.registry'] = $this->getMockBuilder('registry') ->disableOriginalConstructor() ->getMock(); @@ -201,14 +174,11 @@ class AuthenticationManagerServiceProvidertest extends ServiceProviderTestCase })); $app['phraseanet.appbox'] = self::$DI['app']['phraseanet.appbox']; - $app['phraseanet.configuration'] = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration') - ->disableOriginalConstructor() - ->getMock(); - - $app['phraseanet.configuration']->expects($this->any()) - ->method('get') - ->with('authentication') - ->will($this->returnValue(array('captcha' => array('enabled' => false)))); + $app['phraseanet.configuration'] = $conf = $app['phraseanet.configuration']->getConfig(); + $conf['authentication']['captcha'] = array( + 'enabled' => false, + ); + $app['phraseanet.configuration'] = $conf; $app['EM'] = $this->getMockBuilder('Doctrine\Orm\EntityManager') ->disableOriginalConstructor() @@ -230,39 +200,15 @@ class AuthenticationManagerServiceProvidertest extends ServiceProviderTestCase $template2 = \User_Adapter::create(self::$DI['app'], 'template' . $random->generatePassword(), $random->generatePassword(), null, false); $template2->set_template(self::$DI['user']); - $conf = $app['phraseanet.configuration']; - - $app['phraseanet.configuration'] = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration') - ->disableOriginalConstructor() - ->getMock(); - - $app['phraseanet.configuration']->expects($this->any()) - ->method('get') - ->will($this->returnCallback(function ($key) use ($template1, $template2, $conf) { - if ($key === 'authentication') { - return array( - 'auto-create' => array( - 'enabled' => true, - 'templates' => array( - $template1->get_id(), - $template2->get_login() - ) - ) - ); - } else { - return $conf->get($key); - } - })); - - $app['phraseanet.configuration']->expects($this->any()) - ->method('getPhraseanet') - ->will($this->returnValue(new ParameterBag($conf->get('phraseanet')))); - - $conn = $conf->getSpecifications()->getConnexions(); - - $app['phraseanet.configuration']->expects($this->any()) - ->method('getConnexion') - ->will($this->returnValue(new ParameterBag($conn['main_connexion']))); + $app['phraseanet.configuration'] = $conf = $app['phraseanet.configuration']->getConfig(); + $conf['authentication']['auto-create'] = array( + 'enabled' => true, + 'templates' => array( + $template1->get_id(), + $template2->get_login() + ) + ); + $app['phraseanet.configuration'] = $conf; $this->assertEquals(array($template1, $template2), $app['authentication.providers.account-creator']->getTemplates()); diff --git a/tests/Alchemy/Tests/Phrasea/Core/Provider/ConfigurationServiceProviderTest.php b/tests/Alchemy/Tests/Phrasea/Core/Provider/ConfigurationServiceProviderTest.php index 8d7bbfb39a..078ca83f9e 100644 --- a/tests/Alchemy/Tests/Phrasea/Core/Provider/ConfigurationServiceProviderTest.php +++ b/tests/Alchemy/Tests/Phrasea/Core/Provider/ConfigurationServiceProviderTest.php @@ -10,7 +10,11 @@ class ConfigurationServiceProvidertest extends ServiceProviderTestCase public function provideServiceDescription() { return array( - array('Alchemy\Phrasea\Core\Provider\ConfigurationServiceProvider', 'phraseanet.configuration', 'Alchemy\\Phrasea\\Core\\Configuration'), + array( + 'Alchemy\Phrasea\Core\Provider\ConfigurationServiceProvider', + 'phraseanet.configuration', + 'Alchemy\\Phrasea\\Core\\Configuration\\Configuration' + ), ); } } diff --git a/tests/Alchemy/Tests/Phrasea/Core/Provider/RegistrationServiceProviderTest.php b/tests/Alchemy/Tests/Phrasea/Core/Provider/RegistrationServiceProviderTest.php index 65b60fe311..9ae4b47101 100644 --- a/tests/Alchemy/Tests/Phrasea/Core/Provider/RegistrationServiceProviderTest.php +++ b/tests/Alchemy/Tests/Phrasea/Core/Provider/RegistrationServiceProviderTest.php @@ -13,18 +13,9 @@ class RegistrationServiceProvidertest extends \PhraseanetPHPUnitAbstract { self::$DI['app']->register(new RegistrationServiceProvider()); - self::$DI['app']['phraseanet.configuration'] = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration') - ->disableOriginalConstructor() - ->getMock(); - - self::$DI['app']['phraseanet.configuration']->expects($this->once()) - ->method('has') - ->with('registration-fields') - ->will($this->returnValue(true)); - self::$DI['app']['phraseanet.configuration']->expects($this->once()) - ->method('get') - ->with('registration-fields') - ->will($this->returnValue(array('plop'))); + $conf = self::$DI['app']['phraseanet.configuration']->getConfig(); + $conf['registration-fields'] = array('plop'); + self::$DI['app']['phraseanet.configuration'] = $conf; $this->assertEquals(array('plop'), self::$DI['app']['registration.fields']); $this->assertEquals(array('plop'), self::$DI['app']['registration.fields']); diff --git a/tests/Alchemy/Tests/Phrasea/Core/Service/Border/BorderManagerTest.php b/tests/Alchemy/Tests/Phrasea/Core/Service/Border/BorderManagerTest.php deleted file mode 100644 index b4e9becfe0..0000000000 --- a/tests/Alchemy/Tests/Phrasea/Core/Service/Border/BorderManagerTest.php +++ /dev/null @@ -1,210 +0,0 @@ - true, - 'checkers' => array( - 'type' => '', - 'options' => array() - ) - ); - - $manager = new BorderManager(self::$DI['app'], $options); - - $this->assertInstanceOf('\\Alchemy\\Phrasea\\Border\\Manager', $manager->getDriver()); - } - - /** - * @covers Alchemy\Phrasea\Core\Service\Border\BorderManager::getType - */ - public function testGetType() - { - $options = array( - 'enabled' => true, - 'checkers' => array( - 'type' => '', - 'options' => array() - ) - ); - $manager = new BorderManager(self::$DI['app'], $options); - - $this->assertEquals('border', $manager->getType()); - } - - /** - * @covers Alchemy\Phrasea\Core\Service\Border\BorderManager::getMandatoryOptions - */ - public function testGetMandatoryOptions() - { - $manager = new BorderManager(self::$DI['app'], array('enabled' => true, 'checkers' => array())); - $this->assertInternalType('array', $manager->getMandatoryOptions()); - } - - /** - * @dataProvider getVariousWrongOptions - * @covers Alchemy\Phrasea\Core\Service\Border\BorderManager::init - * @covers Alchemy\Phrasea\Core\Service\Border\BorderManager::getUnregisteredCheckers - * @covers Alchemy\Phrasea\Core\Service\Border\BorderManager::addUnregisteredCheck - */ - public function testGetUnregisteredCheckers($options) - { - $manager = new BorderManager(self::$DI['app'], $options); - - $this->assertEquals(1, count($manager->getUnregisteredCheckers())); - } - - /** - * @dataProvider getVariousOptions - * @covers Alchemy\Phrasea\Core\Service\Border\BorderManager::init - */ - public function testGetGoodConf($options) - { - $manager = new BorderManager(self::$DI['app'], $options); - - $this->assertEquals(0, count($manager->getUnregisteredCheckers())); - } - - public function getVariousWrongOptions() - { - list($databox, $collection) = $this->getDataboxAndCollection(); - - return array( - array( - array( - 'enabled' => true, - 'checkers' => array( - array( - 'type' => 'bidule', - 'options' => array(), - ), - ) - ) - ), - array( - array( - 'enabled' => true, - 'checkers' => array( - array( - 'options' => array(), - ), - ) - ) - ), - array( - array( - 'enabled' => true, - 'checkers' => array( - array( - 'type' => 'Checker\\UUID', - 'enabled' => false, - 'options' => array(), - ), - ) - ) - ), - array( - array( - 'enabled' => true, - 'checkers' => array( - array( - 'type' => 'Checker\\UUID', - 'options' => array(), - 'databoxes' => array(0), - ), - ), - ) - ), - array( - array( - 'enabled' => true, - 'checkers' => array( - array( - 'type' => 'Checker\\UUID', - 'options' => array(), - 'collections' => array(0), - ), - ), - ) - ), - array( - array( - 'enabled' => true, - 'checkers' => array( - array( - 'type' => 'Checker\\UUID', - 'options' => array(), - 'databoxes' => array($databox->get_sbas_id()), - 'collections' => array($collection->get_base_id()), - ), - ), - ) - ), - ); - } - - public function getDataboxAndCollection() - { - $app = new Application('test'); - $databox = $collection = null; - - foreach ($app['phraseanet.appbox']->get_databoxes() as $db) { - if (!$databox) { - $databox = $db; - } - if (!$collection) { - foreach ($db->get_collections() as $coll) { - $collection = $coll; - break; - } - } - } - - return array($databox, $collection); - } - - public function getVariousOptions() - { - list($databox, $collection) = $this->getDataboxAndCollection(); - - return array( - array( - array( - 'enabled' => true, - 'checkers' => array( - array( - 'type' => 'Checker\\UUID', - 'enabled' => true, - 'options' => array(), - 'databoxes' => array($databox->get_sbas_id()), - ), - ), - ) - ), - array( - array( - 'enabled' => true, - 'checkers' => array( - array( - 'type' => 'Checker\\UUID', - 'enabled' => true, - 'options' => array(), - 'collections' => array($collection->get_base_id()), - ), - ), - ) - ), - ); - } -} diff --git a/tests/Alchemy/Tests/Phrasea/Core/Service/Cache/ApcCacheTest.php b/tests/Alchemy/Tests/Phrasea/Core/Service/Cache/ApcCacheTest.php deleted file mode 100644 index c345a82820..0000000000 --- a/tests/Alchemy/Tests/Phrasea/Core/Service/Cache/ApcCacheTest.php +++ /dev/null @@ -1,51 +0,0 @@ -getDriver(); - $this->assertTrue($service instanceof \Doctrine\Common\Cache\CacheProvider); - } else { - try { - $cache->getDriver(); - $this->fail("should raise an exception"); - } catch (\Exception $e) { - - } - } - } - - public function testServiceException() - { - $cache = new \Alchemy\Phrasea\Core\Service\Cache\ApcCache( - self::$DI['app'], array() - ); - - try { - $cache->getDriver(); - $this->fail("should raise an exception"); - } catch (\Exception $e) { - - } - } - - public function testType() - { - $cache = new \Alchemy\Phrasea\Core\Service\Cache\ApcCache( - self::$DI['app'], array() - ); - - $this->assertEquals("apc", $cache->getType()); - } -} diff --git a/tests/Alchemy/Tests/Phrasea/Core/Service/Cache/ArrayCacheTest.php b/tests/Alchemy/Tests/Phrasea/Core/Service/Cache/ArrayCacheTest.php deleted file mode 100644 index 876dc1cb79..0000000000 --- a/tests/Alchemy/Tests/Phrasea/Core/Service/Cache/ArrayCacheTest.php +++ /dev/null @@ -1,42 +0,0 @@ -getDriver(); - $this->assertTrue($service instanceof \Doctrine\Common\Cache\CacheProvider); - } - - public function testServiceException() - { - $cache = new \Alchemy\Phrasea\Core\Service\Cache\ArrayCache( - self::$DI['app'], array() - ); - - try { - $cache->getDriver(); - $this->fail("should raise an exception"); - } catch (\Exception $e) { - - } - } - - public function testType() - { - $cache = new \Alchemy\Phrasea\Core\Service\Cache\ArrayCache( - self::$DI['app'], array() - ); - - $this->assertEquals("array", $cache->getType()); - } -} diff --git a/tests/Alchemy/Tests/Phrasea/Core/Service/Cache/MemcacheCacheTest.php b/tests/Alchemy/Tests/Phrasea/Core/Service/Cache/MemcacheCacheTest.php deleted file mode 100644 index 5dd605cb52..0000000000 --- a/tests/Alchemy/Tests/Phrasea/Core/Service/Cache/MemcacheCacheTest.php +++ /dev/null @@ -1,69 +0,0 @@ -getDriver(); - $this->assertTrue($service instanceof \Doctrine\Common\Cache\CacheProvider); - } else { - try { - $cache->getDriver(); - $this->fail("should raise an exception"); - } catch (\Exception $e) { - - } - } - } - - public function testServiceException() - { - $cache = new \Alchemy\Phrasea\Core\Service\Cache\MemcacheCache( - self::$DI['app'], array() - ); - - try { - $cache->getDriver(); - $this->fail("should raise an exception"); - } catch (\Exception $e) { - - } - } - - public function testType() - { - $cache = new \Alchemy\Phrasea\Core\Service\Cache\MemcacheCache( - self::$DI['app'], array() - ); - - $this->assertEquals("memcache", $cache->getType()); - } - - public function testHost() - { - $cache = new \Alchemy\Phrasea\Core\Service\Cache\MemcacheCache( - self::$DI['app'], array() - ); - - $this->assertEquals(\Alchemy\Phrasea\Core\Service\Cache\MemcacheCache::DEFAULT_HOST, $cache->getHost()); - } - - public function testPort() - { - $cache = new \Alchemy\Phrasea\Core\Service\Cache\MemcacheCache( - self::$DI['app'], array() - ); - - $this->assertEquals(\Alchemy\Phrasea\Core\Service\Cache\MemcacheCache::DEFAULT_PORT, $cache->getPort()); - } -} diff --git a/tests/Alchemy/Tests/Phrasea/Core/Service/Cache/XcacheCacheTest.php b/tests/Alchemy/Tests/Phrasea/Core/Service/Cache/XcacheCacheTest.php deleted file mode 100644 index 3bfa85401e..0000000000 --- a/tests/Alchemy/Tests/Phrasea/Core/Service/Cache/XcacheCacheTest.php +++ /dev/null @@ -1,51 +0,0 @@ -getDriver(); - $this->assertTrue($service instanceof \Doctrine\Common\Cache\CacheProvider); - } else { - try { - $cache->getDriver(); - $this->fail("should raise an exception"); - } catch (\Exception $e) { - - } - } - } - - public function testServiceException() - { - $cache = new \Alchemy\Phrasea\Core\Service\Cache\XcacheCache( - self::$DI['app'], array() - ); - - try { - $cache->getDriver(); - $this->fail("should raise an exception"); - } catch (\Exception $e) { - - } - } - - public function testType() - { - $cache = new \Alchemy\Phrasea\Core\Service\Cache\XcacheCache( - self::$DI['app'], array() - ); - - $this->assertEquals("xcache", $cache->getType()); - } -} diff --git a/tests/Alchemy/Tests/Phrasea/Core/Service/Log/Doctrine/MonologTest.php b/tests/Alchemy/Tests/Phrasea/Core/Service/Log/Doctrine/MonologTest.php deleted file mode 100644 index a9135cbad2..0000000000 --- a/tests/Alchemy/Tests/Phrasea/Core/Service/Log/Doctrine/MonologTest.php +++ /dev/null @@ -1,48 +0,0 @@ - "rotate" - , "filename" => "test" - , 'output' => 'json' - , 'channel' => 'test' - ); - - public function testService() - { - - $log = new \Alchemy\Phrasea\Core\Service\Log\Doctrine\Monolog( - self::$DI['app'], $this->options - ); - - $this->assertInstanceOf("\Doctrine\Logger\MonologSQLLogger", $log->getDriver()); - } - - public function testType() - { - $log = new \Alchemy\Phrasea\Core\Service\Log\Doctrine\Monolog( - self::$DI['app'], $this->options - ); - - $this->assertEquals("doctrine_monolog", $log->getType()); - } - - public function testExceptionBadOutput() - { - try { - $this->options["output"] = "unknowOutput"; - $log = new \Alchemy\Phrasea\Core\Service\Log\Doctrine\Monolog( - self::$DI['app'], $this->options - ); - $log->getDriver(); - $this->fail("should raise an exception"); - } catch (\Exception $e) { - - } - } -} diff --git a/tests/Alchemy/Tests/Phrasea/Core/Service/Log/Doctrine/PhpechoTest.php b/tests/Alchemy/Tests/Phrasea/Core/Service/Log/Doctrine/PhpechoTest.php deleted file mode 100644 index 7eb445e752..0000000000 --- a/tests/Alchemy/Tests/Phrasea/Core/Service/Log/Doctrine/PhpechoTest.php +++ /dev/null @@ -1,27 +0,0 @@ -assertInstanceOf("\Doctrine\DBAL\Logging\EchoSQLLogger", $log->getDriver()); - } - - public function testType() - { - $log = new \Alchemy\Phrasea\Core\Service\Log\Doctrine\Phpecho( - self::$DI['app'], array() - ); - - $this->assertEquals("phpecho", $log->getType()); - } -} diff --git a/tests/Alchemy/Tests/Phrasea/Core/Service/Log/MonologTest.php b/tests/Alchemy/Tests/Phrasea/Core/Service/Log/MonologTest.php deleted file mode 100644 index 935f5b3361..0000000000 --- a/tests/Alchemy/Tests/Phrasea/Core/Service/Log/MonologTest.php +++ /dev/null @@ -1,99 +0,0 @@ -options = array( - "handler" => "rotate" - , "filename" => "test" - , "channel" => "test" - ); - } - - public function testService() - { - $log = new \Alchemy\Phrasea\Core\Service\Log\Monolog( - self::$DI['app'], $this->options - ); - - $this->assertInstanceOf("\Monolog\Logger", $log->getDriver()); - } - - public function testType() - { - $log = new \Alchemy\Phrasea\Core\Service\Log\Monolog( - self::$DI['app'], $this->options - ); - - $this->assertEquals("monolog", $log->getType()); - } - - public function testExceptionMissingOptions() - { - try { - $log = new \Alchemy\Phrasea\Core\Service\Log\Monolog( - self::$DI['app'], $this->options - ); - $this->fail("should raise an exception"); - } catch (\Exception $e) { - - } - } - - public function testExceptionMissingHandler() - { - try { - unset($this->options["handler"]); - $log = new \Alchemy\Phrasea\Core\Service\Log\Monolog( - self::$DI['app'], $this->options - ); - $this->fail("should raise an exception"); - } catch (\Exception $e) { - - } - } - - public function testExceptionUnknowHandler() - { - try { - $this->options["handler"] = "unknowHandler"; - $log = new \Alchemy\Phrasea\Core\Service\Log\Monolog( - self::$DI['app'], $this->options - ); - $this->fail("should raise an exception"); - } catch (\Exception $e) { - - } - } - - public function testMissingFile() - { - try { - unset($this->options["filename"]); - $log = new \Alchemy\Phrasea\Core\Service\Log\Monolog( - self::$DI['app'], $this->options - ); - $this->fail("should raise an exception"); - } catch (\Exception $e) { - - } - } - - public function testStreamLogger() - { - - $this->options["handler"] = "stream"; - $log = new \Alchemy\Phrasea\Core\Service\Log\Monolog( - self::$DI['app'], $this->options - ); - $this->assertInstanceOf("\Monolog\Logger", $log->getDriver()); - } -} diff --git a/tests/Alchemy/Tests/Phrasea/Core/Service/Orm/DoctrineTest.php b/tests/Alchemy/Tests/Phrasea/Core/Service/Orm/DoctrineTest.php deleted file mode 100644 index e37175a964..0000000000 --- a/tests/Alchemy/Tests/Phrasea/Core/Service/Orm/DoctrineTest.php +++ /dev/null @@ -1,183 +0,0 @@ -options = array( - "debug" => false - , "log" => array('service' => "Log\\sql_logger") - , "dbal" => "main_connexion" - , "cache" => array( - "metadata" => array('service' => "Cache\\array_cache") - , "query" => array('service' => "Cache\\array_cache") - , "result" => array('service' => "Cache\\array_cache") - ) - ); - } - - public function testService() - { - $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$DI['app'], $this->options - ); - - $this->assertInstanceOf("\Doctrine\ORM\EntityManager", $doctrine->getDriver()); - } - - public function testType() - { - $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$DI['app'], $this->options - ); - - $this->assertEquals("doctrine", $doctrine->getType()); - } - - public function testExceptionMissingOptions() - { - try { - $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$DI['app'], $this->options - ); - $this->fail("should raise an exception"); - } catch (\Exception $e) { - - } - } - - public function testNoCacheInOptions() - { - $this->markTestSkipped('To rewrite'); - unset($this->options["cache"]); - $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$DI['app'], $this->options - ); - - foreach ($doctrine->getCacheServices()->all() as $service) { - $this->assertEquals("array", $service->getType()); - } - } - - public function testUnknowCache() - { - $this->options["cache"]["result"] = "unknowCache"; - - try { - $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$DI['app'], $this->options - ); - $this->fail("An exception should be raised"); - } catch (\Exception $e) { - - } - } - - public function testIsDebug() - { - $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$DI['app'], $this->options - ); - - $this->assertFalse($doctrine->isDebug()); - - $this->options['debug'] = true; - $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$DI['app'], $this->options - ); - - $this->assertTrue($doctrine->isDebug()); - } - - public function testGetCacheServices() - { - $this->markTestSkipped('To rewrite'); - $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$DI['app'], $this->options - ); - $this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag" - , $doctrine->getCacheServices()); - - foreach ($doctrine->getCacheServices()->all() as $service) { - $this->assertEquals("array", $service->getType()); - } - - $this->options['orm']["cache"] = array( - "metadata" => "array_cache" - , "query" => "apc_cache" - , "result" => "xcache_cache" - ); - - if (extension_loaded("apc") && extension_loaded("xcache")) { - $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$DI['app'], $this->options - ); - $this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag" - , $doctrine->getCacheServices()); - - foreach ($doctrine->getCacheServices()->all() as $key => $service) { - if ($key === "metadata") - $this->assertEquals("array", $service->getType()); - elseif ($key === "query") - $this->assertEquals("apc", $service->getType()); - elseif ($key === "result") - $this->assertEquals("xcache", $service->getType()); - } - } else { - try { - $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$DI['app'], $this->options - ); - $this->fail("An exception should be raised"); - } catch (\Exception $e) { - - } - } - } - - public function testExceptionUnknowLogService() - { - try { - $this->options["log"] = "unknowLogger"; - $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$DI['app'], $this->options - ); - $this->fail("should raise an exception"); - } catch (\Exception $e) { - - } - } - - public function testExceptionMissingDbal() - { - try { - unset($this->options["dbal"]); - $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$DI['app'], $this->options - ); - $this->fail("should raise an exception"); - } catch (\Exception $e) { - - } - } - - public function testExceptionUnknowDbal() - { - try { - $this->options["dbal"] = "unknowDbal"; - $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$DI['app'], $this->options - ); - $this->fail("should raise an exception"); - } catch (\Exception $e) { - - } - } -} diff --git a/tests/Alchemy/Tests/Phrasea/Core/Service/ServiceAbtractTest.php b/tests/Alchemy/Tests/Phrasea/Core/Service/ServiceAbtractTest.php deleted file mode 100644 index 08013c3676..0000000000 --- a/tests/Alchemy/Tests/Phrasea/Core/Service/ServiceAbtractTest.php +++ /dev/null @@ -1,33 +0,0 @@ -object = $this->getMockForAbstractClass( - "\Alchemy\Phrasea\Core\Service\ServiceAbstract" - , array( - self::$DI['app'] - , array('option' => 'my_options') - ) - ); - } - - public function testGetOptions() - { - $this->assertTrue(is_array($this->object->getOptions())); - $this->assertEquals(array('option' => 'my_options'), $this->object->getOptions()); - } -} diff --git a/tests/Alchemy/Tests/Phrasea/Core/ServiceBuilder/AbstractBuilderTest.php b/tests/Alchemy/Tests/Phrasea/Core/ServiceBuilder/AbstractBuilderTest.php deleted file mode 100644 index 700b812b1a..0000000000 --- a/tests/Alchemy/Tests/Phrasea/Core/ServiceBuilder/AbstractBuilderTest.php +++ /dev/null @@ -1,45 +0,0 @@ -getMock( - "\Alchemy\Phrasea\Core\Service\Builder" - , array() - , array( - self::$DI['app'] - , '' - , new \Symfony\Component\DependencyInjection\ParameterBag\ParameterBag() - ) - ); - $this->fail("should raise an exception"); - } catch (\Exception $e) { - - } - } - - public function testConstructExceptionCreate() - { - try { - $this->getMock( - "\\Alchemy\\Phrasea\\Core\\Service\\Builder" - , array() - , array( - self::$DI['app'], - 'test', - new \Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(), - ) - ); - $this->fail("should raise an exception"); - } catch (\Exception $e) { - - } - } -} diff --git a/tests/Alchemy/Tests/Phrasea/Core/ServiceBuilder/CacheBuilderTest.php b/tests/Alchemy/Tests/Phrasea/Core/ServiceBuilder/CacheBuilderTest.php deleted file mode 100644 index e07fd9d2a9..0000000000 --- a/tests/Alchemy/Tests/Phrasea/Core/ServiceBuilder/CacheBuilderTest.php +++ /dev/null @@ -1,34 +0,0 @@ - "unknow") - ); - - try { - $service = Builder::create(self::$DI['app'], $configuration); - $this->fail("An exception should be raised"); - } catch (\Exception $e) { - - } - } - - public function testCreate() - { - $configuration = new ParameterBag( - array("type" => "Cache\\ArrayCache") - ); - - $service = Builder::create(self::$DI['app'], $configuration); - $this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service); - } -} diff --git a/tests/Alchemy/Tests/Phrasea/Core/ServiceBuilder/LogBuilderTest.php b/tests/Alchemy/Tests/Phrasea/Core/ServiceBuilder/LogBuilderTest.php deleted file mode 100644 index 392434d902..0000000000 --- a/tests/Alchemy/Tests/Phrasea/Core/ServiceBuilder/LogBuilderTest.php +++ /dev/null @@ -1,51 +0,0 @@ - "unknow", "options" => array()) - ); - - try { - $service = Builder::create(self::$DI['app'], $configuration); - $this->fail("An exception should be raised"); - } catch (\Exception $e) { - - } - } - - public function testCreate() - { - $configuration = new ParameterBag( - array("type" => "Log\\Doctrine\\Monolog", "options" => array( - "handler" => "rotate" - , "filename" => "test" - , 'channel' => 'Test' - , 'output' => 'json' - , 'max_day' => '1' - ) - ) - ); - - $service = Builder::create(self::$DI['app'], $configuration); - $this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service); - } - - public function testCreateNamespace() - { - $configuration = new ParameterBag( - array("type" => "Log\\Doctrine\\Phpecho", "options" => array()) - ); - - $service = Builder::create(self::$DI['app'], $configuration); - $this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service); - } -} diff --git a/tests/Alchemy/Tests/Phrasea/Core/ServiceBuilder/OrmBuilderTest.php b/tests/Alchemy/Tests/Phrasea/Core/ServiceBuilder/OrmBuilderTest.php deleted file mode 100644 index f2c818d793..0000000000 --- a/tests/Alchemy/Tests/Phrasea/Core/ServiceBuilder/OrmBuilderTest.php +++ /dev/null @@ -1,44 +0,0 @@ - "unknow", "options" => array()) - ); - - try { - $service = Builder::create(self::$DI['app'], $configuration); - $this->fail("An exception should be raised"); - } catch (\Exception $e) { - - } - } - - public function testCreate() - { - $configuration = new ParameterBag( - array("type" => "Orm\\Doctrine", "options" => array( - "debug" => false - , "log" => array('service' => "Log\\query_logger") - , "dbal" => "main_connexion" - , "cache" => array( - "metadata" => "Cache\\array_cache" - , "query" => "Cache\\array_cache" - , "result" => "Cache\\array_cache" - ) - ) - ) - ); - - $service = Builder::create(self::$DI['app'], $configuration); - $this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service); - } -} diff --git a/tests/Alchemy/Tests/Phrasea/Setup/AbstractSetupTester.php b/tests/Alchemy/Tests/Phrasea/Setup/AbstractSetupTester.php index e71c9cd7ca..30b18cdac8 100644 --- a/tests/Alchemy/Tests/Phrasea/Setup/AbstractSetupTester.php +++ b/tests/Alchemy/Tests/Phrasea/Setup/AbstractSetupTester.php @@ -19,15 +19,11 @@ abstract class AbstractSetupTester extends \PHPUnit_Framework_TestCase protected function uninstall() { - rename(__DIR__ . '/../../../../../config/config.yml', __DIR__ . '/../../../../../config/config.yml.test'); - rename(__DIR__ . '/../../../../../config/connexions.yml', __DIR__ . '/../../../../../config/connexions.yml.test'); - rename(__DIR__ . '/../../../../../config/services.yml', __DIR__ . '/../../../../../config/services.yml.test'); + rename(__DIR__ . '/../../../../../config/configuration.yml', __DIR__ . '/../../../../../config/configuration.yml.test'); $this->tearDownHandlers[] = function() { - rename(__DIR__ . '/../../../../../config/config.yml.test', __DIR__ . '/../../../../../config/config.yml'); - rename(__DIR__ . '/../../../../../config/connexions.yml.test', __DIR__ . '/../../../../../config/connexions.yml'); - rename(__DIR__ . '/../../../../../config/services.yml.test', __DIR__ . '/../../../../../config/services.yml'); - }; + rename(__DIR__ . '/../../../../../config/configuration.yml.test', __DIR__ . '/../../../../../config/configuration.yml'); + }; } protected function goBackTo31() diff --git a/tests/Alchemy/Tests/Phrasea/Setup/InstallerTest.php b/tests/Alchemy/Tests/Phrasea/Setup/InstallerTest.php index 81b74e67b2..fe530d8781 100644 --- a/tests/Alchemy/Tests/Phrasea/Setup/InstallerTest.php +++ b/tests/Alchemy/Tests/Phrasea/Setup/InstallerTest.php @@ -4,9 +4,10 @@ namespace Alchemy\Tests\Phrasea\Setup; use Alchemy\Phrasea\Setup\Installer; use Alchemy\Phrasea\Application; -use Alchemy\Tests\Phrasea\Setup\TestSpecifications; -use Alchemy\Phrasea\Core\Configuration; +use Alchemy\Phrasea\Core\Configuration\Configuration; use Symfony\Component\Yaml\Parser; +use Symfony\Component\Yaml\Yaml; +use Alchemy\Phrasea\Core\Configuration\Compiler; class InstallerTest extends \PHPUnit_Framework_TestCase { @@ -40,11 +41,16 @@ class InstallerTest extends \PHPUnit_Framework_TestCase $app = new Application('test'); $parser = new Parser(); - $connDatas = $parser->parse(file_get_contents(__DIR__ . '/../../../../../config/connexions.yml')); - $credentials = $connDatas['main_connexion']; + $connDatas = $parser->parse(file_get_contents(__DIR__ . '/../../../../../config/configuration.yml')); + $credentials = $connDatas['main']['database']; - $specifications = new TestSpecifications(); - $app['phraseanet.configuration'] = new Configuration($specifications); + $config = __DIR__ . '/configuration.yml'; + $compiled = __DIR__ . '/configuration.yml.php'; + + @unlink($config); + @unlink($compiled); + + $app['phraseanet.configuration'] = new Configuration(new Yaml(), new Compiler(), $config, $compiled, true); $abConn = new \connection_pdo('abConn', 'localhost', 3306, $credentials['user'], $credentials['password'], 'ab_unitTests'); $dbConn = new \connection_pdo('dbConn', 'localhost', 3306, $credentials['user'], $credentials['password'], 'db_unitTests'); @@ -57,10 +63,14 @@ class InstallerTest extends \PHPUnit_Framework_TestCase \User_Adapter::unsetInstances(); - $this->assertTrue($specifications->isSetup()); + $this->assertTrue($app['phraseanet.configuration']->isSetup()); $this->assertTrue($app['phraseanet.configuration-tester']->isUpToDate()); - $confs = $app['phraseanet.configuration']->getConfigurations(); - $this->assertArrayHasKey('key', $confs); - $this->assertGreaterThan(10, strlen($confs['key'])); + $conf = $app['phraseanet.configuration']->getConfig(); + $this->assertArrayHasKey('main', $conf); + $this->assertArrayHasKey('key', $conf['main']); + $this->assertGreaterThan(10, strlen($conf['main']['key'])); + + @unlink($config); + @unlink($compiled); } } diff --git a/tests/Alchemy/Tests/Phrasea/Setup/TestSpecifications.php b/tests/Alchemy/Tests/Phrasea/Setup/TestSpecifications.php deleted file mode 100644 index b50ce4e9db..0000000000 --- a/tests/Alchemy/Tests/Phrasea/Setup/TestSpecifications.php +++ /dev/null @@ -1,43 +0,0 @@ -rootDir = sys_get_temp_dir() . '/' . microtime(true); - } - - public function __destruct() - { - @unlink($this->getConfigurationsPathFile()); - @unlink($this->getServicesPathFile()); - @unlink($this->getConnexionsPathFile()); - } - - protected function getConfigurationsPathFile() - { - return $this->rootDir . 'config.yml'; - } - - protected function getConnexionsPathFile() - { - return $this->rootDir . 'connexions.yml'; - } - - protected function getServicesPathFile() - { - return $this->rootDir . 'services.yml'; - } - - protected function getBinariesPathFile() - { - return $this->rootDir . 'binaries.yml'; - } -} diff --git a/tests/Alchemy/Tests/Phrasea/Setup/Version/Migration/Migration35Test.php b/tests/Alchemy/Tests/Phrasea/Setup/Version/Migration/Migration35Test.php index 6410cfe466..acb3a782bc 100644 --- a/tests/Alchemy/Tests/Phrasea/Setup/Version/Migration/Migration35Test.php +++ b/tests/Alchemy/Tests/Phrasea/Setup/Version/Migration/Migration35Test.php @@ -3,10 +3,11 @@ namespace Alchemy\Tests\Phrasea\Setup\Version\Migration; use Alchemy\Phrasea\Application; -use Alchemy\Phrasea\Core\Configuration; +use Alchemy\Phrasea\Core\Configuration\Configuration; +use Alchemy\Phrasea\Core\Configuration\Compiler; use Alchemy\Phrasea\Setup\Version\Migration\Migration35; -use Alchemy\Tests\Phrasea\Setup\TestSpecifications; use Alchemy\Tests\Phrasea\Setup\AbstractSetupTester; +use Symfony\Component\Yaml\Yaml; class Migration35Test extends AbstractSetupTester { @@ -33,7 +34,13 @@ class Migration35Test extends AbstractSetupTester public function testMigrate() { - $this->specifications = new TestSpecifications(); + $config = __DIR__ . '/configuration.yml'; + $compiled = __DIR__ . '/configuration.yml.php'; + + @unlink($config); + @unlink($compiled); + + $this->specifications = new Configuration(new Yaml(), new Compiler(), $config, $compiled, true); $this->assertFalse($this->specifications->isSetup()); $this->goBackTo35(); @@ -45,6 +52,9 @@ class Migration35Test extends AbstractSetupTester @unlink(__DIR__ . '/../../../../../../config/connexion.inc.old'); $this->assertTrue($this->specifications->isSetup()); + + @unlink($config); + @unlink($compiled); } private function getMigration(Application $app = null) @@ -52,7 +62,7 @@ class Migration35Test extends AbstractSetupTester $app = $app ? : new Application('test'); if ($this->specifications) { - $app['phraseanet.configuration'] = new Configuration($this->specifications); + $app['phraseanet.configuration'] = $this->specifications; } return new Migration35($app); diff --git a/tests/classes/PhraseanetWebTestCaseAuthenticatedAbstract.php b/tests/classes/PhraseanetWebTestCaseAuthenticatedAbstract.php index 49a986d04e..dcd649b7c0 100644 --- a/tests/classes/PhraseanetWebTestCaseAuthenticatedAbstract.php +++ b/tests/classes/PhraseanetWebTestCaseAuthenticatedAbstract.php @@ -92,13 +92,19 @@ abstract class PhraseanetWebTestCaseAuthenticatedAbstract extends PhraseanetPHPU { $this->createDatabase(); - $configuration = self::$DI['app']['phraseanet.configuration']; - - $choosenConnexion = $configuration->getPhraseanet()->get('database'); - $connexion = $configuration->getConnexion($choosenConnexion); + $connexion = self::$DI['app']['phraseanet.configuration']['main']['database']; try { - $conn = new \connection_pdo('databox_creation', $connexion->get('host'), $connexion->get('port'), $connexion->get('user'), $connexion->get('password'), 'unit_test_db', array(), false); + $conn = new \connection_pdo( + 'databox_creation', + $connexion['host'], + $connexion['port'], + $connexion['user'], + $connexion['password'], + 'unit_test_db', + array(), + false + ); } catch (\PDOException $e) { $this->markTestSkipped('Could not reach DB'); diff --git a/tests/classes/Session/Session_LoggerTest.php b/tests/classes/Session/Session_LoggerTest.php index b19209fdd3..bf6aaab598 100644 --- a/tests/classes/Session/Session_LoggerTest.php +++ b/tests/classes/Session/Session_LoggerTest.php @@ -40,7 +40,7 @@ class Session_LoggerTest extends PhraseanetPHPUnitAbstract $params = array( ':ses_id' => self::$DI['app']['session']->get('session_id') , ':usr_id' => self::$DI['app']['authentication']->getUser()->get_id() - , ':site' => self::$DI['app']['phraseanet.registry']->get('GV_sit') + , ':site' => self::$DI['app']['phraseanet.configuration']['main']['key'] ); $stmt = $this->databox->get_connection()->prepare($sql); @@ -59,7 +59,7 @@ class Session_LoggerTest extends PhraseanetPHPUnitAbstract $params = array( ':ses_id' => $ses_id , ':usr_id' => $usr_id - , ':site' => self::$DI['app']['phraseanet.registry']->get('GV_sit') + , ':site' => self::$DI['app']['phraseanet.configuration']['main']['key'] ); $stmt = $this->databox->get_connection()->prepare($sql); diff --git a/tests/classes/api/v1/api_v1_resultTest.php b/tests/classes/api/v1/api_v1_resultTest.php index df20be5e4d..08cb107422 100644 --- a/tests/classes/api/v1/api_v1_resultTest.php +++ b/tests/classes/api/v1/api_v1_resultTest.php @@ -17,11 +17,9 @@ class API_V1_resultTest extends PhraseanetPHPUnitAuthenticatedAbstract self::$DI['app']->register(new \API_V1_Timer()); - $conf = self::$DI['app']['phraseanet.configuration']; - $confs = $conf->getConfigurations(); - $confs[$conf->getEnvironnement()]['phraseanet']['api-timers'] = true; - - self::$DI['app']['phraseanet.configuration']->setConfigurations($confs); + $conf = self::$DI['app']['phraseanet.configuration']->getConfig(); + $conf['main']['api-timers'] = true; + self::$DI['app']['phraseanet.configuration']->setConfig($conf); $this->api = $this->getMock("API_V1_adapter", array("get_version"), array(), "", false); $this->api->expects($this->any())->method("get_version")->will($this->returnValue("my_super_version1.0")); diff --git a/tests/classes/patch/3803Test.php b/tests/classes/patch/3803Test.php index d6a8719663..324d67219d 100644 --- a/tests/classes/patch/3803Test.php +++ b/tests/classes/patch/3803Test.php @@ -2,90 +2,6 @@ class patch_3803Test extends PhraseanetPHPUnitAbstract { - /** - * @covers patch_3803::apply - */ - public function testApplyInSphinxEnvironment() - { - $patch = new patch_3803(); - - $appbox = $this->getMockBuilder('appbox') - ->disableOriginalConstructor() - ->getMock(); - - $app = self::$DI['app']; - - $app['phraseanet.registry'] = $this->getMock('registryInterface'); - $app['phraseanet.registry']->expects($this->any()) - ->method('get') - ->will($this->returnCallback(function ($parameter) { - switch ($parameter) { - case 'GV_sphinx': - return true; - case 'GV_sphinx_rt_port': - return 5678; - case 'GV_sphinx_rt_host': - return 'sphinx.rt_host'; - case 'GV_sphinx_host': - return 'sphinx.host'; - case 'GV_sphinx_port': - return 1234; - default: - throw new \InvalidArgumentException(sprintf('%s is missing, test case not ready', $parameter)); - } - })); - - $catchConfiguration = $catchSEConf = null; - - $app['phraseanet.configuration'] = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration') - ->disableOriginalConstructor() - ->getMock(); - $app['phraseanet.configuration']->expects($this->once()) - ->method('getConfigurations') - ->will($this->returnValue(array('environment' => 'prod', 'prod' => array(), 'dev' => array()))); - $app['phraseanet.configuration']->expects($this->once()) - ->method('setConfigurations') - ->will($this->returnCallback(function($configuration) use (&$catchConfiguration) { - $catchConfiguration = $configuration; - })); - - $panel = $this->getMock('Alchemy\Phrasea\SearchEngine\ConfigurationPanelInterface'); - $panel->expects($this->once()) - ->method('saveConfiguration') - ->will($this->returnCallback(function($json) use (&$catchSEConf) { - $catchSEConf = $json; - })); - $panel->expects($this->once()) - ->method('getConfiguration') - ->will($this->returnValue(array())); - - $app['phraseanet.SE'] = $this->getMock('Alchemy\Phrasea\SearchEngine\SearchEngineInterface'); - $app['phraseanet.SE']->expects($this->any()) - ->method('getConfigurationPanel') - ->will($this->returnValue($panel)); - - $this->assertTrue($patch->apply($appbox, $app)); - - $upgrade = 0; - foreach ($catchConfiguration as $env => $conf) { - if (in_array($env, array('environment', 'key'))) { - continue; - } - $this->assertArrayHasKey('search-engine', $conf); - $upgrade++; - } - - $this->assertEquals(2, $upgrade); - $this->assertArrayHasKey('port', $catchSEConf); - $this->assertArrayHasKey('host', $catchSEConf); - $this->assertArrayHasKey('rt_port', $catchSEConf); - $this->assertArrayHasKey('rt_host', $catchSEConf); - $this->assertEquals(5678, $catchSEConf['rt_port']); - $this->assertEquals('sphinx.rt_host', $catchSEConf['rt_host']); - $this->assertEquals(1234, $catchSEConf['port']); - $this->assertEquals('sphinx.host', $catchSEConf['host']); - } - /** * @covers patch_3803::apply */ @@ -99,63 +15,11 @@ class patch_3803Test extends PhraseanetPHPUnitAbstract $app = self::$DI['app']; - $app['phraseanet.registry'] = $this->getMock('registryInterface'); - $app['phraseanet.registry']->expects($this->any()) - ->method('get') - ->will($this->returnCallback(function ($parameter) { - switch ($parameter) { - case 'GV_sphinx': - return false; - case 'GV_phrasea_sort': - return 'custom-sort'; - default: - throw new \InvalidArgumentException(sprintf('%s is missing, test case not ready', $parameter)); - } - })); - - $catchConfiguration = $catchPhraseaConf = null; - - $app['phraseanet.configuration'] = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration') - ->disableOriginalConstructor() - ->getMock(); + $app['phraseanet.configuration'] = $this->getMock('Alchemy\Phrasea\Core\Configuration\ConfigurationInterface'); $app['phraseanet.configuration']->expects($this->once()) - ->method('getConfigurations') - ->will($this->returnValue(array('environment' => 'prod', 'prod' => array(), 'dev' => array()))); - $app['phraseanet.configuration']->expects($this->once()) - ->method('setConfigurations') - ->will($this->returnCallback(function($configuration) use (&$catchConfiguration) { - $catchConfiguration = $configuration; - })); - - $panel = $this->getMock('Alchemy\Phrasea\SearchEngine\ConfigurationPanelInterface'); - $panel->expects($this->once()) - ->method('saveConfiguration') - ->will($this->returnCallback(function($json) use (&$catchSEConf) { - $catchSEConf = $json; - })); - $panel->expects($this->once()) - ->method('getConfiguration') - ->will($this->returnValue(array())); - - $app['phraseanet.SE'] = $this->getMock('Alchemy\Phrasea\SearchEngine\SearchEngineInterface'); - $app['phraseanet.SE']->expects($this->any()) - ->method('getConfigurationPanel') - ->will($this->returnValue($panel)); + ->method('setDefault') + ->with('main', 'search-engine'); $this->assertTrue($patch->apply($appbox, $app)); - - $upgrade = 0; - foreach ($catchConfiguration as $env => $conf) { - if (in_array($env, array('environment', 'key'))) { - continue; - } - $this->assertArrayHasKey('search-engine', $conf); - $upgrade++; - } - - $this->assertEquals(2, $upgrade); - - $this->assertArrayHasKey('default_sort', $catchSEConf); - $this->assertEquals('custom-sort', $catchSEConf['default_sort']); } } diff --git a/tests/classes/patch/3804Test.php b/tests/classes/patch/3804Test.php index ca1b9fa891..0b9684efbf 100644 --- a/tests/classes/patch/3804Test.php +++ b/tests/classes/patch/3804Test.php @@ -15,46 +15,11 @@ class patch_3804Test extends PhraseanetPHPUnitAbstract ->disableOriginalConstructor() ->getMock(); - $catchConfiguration = null; - - $app['phraseanet.configuration'] = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration') - ->disableOriginalConstructor() - ->getMock(); - + $app['phraseanet.configuration'] = $this->getMock('Alchemy\Phrasea\Core\Configuration\ConfigurationInterface'); $app['phraseanet.configuration']->expects($this->once()) - ->method('getConfigurations') - ->will($this->returnValue(array( - 'environment' => 'prod', - 'prod' => array(), - 'dev' => array() - ))); - $app['phraseanet.configuration']->expects($this->once()) - ->method('setConfigurations') - ->will($this->returnCallback(function($configuration) use (&$catchConfiguration) { - $catchConfiguration = $configuration; - })); - - $app['phraseanet.configuration']->expects($this->once()) - ->method('getServices') - ->will($this->returnValue(array( - 'SearchEngine' => array(), - ))); - - $app['phraseanet.configuration']->expects($this->once()) - ->method('resetServices') - ->with($this->equalTo('TaskManager')); + ->method('setDefault') + ->with('main', 'task-manager'); $this->assertTrue($patch->apply($appbox, $app)); - - $upgrade = 0; - foreach ($catchConfiguration as $env => $conf) { - if (in_array($env, array('environment', 'key'))) { - continue; - } - $this->assertArrayHasKey('task-manager', $conf); - $upgrade++; - } - - $this->assertEquals(2, $upgrade); } } diff --git a/tests/classes/patch/3807Test.php b/tests/classes/patch/3807Test.php new file mode 100644 index 0000000000..d0803acb98 --- /dev/null +++ b/tests/classes/patch/3807Test.php @@ -0,0 +1,272 @@ +revert(); + } + + public function tearDown() + { + $this->revert(); + } + + private function revert() + { + foreach (array('binaries.yml.bkp', 'config.yml.bkp', 'connexions.yml.bkp', 'services.yml.bkp') as $backupFile) { + if (is_file(__DIR__ . '/fixtures-3807/config/' . $backupFile)) { + rename(__DIR__ . '/fixtures-3807/config/' . $backupFile, __DIR__ . '/fixtures-3807/config/' . substr($backupFile, 0, -4)); + } + } + } + + public function testApply() + { + $app = new Application(); + $app['phraseanet.configuration'] = $this->getMock('Alchemy\Phrasea\Core\Configuration\ConfigurationInterface'); + $app['root.path'] = __DIR__ . '/fixtures-3807'; + + $app['phraseanet.configuration']->expects($this->once()) + ->method('getConfig') + ->will($this->returnValue($this->getCurrent())); + + $app['phraseanet.configuration']->expects($this->once()) + ->method('setConfig') + ->with($this->getModified()); + + $appbox = $this->getMockBuilder('appbox') + ->disableOriginalConstructor() + ->getMock(); + + $patch = new patch_3807(); + $patch->apply($appbox, $app); + + } + + private function getModified() + { + $modified = $this->getCurrent(); + + $modified['main']['key'] = '1234567890'; + $modified['main']['servername'] = 'http://sub.domain.tld/'; + $modified['main']['maintenance'] = true; + $modified['binaries']['test_binary'] = '/path/to/test/binary/file'; + $modified['main']['database'] = array_replace($modified['main']['database'], array( + 'host' => 'sql-host', + 'port' => '13306', + 'user' => 'username', + 'password' => 's3cr3t', + 'dbname' => 'phrasea_db', + )); + $modified['main']['cache'] = array( + 'type' => 'MemcacheCache', + 'options' => array( + 'host' => 'memcache-host', + 'port' => 21211, + ) + ); + $modified['main']['opcodecache'] = array( + 'type' => 'ApcCache', + 'options' => array(), + ); + $modified['border-manager']['enabled'] = false; + + return $modified; + } + + private function getCurrent() + { + return array( + 'main' => array( + 'servername' => 'http://local.phrasea/', + 'maintenance' => false, + 'database' => array( + 'host' => '127.0.0.1', + 'port' => '3306', + 'user' => 'root', + 'password' => '', + 'dbname' => 'ab_test', + 'driver' => 'pdo_mysql', + 'charset' => 'UTF8', + ), + 'database-test' => array( + 'driver' => 'pdo_sqlite', + 'path' => '/tmp/db.sqlite', + 'charset' => 'UTF8', + ), + 'api-timers' => true, + 'cache' => array( + 'type' => 'ArrayCache', + 'options' => array( + ), + ), + 'opcodecache' => array( + 'type' => 'ArrayCache', + 'options' => array( + ), + ), + 'search-engine' => array( + 'type' => 'Alchemy\Phrasea\SearchEngine\Phrasea\PhraseaEngine', + 'options' => array( + ), + ), + 'task-manager' => array( + 'options' => '', + ), + 'key' => null, + ), + 'binaries' => array( + 'legacy_binay' => '/path/to/legacy/binary', + ), + 'border-manager' => array( + 'enabled' => true, + 'checkers' => array( + array( + 'type' => 'Checker\Sha256', + 'enabled' => true, + ), + array( + 'type' => 'Checker\UUID', + 'enabled' => true, + ), + array( + 'type' => 'Checker\Colorspace', + 'enabled' => false, + 'options' => array( + 'colorspaces' => array( + 'cmyk', + 'grayscale', + 'rgb', + ), + ), + ), + array( + 'type' => 'Checker\Dimension', + 'enabled' => false, + 'options' => array( + 'width' => 80, + 'height' => 160, + ), + ), + array( + 'type' => 'Checker\Extension', + 'enabled' => false, + 'options' => array( + 'extensions' => array( + 'jpg', + 'jpeg', + 'bmp', + 'tif', + 'gif', + 'png', + 'pdf', + 'doc', + 'odt', + 'mpg', + 'mpeg', + 'mov', + 'avi', + 'xls', + 'flv', + 'mp3', + 'mp2', + ), + ), + ), + array( + 'type' => 'Checker\Filename', + 'enabled' => false, + 'options' => array( + 'sensitive' => true, + ), + ), + array( + 'type' => 'Checker\MediaType', + 'enabled' => false, + 'options' => array( + 'mediatypes' => array( + 'Audio', + 'Document', + 'Flash', + 'Image', + 'Video', + ), + ), + ), + ), + ), + 'authentication' => array( + 'auto-create' => array( + 'enabled' => false, + 'templates' => array( + ), + ), + 'captcha' => array( + 'enabled' => true, + 'trials-before-failure' => 9, + ), + 'providers' => array( + 'facebook' => array( + 'enabled' => false, + 'options' => array( + 'app-id' => '', + 'secret' => '', + ), + ), + 'twitter' => array( + 'enabled' => false, + 'options' => array( + 'consumer-key' => '', + 'consumer-secret' => '', + ), + ), + 'google-plus' => array( + 'enabled' => false, + 'options' => array( + 'client-id' => '', + 'client-secret' => '', + ), + ), + 'github' => array( + 'enabled' => false, + 'options' => array( + 'client-id' => '', + 'client-secret' => '', + ), + ), + 'viadeo' => array( + 'enabled' => false, + 'options' => array( + 'client-id' => '', + 'client-secret' => '', + ), + ), + 'linkedin' => array( + 'enabled' => false, + 'options' => array( + 'client-id' => '', + 'client-secret' => '', + ), + ), + ), + ), + 'registration-fields' => array( + array( + 'name' => 'company', + 'required' => true, + ), + array( + 'name' => 'firstname', + 'required' => true, + ), + array( + 'name' => 'geonameid', + 'required' => true, + ), + ), + ); + } +} \ No newline at end of file diff --git a/tests/classes/patch/fixtures-3807/config/binaries.yml b/tests/classes/patch/fixtures-3807/config/binaries.yml new file mode 100644 index 0000000000..9ec01c3124 --- /dev/null +++ b/tests/classes/patch/fixtures-3807/config/binaries.yml @@ -0,0 +1,2 @@ +binaries: + test_binary: /path/to/test/binary/file \ No newline at end of file diff --git a/tests/classes/patch/fixtures-3807/config/config.yml b/tests/classes/patch/fixtures-3807/config/config.yml new file mode 100644 index 0000000000..14da7ff3d3 --- /dev/null +++ b/tests/classes/patch/fixtures-3807/config/config.yml @@ -0,0 +1,16 @@ +environment : prod +key : 1234567890 + +prod: + phraseanet: + servername: 'http://sub.domain.tld/' + maintenance: true + debug: false + display_errors: false + database: main_connexion + api-timers: false + template_engine: twig + orm: doctrine_prod + cache: memcache_cache + opcodecache: apc_cache + border-manager: border_manager diff --git a/tests/classes/patch/fixtures-3807/config/connexions.yml b/tests/classes/patch/fixtures-3807/config/connexions.yml new file mode 100644 index 0000000000..70ee4ccc22 --- /dev/null +++ b/tests/classes/patch/fixtures-3807/config/connexions.yml @@ -0,0 +1,13 @@ +main_connexion: + host: 'sql-host' + port: 13306 + user: username + password: s3cr3t + dbname: phrasea_db + driver: pdo_mysql + charset: UTF8 + +test_connexion: + driver: pdo_sqlite + path: '/tmp/db.sqlite' + charset: UTF8 diff --git a/tests/classes/patch/fixtures-3807/config/services.yml b/tests/classes/patch/fixtures-3807/config/services.yml new file mode 100644 index 0000000000..dc3dce9e0a --- /dev/null +++ b/tests/classes/patch/fixtures-3807/config/services.yml @@ -0,0 +1,109 @@ +Orm: + doctrine_prod: + type: Orm\Doctrine + options: + debug: false + dbal: main_connexion + cache: + query: + service: Cache\array_cache + result: + service: Cache\array_cache + metadata: + service: Cache\array_cache + +Log: + query_logger: + type: Log\Doctrine\Monolog + options: + output: json + channel: query-logger + handler: rotate + max_day: 2 + filename: doctrine-query.log + sql_logger: + type: Log\Doctrine\Phpecho + +Cache: + array_cache: + type: Cache\ArrayCache + memcache_cache: + type: Cache\MemcacheCache + options: + host: memcache-host + port: 21211 + apc_cache: + type: Cache\ApcCache + xcache_cache: + type: Cache\XcacheCache + wincache_cache: + type: Cache\WinCacheCache + +Border: + #Define Border service + #The border service handles checks validation constraints against incoming files + border_manager: + type: Border\BorderManager + options: + #Enable validation on incoming files + enabled: false + checkers: + #Check for duplicated file based on their sha256 check sum + - + type: Checker\Sha256 + enabled: true + #Check for duplicated file based on their UUID + - + type: Checker\UUID + enabled: true + #Check colorspace (if applicable) + - + type: Checker\Colorspace + enabled: false + options: + colorspaces: [cmyk, grayscale, rgb] + #Check file dimension (if applicable) + - + type: Checker\Dimension + enabled: false + options: + width: 80 + height: 160 + #Check file extension + #set to false to enable all file extensions + - + type: Checker\Extension + enabled: false + options: + extensions: [jpg, jpeg, bmp, tif, gif, png, pdf, doc, odt, mpg, mpeg, mov, avi, xls, flv, mp3, mp2] + #Check filename + - + type: Checker\Filename + enabled: false + options: + sensitive: true + #Check media type + #Set to false to enable all mediatype + - + type: Checker\MediaType + enabled: false + options: + mediatypes: [Audio, Document, Flash, Image, Video] +SearchEngine: + phrasea: + type: SearchEngine\PhraseaEngine + sphinxsearch: + type: SearchEngine\SphinxSearch + options: + host: localhost + port: 9306 + rt_host: localhost + rt_port: 9308 +TaskManager: + task_manager: + type: TaskManager\TaskManager + options: + # set the threshold for sending task logs to syslog or by mail + # values : task_abstract::[LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERROR | LOG_CRITICAL | LOG_ALERT] + #syslog_level: task_abstract::LOG_ERROR + #maillog_level: task_abstract::LOG_ERROR