diff --git a/tests/PhraseanetPHPUnitAbstract.class.inc b/tests/PhraseanetPHPUnitAbstract.class.inc index 34c62b5fdb..7d789ecd78 100644 --- a/tests/PhraseanetPHPUnitAbstract.class.inc +++ b/tests/PhraseanetPHPUnitAbstract.class.inc @@ -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']); + } } diff --git a/tests/PhraseanetPHPUnitAuthenticatedAbstract.class.inc b/tests/PhraseanetPHPUnitAuthenticatedAbstract.class.inc index 7c6078bdd3..59f3d47cec 100644 --- a/tests/PhraseanetPHPUnitAuthenticatedAbstract.class.inc +++ b/tests/PhraseanetPHPUnitAuthenticatedAbstract.class.inc @@ -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(); } } diff --git a/tests/PhraseanetWebTestCaseAuthenticatedAbstract.class.inc b/tests/PhraseanetWebTestCaseAuthenticatedAbstract.class.inc index b5613c9656..e8eed67b12 100644 --- a/tests/PhraseanetWebTestCaseAuthenticatedAbstract.class.inc +++ b/tests/PhraseanetWebTestCaseAuthenticatedAbstract.class.inc @@ -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(); + } } diff --git a/tests/bootstrap.inc b/tests/bootstrap.inc index deff8c2f40..62fbbf85e5 100644 --- a/tests/bootstrap.inc +++ b/tests/bootstrap.inc @@ -1,5 +1,3 @@