mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
Update test framework
This commit is contained in:
@@ -5,6 +5,7 @@ require_once __DIR__ . "/PhraseanetPHPUnitListener.class.inc";
|
|||||||
use Alchemy\Phrasea\Application;
|
use Alchemy\Phrasea\Application;
|
||||||
use Doctrine\Common\DataFixtures\Loader;
|
use Doctrine\Common\DataFixtures\Loader;
|
||||||
use Silex\WebTestCase;
|
use Silex\WebTestCase;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
use Symfony\Component\HttpKernel\Client;
|
use Symfony\Component\HttpKernel\Client;
|
||||||
use Symfony\Component\DomCrawler\Crawler;
|
use Symfony\Component\DomCrawler\Crawler;
|
||||||
@@ -99,8 +100,6 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
|
|||||||
|
|
||||||
self::createSetOfUserTests();
|
self::createSetOfUserTests();
|
||||||
|
|
||||||
// self::giveRightsToUser(self::$user);
|
|
||||||
|
|
||||||
self::setCollection();
|
self::setCollection();
|
||||||
|
|
||||||
self::generateRecords();
|
self::generateRecords();
|
||||||
@@ -552,8 +551,6 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
|
|||||||
unlink(Setup_Upgrade::get_lock_file());
|
unlink(Setup_Upgrade::get_lock_file());
|
||||||
}
|
}
|
||||||
|
|
||||||
self::activateEM();
|
|
||||||
|
|
||||||
$upgrader = new Setup_Upgrade(self::$application);
|
$upgrader = new Setup_Upgrade(self::$application);
|
||||||
// $appbox->forceUpgrade($upgrader, self::$application);
|
// $appbox->forceUpgrade($upgrader, self::$application);
|
||||||
unset($upgrader);
|
unset($upgrader);
|
||||||
@@ -580,6 +577,8 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
|
|||||||
self::$updated = true;
|
self::$updated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self::activateEM();
|
||||||
|
|
||||||
set_time_limit(3600);
|
set_time_limit(3600);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -809,6 +808,8 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
|
|||||||
|
|
||||||
return \record_adapter::createFromFile($file, $app);
|
return \record_adapter::createFromFile($file, $app);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
self::giveRightsToUser(self::$user);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -835,7 +836,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
|
|||||||
|
|
||||||
if (self::$recordsInitialized !== false) {
|
if (self::$recordsInitialized !== false) {
|
||||||
foreach (self::$recordsInitialized as $i) {
|
foreach (self::$recordsInitialized as $i) {
|
||||||
static::$records['record_' . $i]->delete();
|
// static::$records['record_' . $i]->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
self::$recordsInitialized = array();
|
self::$recordsInitialized = array();
|
||||||
@@ -843,4 +844,12 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function assertXMLHTTPBadJsonResponse(Response $response)
|
||||||
|
{
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
$data = json_decode($response->getContent(), true);
|
||||||
|
$this->assertTrue(is_array($data));
|
||||||
|
$this->assertFalse($data['success']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,17 +12,13 @@ abstract class PhraseanetPHPUnitAuthenticatedAbstract extends PhraseanetPHPUnitA
|
|||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$appbox = self::$application['phraseanet.appbox'];
|
|
||||||
$session = $appbox->get_session();
|
|
||||||
$auth = new Session_Authentication_None(self::$user);
|
$auth = new Session_Authentication_None(self::$user);
|
||||||
$session->authenticate($auth);
|
self::$application->openAccount($auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
public function tearDown()
|
||||||
{
|
{
|
||||||
$appbox = self::$application['phraseanet.appbox'];
|
self::$application->closeAccount();
|
||||||
$session = $appbox->get_session();
|
|
||||||
$session->logout();
|
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,21 +9,18 @@ use Symfony\Component\HttpFoundation\Response;
|
|||||||
abstract class PhraseanetWebTestCaseAuthenticatedAbstract extends PhraseanetPHPUnitAuthenticatedAbstract
|
abstract class PhraseanetWebTestCaseAuthenticatedAbstract extends PhraseanetPHPUnitAuthenticatedAbstract
|
||||||
{
|
{
|
||||||
protected $StubbedACL;
|
protected $StubbedACL;
|
||||||
|
protected static $createdDataboxes = array();
|
||||||
|
|
||||||
public static function setUpBeforeClass()
|
public static function setUpBeforeClass()
|
||||||
{
|
{
|
||||||
parent::setUpBeforeClass();
|
parent::setUpBeforeClass();
|
||||||
$appbox = self::$application['phraseanet.appbox'];
|
|
||||||
$session = $appbox->get_session();
|
|
||||||
$auth = new Session_Authentication_None(self::$user);
|
$auth = new Session_Authentication_None(self::$user);
|
||||||
$session->authenticate($auth);
|
self::$application->openAccount($auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function tearDownAfterClass()
|
public static function tearDownAfterClass()
|
||||||
{
|
{
|
||||||
$appbox = self::$application['phraseanet.appbox'];
|
self::$application->closeAccount();
|
||||||
$session = $appbox->get_session();
|
|
||||||
$session->logout();
|
|
||||||
parent::tearDownAfterClass();
|
parent::tearDownAfterClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +36,7 @@ abstract class PhraseanetWebTestCaseAuthenticatedAbstract extends PhraseanetPHPU
|
|||||||
public function setAdmin($bool)
|
public function setAdmin($bool)
|
||||||
{
|
{
|
||||||
$stubAuthenticatedUser = $this->getMockBuilder('\User_Adapter')//, array('is_admin', 'ACL'), array(self::$application['phraseanet.user']->get_id(), self::$application))
|
$stubAuthenticatedUser = $this->getMockBuilder('\User_Adapter')//, array('is_admin', 'ACL'), array(self::$application['phraseanet.user']->get_id(), self::$application))
|
||||||
->setMethods(array('ACL'))
|
->setMethods(array('ACL', 'get_id'))
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
@@ -67,10 +64,22 @@ abstract class PhraseanetWebTestCaseAuthenticatedAbstract extends PhraseanetPHPU
|
|||||||
->method('has_right_on_sbas')
|
->method('has_right_on_sbas')
|
||||||
->will($this->returnValue($bool));
|
->will($this->returnValue($bool));
|
||||||
|
|
||||||
|
$this->StubbedACL->expects($this->any())
|
||||||
|
->method('has_access_to_sbas')
|
||||||
|
->will($this->returnValue($bool));
|
||||||
|
|
||||||
|
$this->StubbedACL->expects($this->any())
|
||||||
|
->method('has_access_to_base')
|
||||||
|
->will($this->returnValue($bool));
|
||||||
|
|
||||||
$this->StubbedACL->expects($this->any())
|
$this->StubbedACL->expects($this->any())
|
||||||
->method('has_right')
|
->method('has_right')
|
||||||
->will($this->returnValue($bool));
|
->will($this->returnValue($bool));
|
||||||
|
|
||||||
|
$this->StubbedACL->expects($this->any())
|
||||||
|
->method('has_access_to_module')
|
||||||
|
->will($this->returnValue($bool));
|
||||||
|
|
||||||
$this->StubbedACL->expects($this->any())
|
$this->StubbedACL->expects($this->any())
|
||||||
->method('get_granted_base')
|
->method('get_granted_base')
|
||||||
->will($this->returnValue(array(self::$collection)));
|
->will($this->returnValue(array(self::$collection)));
|
||||||
@@ -83,8 +92,76 @@ abstract class PhraseanetWebTestCaseAuthenticatedAbstract extends PhraseanetPHPU
|
|||||||
->method('ACL')
|
->method('ACL')
|
||||||
->will($this->returnValue($this->StubbedACL));
|
->will($this->returnValue($this->StubbedACL));
|
||||||
|
|
||||||
|
$stubAuthenticatedUser->expects($this->any())
|
||||||
|
->method('get_id')
|
||||||
|
->will($this->returnValue(self::$user->get_id()));
|
||||||
|
|
||||||
self::$application['phraseanet.user'] = $stubAuthenticatedUser;
|
self::$application['phraseanet.user'] = $stubAuthenticatedUser;
|
||||||
|
|
||||||
$this->client = new Client(self::$application, array());
|
$this->client = new Client(self::$application, array());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function createDatabox()
|
||||||
|
{
|
||||||
|
$registry = self::$application['phraseanet.registry'];
|
||||||
|
|
||||||
|
$this->createDatabase();
|
||||||
|
|
||||||
|
$configuration = self::$application['phraseanet.configuration'];
|
||||||
|
|
||||||
|
$choosenConnexion = $configuration->getPhraseanet()->get('database');
|
||||||
|
$connexion = $configuration->getConnexion($choosenConnexion);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$conn = new \connection_pdo('databox_creation', $connexion->get('host'), $connexion->get('port'), $connexion->get('user'), $connexion->get('password'), 'unit_test_db', array(), $registry);
|
||||||
|
} catch (\PDOException $e) {
|
||||||
|
|
||||||
|
$this->markTestSkipped('Could not reach DB');
|
||||||
|
}
|
||||||
|
|
||||||
|
$databox = \databox::create(
|
||||||
|
self::$application, $conn, new \SplFileInfo($registry->get('GV_RootPath') . 'lib/conf.d/data_templates/fr-simple.xml'), $registry
|
||||||
|
);
|
||||||
|
|
||||||
|
self::$createdDataboxes[] = $databox;
|
||||||
|
|
||||||
|
|
||||||
|
$rights = array(
|
||||||
|
'bas_manage' => '1'
|
||||||
|
, 'bas_modify_struct' => '1'
|
||||||
|
, 'bas_modif_th' => '1'
|
||||||
|
, 'bas_chupub' => '1'
|
||||||
|
);
|
||||||
|
|
||||||
|
self::$application['phraseanet.user']->ACL()->update_rights_to_sbas($databox->get_sbas_id(), $rights);
|
||||||
|
|
||||||
|
|
||||||
|
$databox->registerAdmin(self::$application['phraseanet.user']);
|
||||||
|
|
||||||
|
return $databox;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dropDatabase()
|
||||||
|
{
|
||||||
|
$stmt = self::$application['phraseanet.appbox']
|
||||||
|
->get_connection()
|
||||||
|
->prepare('DROP DATABASE IF EXISTS `unit_test_db`');
|
||||||
|
$stmt->execute();
|
||||||
|
$stmt = self::$application['phraseanet.appbox']
|
||||||
|
->get_connection()
|
||||||
|
->prepare('DELETE FROM sbas WHERE dbname = "unit_test_db"');
|
||||||
|
$stmt->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createDatabase()
|
||||||
|
{
|
||||||
|
self::dropDatabase();
|
||||||
|
|
||||||
|
$stmt = self::$application['phraseanet.appbox']
|
||||||
|
->get_connection()
|
||||||
|
->prepare('CREATE DATABASE `unit_test_db`
|
||||||
|
CHARACTER SET utf8 COLLATE utf8_unicode_ci');
|
||||||
|
$stmt->execute();
|
||||||
|
$stmt->closeCursor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,3 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once dirname(__FILE__) . '/../lib/classes/bootstrap.class.php';
|
require dirname(__FILE__) . '/../lib/bootstrap.php';
|
||||||
|
|
||||||
return bootstrap::execute('test');
|
|
||||||
|
Reference in New Issue
Block a user