diff --git a/lib/unitTest/Core/Configuration/ApplicationTest.php b/lib/unitTest/Core/Configuration/ApplicationTest.php new file mode 100644 index 0000000000..c81f3322af --- /dev/null +++ b/lib/unitTest/Core/Configuration/ApplicationTest.php @@ -0,0 +1,139 @@ +getNonExtendablePath(); + $this->assertTrue(is_array($paths)); + foreach ($paths as $path) + { + $this->assertTrue(is_array($path)); + foreach ($path as $key) + { + $this->assertTrue(is_string($key)); + } + } + } + + public function testGetConfFileFromEnvName() + { + $app = $this->getMock( + '\Alchemy\Phrasea\Core\Configuration\Application' + , array('getMainConfigurationFile', 'getConfigurationFilePath') + ); + + $fileName = __DIR__ . '/confTestFiles/good.yml'; + + $app->expects($this->any()) + ->method('getMainConfigurationFile') + ->will( + $this->returnValue( + new \SplFileObject($fileName) + ) + ); + $app->expects($this->any()) + ->method('getConfigurationFilePath') + ->will( + $this->returnValue( + __DIR__ . '/confTestFiles' + ) + ); + + $this->assertInstanceOf('SplFileObject', $app->getConfFileFromEnvName('oneenv')); + $this->assertInstanceOf('SplFileObject', $app->getConfFileFromEnvName(Application::EXTENDED_MAIN_KEYWORD)); + + try + { + $app->getConfFileFromEnvName('unknow_env'); + $this->fail('An exception shoud be raised'); + } + catch (\Exception $e) + { + + } + } + + public function testGetConfigurationFilePath() + { + $app = new Application(); + $this->assertTrue(is_string($app->getConfigurationFilePath())); + } + + public function testGetMainConfigurationFile() + { + $app = new Application(); + try + { + $this->assertInstanceOf('SplFileObject', $app->getMainConfigurationFile()); + } + catch(Exception $e) + { + $this->markTestSkipped('Config file config.yml is not present'); + } + } + + public function testGetConfFileExtension() + { + $app = new Application(); + $this->assertEquals('yml', $app->getConfFileExtension()); + } + + public function testIsExtended() + { + $app = new Application(); + + $testExtendedEnv = array('extends' => 'value'); + $testNonExtendedEnv = array('blabla' => 'blabla'); + + $this->assertTrue($app->isExtended($testExtendedEnv)); + $this->assertFalse($app->isExtended($testNonExtendedEnv)); + } + + public function testGetExtendedEnvName() + { + $app = new Application(); + $testExtendedEnv = array('extends' => 'value'); + $testNonExtendedEnv = array('blabla' => 'blabla'); + + $this->assertEquals('value', $app->getExtendedEnvName($testExtendedEnv)); + $this->assertNull($app->getExtendedEnvName($testNonExtendedEnv)); + } + +} diff --git a/lib/unitTest/Core/Configuration/ConfigurationTest.php b/lib/unitTest/Core/Configuration/ConfigurationTest.php new file mode 100644 index 0000000000..735242bdf4 --- /dev/null +++ b/lib/unitTest/Core/Configuration/ConfigurationTest.php @@ -0,0 +1,174 @@ +getMock( + '\Alchemy\Phrasea\Core\Configuration\Application' + , array('getMainConfigurationFile') + ); + + $fileName = __DIR__ . '/confTestFiles/good.yml'; + + $spec->expects($this->any()) + ->method('getMainConfigurationFile') + ->will( + $this->returnValue( + new \SplFileObject($fileName) + ) + ); + + $handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml()); + + $environnement = 'main'; + $configuration = new PhraseaCore\Configuration($environnement, $handler); + + $this->assertEquals($environnement, $configuration->getEnvironnement()); + $this->assertTrue($configuration->isInstalled()); + $this->assertInstanceOf( + 'Alchemy\Phrasea\Core\Configuration\Parameter' + , $configuration->getConfiguration() + ); + $this->assertFalse($configuration->isDebug()); + $this->assertFalse($configuration->displayErrors()); + $this->assertTrue(is_array($configuration->getPhraseanet())); + $this->assertTrue(is_array($configuration->getDoctrine())); + } + + public function testInstalled() + { + $spec = $this->getMock( + '\Alchemy\Phrasea\Core\Configuration\Application' + , array('getMainConfigurationFile') + ); + + $spec->expects($this->any()) + ->method('getMainConfigurationFile') + ->will($this->throwException(new \Exception())); + + $handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml()); + + $environnement = 'main'; + $configuration = new PhraseaCore\Configuration($environnement, $handler); + + $this->assertFalse($configuration->isInstalled()); + $this->assertTrue(is_array($configuration->getPhraseanet())); + $this->assertTrue(is_array($configuration->getDoctrine())); + } + + public function testGetAvailableLogger() + { + $spec = $this->getMock('\Alchemy\Phrasea\Core\Configuration\Application'); + $handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml()); + + $environnement = 'main'; + $configuration = new PhraseaCore\Configuration($environnement, $handler); + + $availableLogger = $configuration->getAvailableDoctrineLogger(); + + $this->assertTrue(is_array($availableLogger)); + $this->assertContains('monolog', $availableLogger); + $this->assertContains('echo', $availableLogger); + } + + public function testGetHandler() + { + $spec = $this->getMock('\Alchemy\Phrasea\Core\Configuration\Application'); + $handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml()); + + $environnement = 'main'; + $configuration = new PhraseaCore\Configuration($environnement, $handler); + + $this->assertInstanceOf('\Alchemy\Phrasea\Core\Configuration\Handler', $configuration->getConfigurationHandler()); + } + + public function testSetHandler() + { + $spec = $this->getMock('\Alchemy\Phrasea\Core\Configuration\Application'); + $handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml()); + + $environnement = 'main'; + $configuration = new PhraseaCore\Configuration($environnement, $handler); + + $spec2 = $this->getMock('\Alchemy\Phrasea\Core\Configuration\Application'); + + $spec2->expects($this->any()) + ->method('getMainConfigurationFile') + ->will( + $this->returnValue( + 'test' + ) + ); + + $newHandler = new Configuration\Handler($spec2, new Configuration\Parser\Yaml()); + + $configuration->setConfigurationHandler($newHandler); + + $this->assertEquals('test', $configuration->getConfigurationHandler()->getSpecification()->getMainConfigurationFile()); + } + + public function testBadDoctrineLogger() + { + $spec = $this->getMock( + '\Alchemy\Phrasea\Core\Configuration\Application' + , array('getMainConfigurationFile') + ); + + $fileName = __DIR__ . '/confTestFiles/bad_doctrine_logger.yml'; + + $spec->expects($this->any()) + ->method('getMainConfigurationFile') + ->will( + $this->returnValue( + new \SplFileObject($fileName) + ) + ); + + $handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml()); + + $environnement = 'main'; + $configuration = new PhraseaCore\Configuration($environnement, $handler); + + try + { + $configuration->getDoctrine(); + $this->fail('An exception should be raised'); + } + catch(Exception $e) + { + + } + } +} \ No newline at end of file diff --git a/lib/unitTest/Core/Configuration/HandlerTest.php b/lib/unitTest/Core/Configuration/HandlerTest.php new file mode 100644 index 0000000000..f889cb9d53 --- /dev/null +++ b/lib/unitTest/Core/Configuration/HandlerTest.php @@ -0,0 +1,164 @@ +getMock( + '\Alchemy\Phrasea\Core\Configuration\Application' + , array('getMainConfigurationFile') + ); + + $fileName = __DIR__ . '/confTestFiles/good.yml'; + + $spec->expects($this->any()) + ->method('getMainConfigurationFile') + ->will( + $this->returnValue( + new \SplFileObject($fileName) + ) + ); + + $handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml()); + + $this->assertInstanceOf('\Alchemy\Phrasea\Core\Configuration\Specification', $handler->getSpecification()); + } + + public function testGetParser() + { + $spec = $this->getMock( + '\Alchemy\Phrasea\Core\Configuration\Application' + , array('getMainConfigurationFile') + ); + + $fileName = __DIR__ . '/confTestFiles/good.yml'; + + $spec->expects($this->any()) + ->method('getMainConfigurationFile') + ->will( + $this->returnValue( + new \SplFileObject($fileName) + ) + ); + + $handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml()); + + $this->assertInstanceOf('\Alchemy\Phrasea\Core\Configuration\Parser', $handler->getParser()); + } + + public function testRetrieveExtendedEnvFromFile() + { + + $handler = new Configuration\Handler(new Application(), new Configuration\Parser\Yaml()); + + $fileName = __DIR__ . '/confTestFiles/config_test.yml'; + $file = new \SplFileObject($fileName); + + $envs = $handler->retrieveExtendedEnvFromFile($file); + + $this->assertEquals(3, count($envs)); + } + + public function testRetrieveExtendedEnvFromFileNonExisting() + { + + $handler = new Configuration\Handler(new Application(), new Configuration\Parser\Yaml()); + + $fileName = __DIR__ . '/confTestFiles/extends_non_existing_file.yml'; + $file = new \SplFileObject($fileName); + + try + { + $envs = $handler->retrieveExtendedEnvFromFile($file); + $this->fail('An exception should have been raised'); + } + catch (Exception $e) + { + + } + } + + public function testHandle() + { + $spec = $this->getMock( + '\Alchemy\Phrasea\Core\Configuration\Application' + , array('getConfigurationFilePath') + ); + + $spec->expects($this->any()) + ->method('getConfigurationFilePath') + ->will( + $this->returnValue( + __DIR__ . '/confTestFiles' + ) + ); + + $handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml()); + + $result = $handler->handle('test'); + + $this->assertTrue(is_array($result)); + } + + public function testHandleDataNotfound() + { + $spec = $this->getMock( + '\Alchemy\Phrasea\Core\Configuration\Application' + , array('getConfigurationFilePath', 'getNonExtendablePath') + ); + + $spec->expects($this->any()) + ->method('getConfigurationFilePath') + ->will( + $this->returnValue( + __DIR__ . '/confTestFiles' + ) + ); + + $spec->expects($this->any()) + ->method('getNonExtendablePath') + ->will( + $this->returnValue( + array(array('NON', 'EXISTING', 'VALUE')) + ) + ); + + $handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml()); + + $result = $handler->handle('test'); + + $this->assertTrue(is_array($result)); + } + +} \ No newline at end of file diff --git a/lib/unitTest/Core/Configuration/ParserTest.php b/lib/unitTest/Core/Configuration/ParserTest.php new file mode 100644 index 0000000000..0df9a5fefe --- /dev/null +++ b/lib/unitTest/Core/Configuration/ParserTest.php @@ -0,0 +1,64 @@ +parse($file); + + $this->assertTrue(is_array($result)); + + $filename = $fileName = __DIR__ . '/confTestFiles/test.json'; + + $file = new SplFileObject($filename); + + try + { + $result = $parser->parse($file); + $this->fail('An exception shoud have been raised'); + } + catch(Exception $e) + { + + } + + + } +} \ No newline at end of file diff --git a/lib/unitTest/Core/Configuration/confTestFiles/bad_doctrine_logger.yml b/lib/unitTest/Core/Configuration/confTestFiles/bad_doctrine_logger.yml new file mode 100644 index 0000000000..d715751e74 --- /dev/null +++ b/lib/unitTest/Core/Configuration/confTestFiles/bad_doctrine_logger.yml @@ -0,0 +1,60 @@ +## YAML Template. +--- +phraseanet: + servername: http://dev.phrasea.net/ + maintenance: false + debug: false + display_errors: false + +# Twig Configuration +twig: + debug: false + strict_variables: true + +# Doctrine Configuration +doctrine: + dbal: + driver: pdo_mysql + host: localhost + port: 3306 + dbname: ab_trunk + user: root + password: nicolas007 + charset: UTF8 + + orm: + auto_generate_proxy_classes: %phraseanet.debug% + auto_mapping: true + cache: + query: array + result: array + metadata: array + + log: + enable: true + type: bad_logger + handler: rotate + output: json + filename: doctrine-query.log + max_day: 10 + +# Monolog LOG Configuration +monolog: + output: yaml + handlers: + main: + type: stream + level: debug + rotate: + type: rotatingFile + level: debug + max_day: 10 + +# Memchache Configuration +memcached: + host: 11211 + + + + + \ No newline at end of file diff --git a/lib/unitTest/Core/Configuration/confTestFiles/config.yml b/lib/unitTest/Core/Configuration/confTestFiles/config.yml new file mode 100644 index 0000000000..2d01e4fa18 --- /dev/null +++ b/lib/unitTest/Core/Configuration/confTestFiles/config.yml @@ -0,0 +1,60 @@ +## YAML Template. +--- +phraseanet: + servername: http://dev.phrasea.net/ + maintenance: false + debug: false + display_errors: false + +# Twig Configuration +twig: + debug: false + strict_variables: true + +# Doctrine Configuration +doctrine: + dbal: + driver: pdo_mysql + host: localhost + port: 3306 + dbname: ab_trunk + user: root + password: nicolas007 + charset: UTF8 + + orm: + auto_generate_proxy_classes: %phraseanet.debug% + auto_mapping: true + cache: + query: array + result: array + metadata: array + + log: + enable: false + type: monolog + handler: rotate + output: json + filename: doctrine-query.log + max_day: 10 + +# Monolog LOG Configuration +monolog: + output: yaml + handlers: + main: + type: stream + level: debug + rotate: + type: rotatingFile + level: debug + max_day: 10 + +# Memchache Configuration +memcached: + host: 11211 + + + + + \ No newline at end of file diff --git a/lib/unitTest/Core/Configuration/confTestFiles/config_dev.yml b/lib/unitTest/Core/Configuration/confTestFiles/config_dev.yml new file mode 100644 index 0000000000..34724fcc33 --- /dev/null +++ b/lib/unitTest/Core/Configuration/confTestFiles/config_dev.yml @@ -0,0 +1,19 @@ +## YAML Template. +--- +extends: main + +phraseanet: + debug: true + + +doctrine: + orm: + cache: + query: array + result: array + metadata: array + log: + enable: true + output: json + rotate: + max_day: 2 \ No newline at end of file diff --git a/lib/unitTest/Core/Configuration/confTestFiles/config_oneenv.yml b/lib/unitTest/Core/Configuration/confTestFiles/config_oneenv.yml new file mode 100644 index 0000000000..68a2b380bd --- /dev/null +++ b/lib/unitTest/Core/Configuration/confTestFiles/config_oneenv.yml @@ -0,0 +1,2 @@ +## YAML Template. +--- diff --git a/lib/unitTest/Core/Configuration/confTestFiles/config_prod.yml b/lib/unitTest/Core/Configuration/confTestFiles/config_prod.yml new file mode 100644 index 0000000000..893618d1b6 --- /dev/null +++ b/lib/unitTest/Core/Configuration/confTestFiles/config_prod.yml @@ -0,0 +1,12 @@ +## YAML Template. +--- + +# Doctrine Configuration +doctrine: + orm: + cache: + query: apc + result: memcached + metadata: apc + log: + enable: true \ No newline at end of file diff --git a/lib/unitTest/Core/Configuration/confTestFiles/config_test.yml b/lib/unitTest/Core/Configuration/confTestFiles/config_test.yml new file mode 100644 index 0000000000..5f080b61bb --- /dev/null +++ b/lib/unitTest/Core/Configuration/confTestFiles/config_test.yml @@ -0,0 +1,10 @@ +## YAML Template. +--- + +extends: dev + +doctrine: + dbal: + driver: pdo_sqlite + path: /Users/nicolasl/workspace/phraseanet/lib/unitTest/tests.sqlite + charset: UTF8 \ No newline at end of file diff --git a/lib/unitTest/Core/Configuration/confTestFiles/extends_non_existing_file.yml b/lib/unitTest/Core/Configuration/confTestFiles/extends_non_existing_file.yml new file mode 100644 index 0000000000..b0de733d80 --- /dev/null +++ b/lib/unitTest/Core/Configuration/confTestFiles/extends_non_existing_file.yml @@ -0,0 +1,5 @@ +## YAML Template. +--- + + +extends: unknow \ No newline at end of file diff --git a/lib/unitTest/Core/Configuration/confTestFiles/good.yml b/lib/unitTest/Core/Configuration/confTestFiles/good.yml new file mode 100644 index 0000000000..824f4d1759 --- /dev/null +++ b/lib/unitTest/Core/Configuration/confTestFiles/good.yml @@ -0,0 +1,60 @@ +## YAML Template. +--- +phraseanet: + servername: http://dev.phrasea.net/ + maintenance: false + debug: false + display_errors: false + +# Twig Configuration +twig: + debug: false + strict_variables: true + +# Doctrine Configuration +doctrine: + dbal: + driver: pdo_mysql + host: localhost + port: 3306 + dbname: ab_trunk + user: root + password: nicolas007 + charset: UTF8 + + orm: + auto_generate_proxy_classes: %phraseanet.debug% + auto_mapping: true + cache: + query: array + result: array + metadata: array + + log: + enable: true + type: monolog + handler: rotate + output: json + filename: doctrine-query.log + max_day: 10 + +# Monolog LOG Configuration +monolog: + output: yaml + handlers: + main: + type: stream + level: debug + rotate: + type: rotatingFile + level: debug + max_day: 10 + +# Memchache Configuration +memcached: + host: 11211 + + + + + \ No newline at end of file diff --git a/lib/unitTest/Core/Configuration/confTestFiles/good_no_output.yml b/lib/unitTest/Core/Configuration/confTestFiles/good_no_output.yml new file mode 100644 index 0000000000..22907c6a1f --- /dev/null +++ b/lib/unitTest/Core/Configuration/confTestFiles/good_no_output.yml @@ -0,0 +1,59 @@ +## YAML Template. +--- +phraseanet: + servername: http://dev.phrasea.net/ + maintenance: false + debug: false + display_errors: false + +# Twig Configuration +twig: + debug: false + strict_variables: true + +# Doctrine Configuration +doctrine: + dbal: + driver: pdo_mysql + host: localhost + port: 3306 + dbname: ab_trunk + user: root + password: nicolas007 + charset: UTF8 + + orm: + auto_generate_proxy_classes: %phraseanet.debug% + auto_mapping: true + cache: + query: array + result: array + metadata: array + + log: + enable: true + type: monolog + handler: rotate + filename: doctrine-query.log + max_day: 10 + +# Monolog LOG Configuration +monolog: + output: yaml + handlers: + main: + type: stream + level: debug + rotate: + type: rotatingFile + level: debug + max_day: 10 + +# Memchache Configuration +memcached: + host: 11211 + + + + + \ No newline at end of file diff --git a/lib/unitTest/Core/Configuration/confTestFiles/good_with_no_logger_output.yml b/lib/unitTest/Core/Configuration/confTestFiles/good_with_no_logger_output.yml new file mode 100644 index 0000000000..22907c6a1f --- /dev/null +++ b/lib/unitTest/Core/Configuration/confTestFiles/good_with_no_logger_output.yml @@ -0,0 +1,59 @@ +## YAML Template. +--- +phraseanet: + servername: http://dev.phrasea.net/ + maintenance: false + debug: false + display_errors: false + +# Twig Configuration +twig: + debug: false + strict_variables: true + +# Doctrine Configuration +doctrine: + dbal: + driver: pdo_mysql + host: localhost + port: 3306 + dbname: ab_trunk + user: root + password: nicolas007 + charset: UTF8 + + orm: + auto_generate_proxy_classes: %phraseanet.debug% + auto_mapping: true + cache: + query: array + result: array + metadata: array + + log: + enable: true + type: monolog + handler: rotate + filename: doctrine-query.log + max_day: 10 + +# Monolog LOG Configuration +monolog: + output: yaml + handlers: + main: + type: stream + level: debug + rotate: + type: rotatingFile + level: debug + max_day: 10 + +# Memchache Configuration +memcached: + host: 11211 + + + + + \ No newline at end of file diff --git a/lib/unitTest/Core/Configuration/confTestFiles/test.json b/lib/unitTest/Core/Configuration/confTestFiles/test.json new file mode 100644 index 0000000000..43133b13c7 --- /dev/null +++ b/lib/unitTest/Core/Configuration/confTestFiles/test.json @@ -0,0 +1,12 @@ +{ + "meta": { + "api_version": "1.0", + "request": "GET /api/v1/feeds/288/content/", + "response_time": "2011-07-27T15:52:04+02:00", + "http_code": 200, + "error_message": null, + "error_details": null, + "charset": "UTF-8" + }, + "response": {} +} \ No newline at end of file diff --git a/lib/unitTest/Core/Service/DoctrineTest.php b/lib/unitTest/Core/Service/DoctrineTest.php new file mode 100644 index 0000000000..f6a168514b --- /dev/null +++ b/lib/unitTest/Core/Service/DoctrineTest.php @@ -0,0 +1,87 @@ +getMock( + '\Alchemy\Phrasea\Core\Configuration\Application' + , array('getMainConfigurationFile') + ); + + $fileName = __DIR__ . '/../Configuration/confTestFiles/good.yml'; + + $spec->expects($this->any()) + ->method('getMainConfigurationFile') + ->will( + $this->returnValue( + new SplFileObject($fileName) + ) + ); + + $handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml()); + + $environnement = 'main'; + $configuration = new PhraseaCore\Configuration($environnement, $handler); + + $doctrineService = new Doctrine(); + $doctrineService = new Doctrine($configuration->getDoctrine()); + } + catch (Exception $e) + { + $this->fail($e->getMessage()); + } + } + + public function testGetVersion() + { + $doctrineService = new Doctrine(); + $this->assertTrue(is_string($doctrineService->getVersion())); + } + + public function testGetEntityManager() + { + $doctrineService = new Doctrine(); + $this->assertInstanceOf('\Doctrine\ORM\EntityManager', $doctrineService->getEntityManager()); + } + +} \ No newline at end of file diff --git a/lib/unitTest/Core/VersionTest.php b/lib/unitTest/Core/VersionTest.php new file mode 100644 index 0000000000..d602d022cc --- /dev/null +++ b/lib/unitTest/Core/VersionTest.php @@ -0,0 +1,48 @@ +assertTrue(is_string(Version::getName())); + } + + public function testGetName() + { + $this->assertTrue(is_string(Version::getNumber())); + } +} \ No newline at end of file