Add setup tests

Fix setup process
This commit is contained in:
Romain Neutron
2012-05-03 14:54:00 +02:00
parent 1feae6a254
commit b539d86ad2
5 changed files with 176 additions and 33 deletions

7
hudson/InstallDBs.yml Normal file
View File

@@ -0,0 +1,7 @@
database:
host: localhost
port: port
user: phraseaUnitTests
password: iWvGxPE8
applicationBox: ab_unitTests
dataBox: db_unitTests

View File

@@ -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&notice=install_success';
return $app->redirect($redirection);

View File

@@ -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)

View File

@@ -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);
}

View File

@@ -1,35 +1,161 @@
<?php
require_once __DIR__ . '/../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/../../../../Alchemy/Phrasea/Application/Setup.php';
require_once __DIR__ . '/../../../PhraseanetWebTestCaseAbstract.class.inc';
use Silex\WebTestCase;
use Symfony\Component\HttpFoundation\Response;
class ApplicationSetupTest extends PhraseanetWebTestCaseAuthenticatedAbstract
class ApplicationSetupTest extends PhraseanetWebTestCaseAbstract
{
protected $client;
protected $root;
protected $appbox;
protected $connection;
protected $client;
protected static $need_records = false;
public function createApplication()
{
return require __DIR__ . '/../../../../Alchemy/Phrasea/Application/Setup.php';
}
public function createApplication()
{
return require __DIR__ . '/../../../../Alchemy/Phrasea/Application/Setup.php';
}
public function setUp()
{
parent::setUp();
$this->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');
}
}
}