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 Doctrine\Common\DataFixtures\Loader;
|
||||
use Silex\WebTestCase;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\HttpKernel\Client;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
@@ -99,8 +100,6 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
|
||||
|
||||
self::createSetOfUserTests();
|
||||
|
||||
// self::giveRightsToUser(self::$user);
|
||||
|
||||
self::setCollection();
|
||||
|
||||
self::generateRecords();
|
||||
@@ -552,8 +551,6 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
|
||||
unlink(Setup_Upgrade::get_lock_file());
|
||||
}
|
||||
|
||||
self::activateEM();
|
||||
|
||||
$upgrader = new Setup_Upgrade(self::$application);
|
||||
// $appbox->forceUpgrade($upgrader, self::$application);
|
||||
unset($upgrader);
|
||||
@@ -580,6 +577,8 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
|
||||
self::$updated = true;
|
||||
}
|
||||
|
||||
self::activateEM();
|
||||
|
||||
set_time_limit(3600);
|
||||
|
||||
return;
|
||||
@@ -809,6 +808,8 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
|
||||
|
||||
return \record_adapter::createFromFile($file, $app);
|
||||
});
|
||||
|
||||
self::giveRightsToUser(self::$user);
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -835,7 +836,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
|
||||
|
||||
if (self::$recordsInitialized !== false) {
|
||||
foreach (self::$recordsInitialized as $i) {
|
||||
static::$records['record_' . $i]->delete();
|
||||
// static::$records['record_' . $i]->delete();
|
||||
}
|
||||
|
||||
self::$recordsInitialized = array();
|
||||
@@ -843,4 +844,12 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
|
||||
|
||||
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()
|
||||
{
|
||||
parent::setUp();
|
||||
$appbox = self::$application['phraseanet.appbox'];
|
||||
$session = $appbox->get_session();
|
||||
$auth = new Session_Authentication_None(self::$user);
|
||||
$session->authenticate($auth);
|
||||
self::$application->openAccount($auth);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$appbox = self::$application['phraseanet.appbox'];
|
||||
$session = $appbox->get_session();
|
||||
$session->logout();
|
||||
self::$application->closeAccount();
|
||||
parent::tearDown();
|
||||
}
|
||||
}
|
||||
|
@@ -9,21 +9,18 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
abstract class PhraseanetWebTestCaseAuthenticatedAbstract extends PhraseanetPHPUnitAuthenticatedAbstract
|
||||
{
|
||||
protected $StubbedACL;
|
||||
protected static $createdDataboxes = array();
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
$appbox = self::$application['phraseanet.appbox'];
|
||||
$session = $appbox->get_session();
|
||||
$auth = new Session_Authentication_None(self::$user);
|
||||
$session->authenticate($auth);
|
||||
self::$application->openAccount($auth);
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
$appbox = self::$application['phraseanet.appbox'];
|
||||
$session = $appbox->get_session();
|
||||
$session->logout();
|
||||
self::$application->closeAccount();
|
||||
parent::tearDownAfterClass();
|
||||
}
|
||||
|
||||
@@ -39,7 +36,7 @@ abstract class PhraseanetWebTestCaseAuthenticatedAbstract extends PhraseanetPHPU
|
||||
public function setAdmin($bool)
|
||||
{
|
||||
$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()
|
||||
->getMock();
|
||||
|
||||
@@ -67,10 +64,22 @@ abstract class PhraseanetWebTestCaseAuthenticatedAbstract extends PhraseanetPHPU
|
||||
->method('has_right_on_sbas')
|
||||
->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())
|
||||
->method('has_right')
|
||||
->will($this->returnValue($bool));
|
||||
|
||||
$this->StubbedACL->expects($this->any())
|
||||
->method('has_access_to_module')
|
||||
->will($this->returnValue($bool));
|
||||
|
||||
$this->StubbedACL->expects($this->any())
|
||||
->method('get_granted_base')
|
||||
->will($this->returnValue(array(self::$collection)));
|
||||
@@ -83,8 +92,76 @@ abstract class PhraseanetWebTestCaseAuthenticatedAbstract extends PhraseanetPHPU
|
||||
->method('ACL')
|
||||
->will($this->returnValue($this->StubbedACL));
|
||||
|
||||
$stubAuthenticatedUser->expects($this->any())
|
||||
->method('get_id')
|
||||
->will($this->returnValue(self::$user->get_id()));
|
||||
|
||||
self::$application['phraseanet.user'] = $stubAuthenticatedUser;
|
||||
|
||||
$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
|
||||
|
||||
require_once dirname(__FILE__) . '/../lib/classes/bootstrap.class.php';
|
||||
|
||||
return bootstrap::execute('test');
|
||||
require dirname(__FILE__) . '/../lib/bootstrap.php';
|
||||
|
Reference in New Issue
Block a user