diff --git a/hudson/InstallDBs.yml b/hudson/InstallDBs.yml new file mode 100644 index 0000000000..218e135cd6 --- /dev/null +++ b/hudson/InstallDBs.yml @@ -0,0 +1,7 @@ +database: + host: localhost + port: port + user: phraseaUnitTests + password: iWvGxPE8 + applicationBox: ab_unitTests + dataBox: db_unitTests \ No newline at end of file diff --git a/lib/Alchemy/Phrasea/Controller/Setup/Installer.php b/lib/Alchemy/Phrasea/Controller/Setup/Installer.php index 3348e4819d..cb85c47ae9 100644 --- a/lib/Alchemy/Phrasea/Controller/Setup/Installer.php +++ b/lib/Alchemy/Phrasea/Controller/Setup/Installer.php @@ -263,10 +263,14 @@ class Installer implements ControllerProviderInterface $user = \User_Adapter::create($appbox, $request->get('email'), $request->get('password'), $request->get('email'), true); - if (!\p4string::hasAccent($databox_name)) + \phrasea::start($app['Core']); + + $auth = new \Session_Authentication_None($user); + + $appbox->get_session()->authenticate($auth); + + if ($databox_name && !\p4string::hasAccent($databox_name)) { - if ($databox_name) - { $template = new \system_file(__DIR__ . '/../../../../conf.d/data_templates/' . $request->get('db_template') . '.xml'); $databox = \databox::create($appbox, $connbas, $template, $registry); $user->ACL() @@ -329,15 +333,8 @@ class Installer implements ControllerProviderInterface break; } } - } } - \phrasea::start($app['Core']); - - $auth = new \Session_Authentication_None($user); - - $appbox->get_session()->authenticate($auth); - $redirection = '/admin/?section=taskmanager¬ice=install_success'; return $app->redirect($redirection); diff --git a/lib/classes/base.class.php b/lib/classes/base.class.php index f5d87a5270..1e68e73822 100644 --- a/lib/classes/base.class.php +++ b/lib/classes/base.class.php @@ -162,6 +162,19 @@ abstract class base implements cache_cacheableInterface return $this->connection; } + /** + * Replaces the connection + * + * @param \connection_pdo $connection + * @return \base + */ + public function set_connection(\connection_pdo $connection) + { + $this->connection = $connection; + + return $this; + } + public function get_cache() { if (!$this->cache) diff --git a/lib/classes/phrasea.class.php b/lib/classes/phrasea.class.php index cfc2856d13..594a072942 100644 --- a/lib/classes/phrasea.class.php +++ b/lib/classes/phrasea.class.php @@ -121,7 +121,7 @@ class phrasea printf("Missing Extension php-phrasea"); if (function_exists('phrasea_conn')) - if (phrasea_conn($hostname, $port, $user, $password, $dbname) !== true) + if (phrasea_conn($hostname, (int) $port, $user, $password, $dbname) !== true) self::headers(500); } diff --git a/lib/unitTest/Alchemy/Phrasea/Application/SetupTest.php b/lib/unitTest/Alchemy/Phrasea/Application/SetupTest.php index 5a1b51acd6..eed36c7f24 100644 --- a/lib/unitTest/Alchemy/Phrasea/Application/SetupTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Application/SetupTest.php @@ -1,35 +1,161 @@ root = __DIR__ . '/../../../../../'; + $this->client = $this->createClient(); + $this->temporaryUnInstall(); + $this->appbox = appbox::get_instance(\bootstrap::getCore()); + $this->connection = $this->appbox->get_connection(); + } - public function setUp() - { - parent::setUp(); - $this->client = $this->createClient(); - } + public function tearDown() + { + $this->temporaryReInstall(); + $this->appbox->set_connection($this->connection); + parent::tearDown(); + } - public function testRouteSlash() - { - $crawler = $this->client->request('GET', '/'); - $response = $this->client->getResponse(); - $this->assertEquals(302, $response->getStatusCode()); - $this->assertEquals('/login/', $response->headers->get('location')); - } + /** + * @covers Alchemy\Phrasea\Controller\Setup\Installer::connect + */ + public function testRouteSlash() + { + $crawler = $this->client->request('GET', '/'); + $response = $this->client->getResponse(); + $this->assertEquals(302, $response->getStatusCode()); + $this->assertEquals('/setup/installer/', $response->headers->get('location')); + $this->temporaryReInstall(); + + $crawler = $this->client->request('GET', '/'); + $response = $this->client->getResponse(); + $this->assertEquals(302, $response->getStatusCode()); + $this->assertEquals('/login/', $response->headers->get('location')); + } + + /** + * @covers Alchemy\Phrasea\Controller\Setup\Installer::connect + */ + public function testRouteSetupInstaller() + { + $crawler = $this->client->request('GET', '/installer/'); + $response = $this->client->getResponse(); + $this->assertEquals(302, $response->getStatusCode()); + $this->assertEquals('/setup/installer/step2/', $response->headers->get('location')); + } + + /** + * @covers Alchemy\Phrasea\Controller\Setup\Installer::connect + */ + public function testRouteSetupInstallerStep2() + { + $crawler = $this->client->request('GET', '/installer/step2/'); + $response = $this->client->getResponse(); + $this->assertEquals(200, $response->getStatusCode()); + } + + /** + * @covers Alchemy\Phrasea\Controller\Setup\Installer::connect + */ + public function testRouteSetupInstallerInstall() + { + + $settings = Symfony\Component\Yaml\Yaml::parse(file_get_contents($this->root . 'hudson/InstallDBs.yml')); + + $settings = $settings['database']; + + $host = isset($settings['host']) ? $settings['host'] : 'localhost'; + $port = isset($settings['port']) ? $settings['port'] : '3306'; + $MySQLuser = isset($settings['user']) ? $settings['user'] : 'root'; + $MySQLpassword = isset($settings['password']) ? $settings['password'] : ''; + $abName = isset($settings['applicationBox']) ? $settings['applicationBox'] : null; + $dbName = isset($settings['dataBox']) ? $settings['dataBox'] : null; + + + $connection = new connection_pdo('unitTestsAB', $host, $port, $MySQLuser, $MySQLpassword, $abName); + + $this->appbox->set_connection($connection); + + $dataDir = sys_get_temp_dir() . '/datainstall/'; + + $params = array( + 'email' => 'user@example.org', + 'password' => 'prètty%%password', + 'binary_xpdf' => '/path/to/xpdf', + 'binary_mplayer' => '/path/to/mplayer', + 'binary_MP4Box' => '/path/to/MP4Box', + 'binary_ffmpeg' => '/path/to/ffmpeg', + 'binary_unoconv' => '/path/to/unoconv', + 'binary_swfrender' => '/path/to/swfrender', + 'binary_pdf2swf' => '/path/to/pdf2swf', + 'binary_swfextract' => '/path/to/swfextract', + 'binary_exiftool' => '/path/to/exiftool', + 'binary_composite' => '/path/to/composite', + 'binary_convert' => '/path/to/convert', + 'binary_php' => '/path/to/php', + 'mount_point_web' => 'web', + 'datapath_web' => $dataDir . 'web', + 'datapath_noweb' => $dataDir . 'noweb', + 'ab_hostname' => $host, + 'ab_port' => $port, + 'ab_user' => $MySQLuser, + 'ab_password' => $MySQLpassword, + 'ab_name' => $abName, + 'db_name' => $dbName, + 'db_template' => 'en-simple', + 'create_task' => array(), + 'binary_phraseanet_indexer' => '/path/to/phraseanet_indexer', + ); + + $crawler = $this->client->request('POST', '/installer/install/', $params); + $response = $this->client->getResponse(); + + $this->assertEquals(302, $response->getStatusCode()); + $this->assertTrue(false === strpos($response->headers->get('location'), '/setup/installer/')); + } + + public function temporaryUnInstall() + { + if (file_exists($this->root . 'config/config.yml')) { + rename($this->root . 'config/config.yml', $this->root . 'config/config.yml.unitTests'); + } + if (file_exists($this->root . 'config/services.yml')) { + rename($this->root . 'config/services.yml', $this->root . 'config/services.yml.unitTests'); + } + if (file_exists($this->root . 'config/connexions.yml')) { + rename($this->root . 'config/connexions.yml', $this->root . 'config/connexions.yml.unitTests'); + } + } + + public function temporaryReInstall() + { + if (file_exists($this->root . 'config/config.yml.unitTests')) { + rename($this->root . 'config/config.yml.unitTests', $this->root . 'config/config.yml'); + } + if (file_exists($this->root . 'config/services.yml.unitTests')) { + rename($this->root . 'config/services.yml.unitTests', $this->root . 'config/services.yml'); + } + if (file_exists($this->root . 'config/connexions.yml.unitTests')) { + rename($this->root . 'config/connexions.yml.unitTests', $this->root . 'config/connexions.yml'); + } + } }