mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
Love for unit tests
This commit is contained in:
@@ -11,18 +11,6 @@
|
||||
verbose="false"
|
||||
bootstrap="tests/bootstrap.php"
|
||||
>
|
||||
<!--
|
||||
<logging>
|
||||
<log type="coverage-html" target="tmp/phpunit_report/report" charset="UTF-8"
|
||||
yui="true" highlight="false"
|
||||
lowUpperBound="35" highLowerBound="70"/>
|
||||
<log type="coverage-clover" target="tmp/coverage.xml"/>
|
||||
<log type="json" target="tmp/phpunit_report/logfile.json"/>
|
||||
<log type="junit" target="tmp/phpunit_report/logfile.xml" logIncompleteSkipped="false"/>
|
||||
<log type="testdox-html" target="tmp/phpunit_report/testdox.html"/>
|
||||
<log type="testdox-text" target="tmp/phpunit_report/testdox.txt"/>
|
||||
</logging>
|
||||
-->
|
||||
<php>
|
||||
<ini name="display_errors" value="on"/>
|
||||
</php>
|
||||
@@ -40,10 +28,5 @@
|
||||
<directory>vendor</directory>
|
||||
</blacklist>
|
||||
</filter>
|
||||
|
||||
<listeners>
|
||||
<listener class="PhraseanetPHPUnitListener" file="tests/classes/PhraseanetPHPUnitListener.php"></listener>
|
||||
</listeners>
|
||||
|
||||
</phpunit>
|
||||
|
||||
|
@@ -13,53 +13,38 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
abstract class ApiTestCase extends \PhraseanetWebTestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var Client
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* @var \API_OAuth2_Token
|
||||
*/
|
||||
private static $token;
|
||||
private static $APIrecord;
|
||||
protected $record;
|
||||
|
||||
/**
|
||||
* @var \API_OAuth2_Account
|
||||
*/
|
||||
private static $account;
|
||||
|
||||
/**
|
||||
* @var \API_OAuth2_Application
|
||||
*/
|
||||
private static $oauthApplication;
|
||||
|
||||
/**
|
||||
* @var \API_OAuth2_Token
|
||||
*/
|
||||
private static $adminToken;
|
||||
|
||||
/**
|
||||
* @var \API_OAuth2_Account
|
||||
*/
|
||||
private static $adminAccount;
|
||||
|
||||
/**
|
||||
* @var \API_OAuth2_Application
|
||||
*/
|
||||
private static $adminApplication;
|
||||
private static $databoxe_ids = [];
|
||||
private static $apiInitialized = false;
|
||||
|
||||
abstract public function getParameters(array $parameters = []);
|
||||
|
||||
abstract public function unserialize($data);
|
||||
|
||||
abstract public function getAcceptMimeType();
|
||||
|
||||
private static $apiInitialized = false;
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->unsetToken();
|
||||
@@ -86,14 +71,6 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
|
||||
self::$adminToken = self::$adminAccount->get_token()->get_value();
|
||||
self::$apiInitialized = true;
|
||||
}
|
||||
|
||||
if (!self::$APIrecord) {
|
||||
$file = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess(__DIR__ . '/../../../../files/test024.jpg'), self::$DI['collection']);
|
||||
self::$APIrecord = \record_adapter::createFromFile($file, self::$DI['app']);
|
||||
self::$APIrecord->generate_subdefs(self::$APIrecord->get_databox(), self::$DI['app']);
|
||||
}
|
||||
|
||||
$this->record = self::$APIrecord;
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
@@ -107,10 +84,11 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
|
||||
self::$adminApplication->delete();
|
||||
}
|
||||
|
||||
self::$APIrecord->delete();
|
||||
self::$APIrecord = null;
|
||||
|
||||
self::$apiInitialized = false;
|
||||
self::$databoxe_ids = [];
|
||||
|
||||
self::$token = self::$account = self::$oauthApplication = self::$adminToken
|
||||
= self::$adminAccount = self::$adminApplication = null;
|
||||
|
||||
parent::tearDownAfterClass();
|
||||
}
|
||||
@@ -1040,9 +1018,9 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
|
||||
$keys = array_keys($this->record->get_subdefs());
|
||||
$keys = array_keys(self::$DI['record_1']->get_subdefs());
|
||||
|
||||
$route = '/api/v1/records/' . $this->record->get_sbas_id() . '/' . $this->record->get_record_id() . '/embed/';
|
||||
$route = '/api/v1/records/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/embed/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, ['POST', 'PUT', 'DELETE']);
|
||||
|
||||
self::$DI['client']->request('GET', $route, $this->getParameters(), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
|
||||
@@ -1054,7 +1032,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
|
||||
$this->assertArrayHasKey('embed', $content['response']);
|
||||
|
||||
foreach ($content['response']['embed'] as $embed) {
|
||||
$this->checkEmbed($embed, $this->record);
|
||||
$this->checkEmbed($embed, self::$DI['record_1']);
|
||||
}
|
||||
$route = '/api/v1/records/24892534/51654651553/embed/';
|
||||
$this->evaluateNotFoundRoute($route, ['GET']);
|
||||
@@ -1073,11 +1051,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
|
||||
$story = \record_adapter::createStory(self::$DI['app'], self::$DI['collection']);
|
||||
$media = self::$DI['app']['mediavorus']->guess(__DIR__ . '/../../../../files/cestlafete.jpg');
|
||||
$story->substitute_subdef('preview', $media, self::$DI['app']);
|
||||
$story->substitute_subdef('thumbnail', $media, self::$DI['app']);
|
||||
|
||||
$story = self::$DI['record_story_1'];
|
||||
$keys = array_keys($story->get_subdefs());
|
||||
|
||||
$route = '/api/v1/stories/' . $story->get_sbas_id() . '/' . $story->get_record_id() . '/embed/';
|
||||
@@ -1100,7 +1074,6 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
|
||||
$route = '/api/v1/stories/any_bad_id/sfsd5qfsd5/embed/';
|
||||
$this->evaluateBadRequestRoute($route, ['GET']);
|
||||
$this->evaluateMethodNotAllowedRoute($route, ['POST', 'PUT', 'DELETE']);
|
||||
$story->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1110,7 +1083,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
|
||||
$route = '/api/v1/records/' . $this->record->get_sbas_id() . '/' . $this->record->get_record_id() . '/embed/';
|
||||
$route = '/api/v1/records/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/embed/';
|
||||
|
||||
self::$DI['client']->request('GET', $route, $this->getParameters(['mimes' => ['image/jpg', 'image/jpeg']]), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
|
||||
$content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
|
||||
@@ -1118,7 +1091,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
|
||||
$this->assertArrayHasKey('embed', $content['response']);
|
||||
|
||||
foreach ($content['response']['embed'] as $embed) {
|
||||
$this->checkEmbed($embed, $this->record);
|
||||
$this->checkEmbed($embed, self::$DI['record_1']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1175,8 +1148,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
|
||||
$file = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess(__DIR__ . '/../../../../files/test001.jpg'), self::$DI['collection']);
|
||||
$record = \record_adapter::createFromFile($file, self::$DI['app']);
|
||||
$record = self::$DI['record_1'];
|
||||
|
||||
$route = '/api/v1/records/' . $record->get_sbas_id() . '/' . $record->get_record_id() . '/setmetadatas/';
|
||||
$caption = $record->get_caption();
|
||||
@@ -1287,6 +1259,8 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
|
||||
foreach ($status_bits as $n => $datas) {
|
||||
$this->assertEquals(substr($record_status, ($n), 1), $tochange[$n]);
|
||||
}
|
||||
|
||||
self::$DI['record_1']->set_binary_status(str_repeat('0', 32));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -22,14 +22,9 @@ class oauthv2_application_test extends \PhraseanetAuthenticatedWebTestCase
|
||||
protected $client;
|
||||
protected $queryParameters;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
public function bootTestCase()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
$environment = 'test';
|
||||
$application = require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Api.php';
|
||||
|
||||
self::$appli = \API_OAuth2_Application::create($application, self::$DI['user'], 'test');
|
||||
self::$appli = \API_OAuth2_Application::create(self::$DI['app'], self::$DI['user'], 'test');
|
||||
self::$appli->set_description('une description')
|
||||
->set_redirect_uri('http://callback.com/callback/')
|
||||
->set_website('http://website.com/')
|
||||
@@ -41,6 +36,7 @@ class oauthv2_application_test extends \PhraseanetAuthenticatedWebTestCase
|
||||
if (self::$appli !== false) {
|
||||
self::deleteInsertedRow(self::$DI['app']['phraseanet.appbox'], self::$appli);
|
||||
}
|
||||
self::$appli = null;
|
||||
parent::tearDownAfterClass();
|
||||
}
|
||||
|
||||
|
@@ -2,14 +2,13 @@
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\Application;
|
||||
|
||||
use Alchemy\Phrasea\Border\File;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
|
||||
class OverviewTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
{
|
||||
public function testDatafilesRouteAuthenticated()
|
||||
{
|
||||
$crawler = self::$DI['client']->request('GET', '/datafiles/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/preview/');
|
||||
self::$DI['client']->request('GET', '/datafiles/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/preview/');
|
||||
$response = self::$DI['client']->getResponse();
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
@@ -31,11 +30,7 @@ class OverviewTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$tmp = tempnam(sys_get_temp_dir(), 'testEtag');
|
||||
copy(__DIR__ . '/../../../../files/cestlafete.jpg', $tmp);
|
||||
|
||||
$media = self::$DI['app']['mediavorus']->guess($tmp);
|
||||
|
||||
$file = new File(self::$DI['app'], $media, self::$DI['collection']);
|
||||
$record = \record_adapter::createFromFile($file, self::$DI['app']);
|
||||
|
||||
$record = self::$DI['record_1'];
|
||||
$record->generate_subdefs($record->get_databox(), self::$DI['app']);
|
||||
|
||||
$crawler = self::$DI['client']->request('GET', '/datafiles/' . $record->get_sbas_id() . '/' . $record->get_record_id() . '/preview/');
|
||||
@@ -132,7 +127,7 @@ class OverviewTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$token = "unexisting_token";
|
||||
$url = '/permalink/v1/' . self::$DI['record_1']->get_sbas_id() . "/" . self::$DI['record_1']->get_record_id() . '/caption/?token='.$token;
|
||||
|
||||
$crawler = self::$DI['client']->request('GET', $url);
|
||||
self::$DI['client']->request('GET', $url);
|
||||
$response = self::$DI['client']->getResponse();
|
||||
|
||||
$this->assertEquals(404, $response->getStatusCode());
|
||||
@@ -143,7 +138,7 @@ class OverviewTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$this->assertTrue(self::$DI['app']['authentication']->isAuthenticated());
|
||||
$url = '/permalink/v1/unexisting_record/unexisting_id/caption/?token=unexisting_token';
|
||||
|
||||
$crawler = self::$DI['client']->request('GET', $url);
|
||||
self::$DI['client']->request('GET', $url);
|
||||
$response = self::$DI['client']->getResponse();
|
||||
|
||||
$this->assertEquals(404, $response->getStatusCode());
|
||||
@@ -186,7 +181,7 @@ class OverviewTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$token = self::$DI['record_1']->get_thumbnail()->get_permalink()->get_token();
|
||||
$url = '/permalink/v1/' . self::$DI['record_1']->get_sbas_id() . "/" . self::$DI['record_1']->get_record_id() . '/caption/?token='.$token;
|
||||
|
||||
$crawler = self::$DI['client']->request('GET', $url);
|
||||
self::$DI['client']->request('GET', $url);
|
||||
$response = self::$DI['client']->getResponse();
|
||||
|
||||
foreach ($headers as $name => $value) {
|
||||
@@ -203,7 +198,7 @@ class OverviewTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$token = self::$DI['record_1']->get_preview()->get_permalink()->get_token();
|
||||
$url = '/permalink/v1/whateverIwannt/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/' . $token . '/preview/';
|
||||
|
||||
$crawler = self::$DI['client']->request('GET', $url);
|
||||
self::$DI['client']->request('GET', $url);
|
||||
$response = self::$DI['client']->getResponse();
|
||||
|
||||
foreach ($headers as $name => $value) {
|
||||
@@ -230,7 +225,7 @@ class OverviewTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$url = '/permalink/v1/whateverIwannt/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/' . $token . '/preview/';
|
||||
|
||||
$url = $url . 'view/';
|
||||
$crawler = self::$DI['client']->request('GET', $url);
|
||||
self::$DI['client']->request('GET', $url);
|
||||
$response = self::$DI['client']->getResponse();
|
||||
|
||||
foreach ($headers as $name => $value) {
|
||||
@@ -245,7 +240,7 @@ class OverviewTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$token = self::$DI['record_1']->get_preview()->get_permalink()->get_token();
|
||||
$url = '/permalink/v1/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/preview/whateverIwannt.jpg?token=' . $token . '';
|
||||
|
||||
$crawler = self::$DI['client']->request('GET', $url);
|
||||
self::$DI['client']->request('GET', $url);
|
||||
$response = self::$DI['client']->getResponse();
|
||||
|
||||
$this->assertRegExp('/^inline;/', $response->headers->get('content-disposition'));
|
||||
@@ -262,7 +257,7 @@ class OverviewTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$token = self::$DI['record_1']->get_preview()->get_permalink()->get_token();
|
||||
$url = '/permalink/v1/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/preview/?token=' . $token . '';
|
||||
|
||||
$crawler = self::$DI['client']->request('GET', $url);
|
||||
self::$DI['client']->request('GET', $url);
|
||||
$response = self::$DI['client']->getResponse();
|
||||
|
||||
foreach ($headers as $name => $value) {
|
||||
|
@@ -37,12 +37,7 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
self::$DI['app'] = new Application('test');
|
||||
|
||||
self::giveRightsToUser(self::$DI['app'], self::$DI['user']);
|
||||
self::$DI['app']['acl']->get(self::$DI['user'])->revoke_access_from_bases([self::$DI['collection_no_access']->get_base_id()]);
|
||||
self::$DI['app']['acl']->get(self::$DI['user'])->set_masks_on_base(self::$DI['collection_no_access_by_status']->get_base_id(), '0000000000000000000000000000000000000000000000000001000000000000', '0000000000000000000000000000000000000000000000000001000000000000', '0000000000000000000000000000000000000000000000000001000000000000', '0000000000000000000000000000000000000000000000000001000000000000');
|
||||
|
||||
self::resetUsersRights(self::$DI['app'], self::$DI['user']);
|
||||
parent::tearDownAfterClass();
|
||||
}
|
||||
|
||||
|
@@ -10,17 +10,6 @@ class ControllerBasketTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
{
|
||||
protected $client;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
self::$DI['app'] = new Application('test');
|
||||
|
||||
self::giveRightsToUser(self::$DI['app'], self::$DI['user']);
|
||||
self::$DI['app']['acl']->get(self::$DI['user'])->revoke_access_from_bases([self::$DI['collection_no_access']->get_base_id()]);
|
||||
self::$DI['app']['acl']->get(self::$DI['user'])->set_masks_on_base(self::$DI['collection_no_access_by_status']->get_base_id(), '0000000000000000000000000000000000000000000000000001000000000000', '0000000000000000000000000000000000000000000000000001000000000000', '0000000000000000000000000000000000000000000000000001000000000000', '0000000000000000000000000000000000000000000000000001000000000000');
|
||||
}
|
||||
|
||||
public function testRootPost()
|
||||
{
|
||||
self::$DI['record_1'];
|
||||
@@ -47,15 +36,12 @@ class ControllerBasketTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$response = self::$DI['client']->getResponse();
|
||||
|
||||
$query = self::$DI['app']['EM']->createQuery('SELECT COUNT(b.id) FROM \Alchemy\Phrasea\Model\Entities\Basket b');
|
||||
|
||||
$count = $query->getSingleScalarResult();
|
||||
|
||||
$this->assertEquals(1, $count);
|
||||
|
||||
$this->assertEquals(302, $response->getStatusCode());
|
||||
|
||||
$query = self::$DI['app']['EM']->createQuery('SELECT b FROM \Alchemy\Phrasea\Model\Entities\Basket b');
|
||||
|
||||
$result = $query->getResult();
|
||||
|
||||
$basket = array_shift($result);
|
||||
|
@@ -8,17 +8,6 @@ use Symfony\Component\CssSelector\CssSelector;
|
||||
|
||||
class FeedTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
self::$DI['app'] = new Application('test');
|
||||
|
||||
self::giveRightsToUser(self::$DI['app'], self::$DI['user']);
|
||||
self::$DI['app']['acl']->get(self::$DI['user'])->revoke_access_from_bases([self::$DI['collection_no_access']->get_base_id()]);
|
||||
self::$DI['app']['acl']->get(self::$DI['user'])->set_masks_on_base(self::$DI['collection_no_access_by_status']->get_base_id(), '0000000000000000000000000000000000000000000000000001000000000000', '0000000000000000000000000000000000000000000000000001000000000000', '0000000000000000000000000000000000000000000000000001000000000000', '0000000000000000000000000000000000000000000000000001000000000000');
|
||||
}
|
||||
|
||||
public function testRequestAvailable()
|
||||
{
|
||||
$feed = $this->insertOneFeed(self::$DI['user']);
|
||||
|
@@ -10,10 +10,7 @@ class TOUTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
$application = new Application('test');
|
||||
self::giveRightsToUser($application, self::$DI['user_alt2']);
|
||||
self::$DI['app']['acl']->get(self::$DI['user_alt2'])->revoke_access_from_bases([self::$DI['collection_no_access']->get_base_id()]);
|
||||
self::$DI['app']['acl']->get(self::$DI['user_alt2'])->set_masks_on_base(self::$DI['collection_no_access_by_status']->get_base_id(), '0000000000000000000000000000000000000000000000000001000000000000', '0000000000000000000000000000000000000000000000000001000000000000', '0000000000000000000000000000000000000000000000000001000000000000', '0000000000000000000000000000000000000000000000000001000000000000');
|
||||
self::resetUsersRights(self::$DI['app'], self::$DI['user_alt2']);
|
||||
parent::tearDownAfterClass();
|
||||
}
|
||||
|
||||
|
@@ -33,17 +33,6 @@ class UploadTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
self::$DI['app'] = new Application('test');
|
||||
|
||||
self::giveRightsToUser(self::$DI['app'], self::$DI['user']);
|
||||
self::$DI['app']['acl']->get(self::$DI['user'])->revoke_access_from_bases([self::$DI['collection_no_access']->get_base_id()]);
|
||||
self::$DI['app']['acl']->get(self::$DI['user'])->set_masks_on_base(self::$DI['collection_no_access_by_status']->get_base_id(), '0000000000000000000000000000000000000000000000000001000000000000', '0000000000000000000000000000000000000000000000000001000000000000', '0000000000000000000000000000000000000000000000000001000000000000', '0000000000000000000000000000000000000000000000000001000000000000');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Alchemy\Phrasea\Controller\Prod\Upload::getFlashUploadForm
|
||||
* @covers Alchemy\Phrasea\Controller\Prod\Upload::call
|
||||
|
@@ -8,18 +8,6 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class RecordsRequestTest extends \PhraseanetAuthenticatedTestCase
|
||||
{
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
self::$DI['app'] = new Application('test');
|
||||
|
||||
self::giveRightsToUser(self::$DI['app'], self::$DI['user']);
|
||||
self::$DI['app']['acl']->get(self::$DI['user'])->revoke_access_from_bases([self::$DI['collection_no_access']->get_base_id()]);
|
||||
self::$DI['app']['acl']->get(self::$DI['user'])->set_masks_on_base(self::$DI['collection_no_access_by_status']->get_base_id(), '0000000000000000000000000000000000000000000000000001000000000000', '0000000000000000000000000000000000000000000000000001000000000000', '0000000000000000000000000000000000000000000000000001000000000000', '0000000000000000000000000000000000000000000000000001000000000000');
|
||||
}
|
||||
|
||||
public function testSimple()
|
||||
{
|
||||
$request = new Request([
|
||||
|
@@ -9,12 +9,10 @@ class AccountTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
{
|
||||
private static $authorizedApp;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
public function bootTestCase()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
try {
|
||||
self::$authorizedApp = \API_OAuth2_Application::create(new Application('test'), self::$DI['user'], 'test API v1');
|
||||
self::$authorizedApp = \API_OAuth2_Application::create(self::$DI['app'], self::$DI['user'], 'test API v1');
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
|
@@ -8,14 +8,6 @@ use Alchemy\Tests\Phrasea\SearchEngine\ConfigurationPanelAbstractTest;
|
||||
|
||||
class PhraseaConfigurationPanelTest extends ConfigurationPanelAbstractTest
|
||||
{
|
||||
/**
|
||||
* @covers Alchemy\Phrasea\SearchEngine\Phrasea\ConfigurationPanel
|
||||
*/
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
}
|
||||
|
||||
public function getPanel()
|
||||
{
|
||||
return new ConfigurationPanel(new PhraseaEngine(self::$DI['app']), self::$DI['app']['configuration.store']);
|
||||
|
@@ -19,11 +19,6 @@ class PhraseaEngineTest extends SearchEngineAbstractTest
|
||||
}
|
||||
}
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
}
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
self::$searchEngine = PhraseaEngine::create(self::$DI['app']);
|
||||
|
@@ -8,14 +8,6 @@ use Alchemy\Tests\Phrasea\SearchEngine\ConfigurationPanelAbstractTest;
|
||||
|
||||
class SphinxSearchConfigurationPanelTest extends ConfigurationPanelAbstractTest
|
||||
{
|
||||
/**
|
||||
* @covers Alchemy\Phrasea\SearchEngine\SphinxSearch\ConfigurationPanel
|
||||
*/
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
}
|
||||
|
||||
public function getPanel()
|
||||
{
|
||||
return new ConfigurationPanel(new SphinxSearchEngine(self::$DI['app'], 'localhost', 9306, 'localhost', 9308), self::$DI['app']['configuration.store']);
|
||||
|
@@ -17,10 +17,8 @@ class SphinxSearchEngineTest extends SearchEngineAbstractTest
|
||||
/**
|
||||
* @covers Alchemy\Phrasea\SearchEngine\SphinxSearch\SphinxSearchEngine
|
||||
*/
|
||||
public static function setUpBeforeClass()
|
||||
public function bootTestCase()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
$binaryFinder = new ExecutableFinder();
|
||||
$indexer = $binaryFinder->find('indexer');
|
||||
|
||||
@@ -32,7 +30,7 @@ class SphinxSearchEngineTest extends SearchEngineAbstractTest
|
||||
return;
|
||||
}
|
||||
|
||||
$app = new Application('test');
|
||||
$app = self::$DI['app'];
|
||||
$appbox = $app['phraseanet.appbox'];
|
||||
|
||||
$app['conf']->set(['main', 'search-engine', 'options'], [
|
||||
|
@@ -11,10 +11,7 @@ class ACLTest extends \PhraseanetAuthenticatedTestCase
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
/**
|
||||
* In case first test fails
|
||||
*/
|
||||
$application = new Application('test');
|
||||
$application = self::$DI['app'];
|
||||
$usr_id = User_Adapter::get_usr_id_from_login($application, 'test_phpunit2');
|
||||
try {
|
||||
$template = User_Adapter::getInstance($usr_id, $application);
|
||||
@@ -30,9 +27,7 @@ class ACLTest extends \PhraseanetAuthenticatedTestCase
|
||||
|
||||
}
|
||||
|
||||
self::giveRightsToUser($application, self::$DI['user']);
|
||||
self::$DI['app']['acl']->get(self::$DI['user'])->revoke_access_from_bases([self::$DI['collection_no_access']->get_base_id()]);
|
||||
self::$DI['app']['acl']->get(self::$DI['user'])->set_masks_on_base(self::$DI['collection_no_access_by_status']->get_base_id(), '0000000000000000000000000000000000000000000000000001000000000000', '0000000000000000000000000000000000000000000000000001000000000000', '0000000000000000000000000000000000000000000000000001000000000000', '0000000000000000000000000000000000000000000000000001000000000000');
|
||||
self::resetUsersRights(self::$DI['app'], self::$DI['user']);
|
||||
|
||||
parent::tearDownAfterClass();
|
||||
}
|
||||
@@ -41,9 +36,7 @@ class ACLTest extends \PhraseanetAuthenticatedTestCase
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (null === self::$object) {
|
||||
self::$object = self::$DI['app']['acl']->get(self::$DI['user']);
|
||||
}
|
||||
self::$object = self::$DI['app']['acl']->get(self::$DI['user']);
|
||||
}
|
||||
|
||||
public function testHasAccesToRecord()
|
||||
|
@@ -22,10 +22,9 @@ class Bridge_Api_AbstractTest extends \PhraseanetWebTestCase
|
||||
$this->bridgeApi = $this->getMock('Bridge_Api_Abstract', ["is_configured", "initialize_transport", "set_auth_params", "set_transport_authentication_params"], [self::$DI['app']['url_generator'], self::$DI['app']['phraseanet.registry'], $this->auth, self::$DI['app']['translator']]);
|
||||
}
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
public function bootTestCase()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
$application = new Application('test');
|
||||
$application = self::$DI['app'];
|
||||
try {
|
||||
self::$api = Bridge_Api::get_by_api_name($application, 'apitest');
|
||||
} catch (Bridge_Exception_ApiNotFound $e) {
|
||||
|
@@ -15,11 +15,10 @@ class Bridge_AccountTest extends \PhraseanetAuthenticatedTestCase
|
||||
private static $named;
|
||||
private static $id;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
public function bootTestCase()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
try {
|
||||
$application = new Application('test');
|
||||
$application = self::$DI['app'];
|
||||
|
||||
$sql = 'DELETE FROM bridge_apis WHERE name = "Apitest"';
|
||||
$stmt = $application['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
|
@@ -170,7 +170,7 @@ abstract class PhraseanetAuthenticatedWebTestCase extends \PhraseanetAuthenticat
|
||||
];
|
||||
}
|
||||
|
||||
private function assertFormOrFlashError(Crawler $crawler, $quantity)
|
||||
protected function assertFormOrFlashError(Crawler $crawler, $quantity)
|
||||
{
|
||||
$total = $crawler->filter('.field-error')->count();
|
||||
$total += $crawler->filter('.alert')->count();
|
||||
@@ -178,7 +178,7 @@ abstract class PhraseanetAuthenticatedWebTestCase extends \PhraseanetAuthenticat
|
||||
$this->assertEquals($quantity, $total);
|
||||
}
|
||||
|
||||
private function assertFormError(Crawler $crawler, $quantity)
|
||||
protected function assertFormError(Crawler $crawler, $quantity)
|
||||
{
|
||||
$this->assertEquals($quantity, $crawler->filter('.field-error')->count());
|
||||
}
|
||||
|
@@ -23,7 +23,10 @@ use Alchemy\Phrasea\Model\Entities\UsrListOwner;
|
||||
use Alchemy\Phrasea\Model\Entities\UsrList;
|
||||
use Alchemy\Phrasea\Model\Entities\UsrListEntry;
|
||||
use Alchemy\Phrasea\Model\Entities\StoryWZ;
|
||||
use Monolog\Logger;
|
||||
use Monolog\Handler\NullHandler;
|
||||
use Silex\WebTestCase;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Client;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
@@ -35,6 +38,7 @@ use Alchemy\Tests\Tools\TranslatorMockTrait;
|
||||
abstract class PhraseanetTestCase extends WebTestCase
|
||||
{
|
||||
use TranslatorMockTrait;
|
||||
|
||||
/**
|
||||
* Define some user agents
|
||||
*/
|
||||
@@ -42,67 +46,25 @@ abstract class PhraseanetTestCase extends WebTestCase
|
||||
const USER_AGENT_IE6 = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322)';
|
||||
const USER_AGENT_IPHONE = 'Mozilla/5.0 (iPod; U; CPU iPhone OS 2_1 like Mac OS X; fr-fr) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5F137 Safari/525.20';
|
||||
|
||||
public $app;
|
||||
|
||||
/**
|
||||
* @var \Pimple
|
||||
*/
|
||||
protected static $DI;
|
||||
|
||||
private static $recordsInitialized = false;
|
||||
|
||||
/**
|
||||
* Tell if tables were updated with new schemas
|
||||
* @var boolean
|
||||
*/
|
||||
private static $updated;
|
||||
private static $booted;
|
||||
private static $testCaseBooted;
|
||||
|
||||
/**
|
||||
* Test start time
|
||||
* @var float
|
||||
*/
|
||||
private static $time_start;
|
||||
public $app;
|
||||
private $start;
|
||||
private static $fixtureIds = [];
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Symfony\Component\HttpKernel\Client
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* This method is called before the first test of this test class is run.
|
||||
*/
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
if (!self::$updated) {
|
||||
self::$time_start = microtime(true);
|
||||
|
||||
self::$DI = new \Pimple();
|
||||
self::initializeSqliteDB();
|
||||
|
||||
$application = new Application('test');
|
||||
|
||||
if (!$application['phraseanet.configuration-tester']->isInstalled()) {
|
||||
echo "\033[0;31mPhraseanet is not set up\033[0;37m\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
self::updateTablesSchema($application);
|
||||
|
||||
self::createSetOfUserTests($application);
|
||||
|
||||
self::setCollection($application);
|
||||
|
||||
self::generateRecords($application);
|
||||
|
||||
self::$DI['user']->set_email('valid@phraseanet.com');
|
||||
|
||||
self::$updated = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static function initializeSqliteDB($path = '/tmp/db.sqlite')
|
||||
private function initializeSqliteDB($path = '/tmp/db.sqlite')
|
||||
{
|
||||
if (is_file($path)) {
|
||||
unlink($path);
|
||||
@@ -121,20 +83,16 @@ abstract class PhraseanetTestCase extends WebTestCase
|
||||
public function __destruct()
|
||||
{
|
||||
self::deleteResources();
|
||||
|
||||
if (self::$time_start) {
|
||||
self::$time_start = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
ini_set('memory_limit', '4096M');
|
||||
|
||||
$this->start = $start = microtime(true);
|
||||
|
||||
parent::setUp();
|
||||
|
||||
self::$DI = new \Pimple();
|
||||
|
||||
ini_set('memory_limit', '4096M');
|
||||
|
||||
\PHPUnit_Framework_Error_Warning::$enabled = true;
|
||||
\PHPUnit_Framework_Error_Notice::$enabled = true;
|
||||
|
||||
@@ -150,7 +108,158 @@ abstract class PhraseanetTestCase extends WebTestCase
|
||||
return new Client($DI['app'], []);
|
||||
});
|
||||
|
||||
self::$DI['user']->purgePreferences();
|
||||
self::$DI['user'] = self::$DI->share(function ($DI) {
|
||||
$user = User_Adapter::getInstance(self::$fixtureIds['user']['test_phpunit'], $DI['app']);
|
||||
$user->purgePreferences();
|
||||
|
||||
return $user;
|
||||
});
|
||||
|
||||
self::$DI['user_notAdmin'] = self::$DI->share(function ($DI) {
|
||||
return User_Adapter::getInstance(self::$fixtureIds['user']['test_phpunit_not_admin'], $DI['app']);
|
||||
});
|
||||
|
||||
self::$DI['user_alt1'] = self::$DI->share(function ($DI) {
|
||||
return User_Adapter::getInstance(self::$fixtureIds['user']['test_phpunit_alt1'], $DI['app']);
|
||||
});
|
||||
|
||||
self::$DI['user_alt2'] = self::$DI->share(function ($DI) {
|
||||
return User_Adapter::getInstance(self::$fixtureIds['user']['test_phpunit_alt2'], $DI['app']);
|
||||
});
|
||||
|
||||
self::$DI['logger'] = self::$DI->share(function () {
|
||||
$logger = new Logger('tests');
|
||||
$logger->pushHandler(new NullHandler());
|
||||
|
||||
return $logger;
|
||||
});
|
||||
|
||||
self::$DI['collection'] = self::$DI->share(function ($DI) {
|
||||
return collection::get_from_base_id($DI['app'], self::$fixtureIds['collection']['coll']);
|
||||
});
|
||||
|
||||
self::$DI['collection_no_access'] = self::$DI->share(function ($DI) {
|
||||
return collection::get_from_base_id($DI['app'], self::$fixtureIds['collection']['coll_no_access']);
|
||||
});
|
||||
|
||||
self::$DI['collection_no_access_by_status'] = self::$DI->share(function ($DI) {
|
||||
return collection::get_from_base_id($DI['app'], self::$fixtureIds['collection']['coll_no_status']);
|
||||
});
|
||||
|
||||
if (!self::$booted) {
|
||||
if (!self::$DI['app']['phraseanet.configuration-tester']->isInstalled()) {
|
||||
echo "\033[0;31mPhraseanet is not set up\033[0;37m\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$this->createSetOfUserTests(self::$DI['app']);
|
||||
self::setCollection(self::$DI['app']);
|
||||
|
||||
self::resetUsersRights(self::$DI['app'], self::$DI['user']);
|
||||
self::resetUsersRights(self::$DI['app'], self::$DI['user_notAdmin']);
|
||||
|
||||
self::$booted = true;
|
||||
}
|
||||
|
||||
self::$DI['record_id_resolver'] = self::$DI->protect(function ($id) {
|
||||
if (isset(self::$fixtureIds['records'][$id])) {
|
||||
return self::$fixtureIds['records'][$id];
|
||||
}
|
||||
|
||||
self::$recordsInitialized[] = $id;
|
||||
$file = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess(__DIR__ . '/../files/' . ($id < 10 ? 'test00' . $id . '.jpg' : 'test0' . $id . '.jpg')), self::$DI['collection']);
|
||||
$record = record_adapter::createFromFile($file, self::$DI['app']);
|
||||
$record->generate_subdefs($record->get_databox(), self::$DI['app']);
|
||||
self::$fixtureIds['records'][$id] = $record->get_record_id();
|
||||
|
||||
return self::$fixtureIds['records'][$id];
|
||||
});
|
||||
|
||||
self::$DI['story_id_resolver'] = self::$DI->protect(function ($id) {
|
||||
$id = 'story_'.$id;
|
||||
|
||||
if (isset(self::$fixtureIds['records'][$id])) {
|
||||
return self::$fixtureIds['records'][$id];
|
||||
}
|
||||
|
||||
self::$recordsInitialized[] = $id;
|
||||
$story = record_adapter::createStory(self::$DI['app'], self::$DI['collection']);
|
||||
|
||||
$media = self::$DI['app']['mediavorus']->guess(__DIR__ . '/../files/cestlafete.jpg');
|
||||
$story->substitute_subdef('preview', $media, self::$DI['app']);
|
||||
$story->substitute_subdef('thumbnail', $media, self::$DI['app']);
|
||||
|
||||
self::$fixtureIds['records'][$id] = $story->get_record_id();
|
||||
|
||||
return self::$fixtureIds['records'][$id];
|
||||
});
|
||||
|
||||
foreach (range(1, 24) as $i) {
|
||||
self::$DI['record_' . $i] = self::$DI->share(function ($DI) use ($i) {
|
||||
return new \record_adapter($DI['app'], self::$fixtureIds['databox']['records'], $DI['record_id_resolver']($i));
|
||||
});
|
||||
}
|
||||
|
||||
foreach (range(1, 2) as $i) {
|
||||
self::$DI['record_story_' . $i] = self::$DI->share(function ($DI) use ($i) {
|
||||
return new \record_adapter($DI['app'], self::$fixtureIds['databox']['records'], $DI['story_id_resolver']($i));
|
||||
});
|
||||
}
|
||||
|
||||
self::$DI['record_no_access_resolver'] = self::$DI->protect(function () {
|
||||
$id = 'no_access';
|
||||
|
||||
if (isset(self::$fixtureIds['records'][$id])) {
|
||||
return self::$fixtureIds['records'][$id];
|
||||
}
|
||||
|
||||
self::$recordsInitialized[] = $id;
|
||||
$file = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess(__DIR__ . '/../files/cestlafete.jpg'), self::$DI['collection_no_access']);
|
||||
$record = record_adapter::createFromFile($file, self::$DI['app']);
|
||||
$record->generate_subdefs($record->get_databox(), self::$DI['app']);
|
||||
self::$fixtureIds['records'][$id] = $record->get_record_id();
|
||||
|
||||
return self::$fixtureIds['records'][$id];
|
||||
});
|
||||
|
||||
self::$DI['record_no_access_by_status_resolver'] = self::$DI->protect(function () {
|
||||
$id = 'no_access_by_status';
|
||||
|
||||
if (isset(self::$fixtureIds['records'][$id])) {
|
||||
return self::$fixtureIds['records'][$id];
|
||||
}
|
||||
|
||||
self::$recordsInitialized[] = $id;
|
||||
$file = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess(__DIR__ . '/../files/cestlafete.jpg'), self::$DI['collection_no_access_by_status']);
|
||||
$record = record_adapter::createFromFile($file, self::$DI['app']);
|
||||
$record->generate_subdefs($record->get_databox(), self::$DI['app']);
|
||||
self::$fixtureIds['records'][$id] = $record->get_record_id();
|
||||
|
||||
return self::$fixtureIds['records'][$id];
|
||||
});
|
||||
|
||||
self::$DI['record_no_access'] = self::$DI->share(function ($DI) {
|
||||
return new \record_adapter($DI['app'], self::$fixtureIds['databox']['records'], $DI['record_no_access_resolver']());
|
||||
});
|
||||
|
||||
self::$DI['record_no_access_by_status'] = self::$DI->share(function ($DI) {
|
||||
return new \record_adapter($DI['app'], self::$fixtureIds['databox']['records'], $DI['record_no_access_by_status_resolver']());
|
||||
});
|
||||
|
||||
if (!self::$testCaseBooted) {
|
||||
$this->bootTestCase();
|
||||
}
|
||||
self::$testCaseBooted = true;
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
self::$testCaseBooted = false;
|
||||
}
|
||||
|
||||
protected function bootTestCase()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected function loadCLI($environment = Application::ENV_TEST)
|
||||
@@ -205,7 +314,7 @@ abstract class PhraseanetTestCase extends WebTestCase
|
||||
}));
|
||||
|
||||
$app['browser'] = $app->share($app->extend('browser', function ($browser) {
|
||||
$browser->setUserAgent(PhraseanetTestCase::USER_AGENT_FIREFOX8MAC);
|
||||
$browser->setUserAgent(self::USER_AGENT_FIREFOX8MAC);
|
||||
|
||||
return $browser;
|
||||
}));
|
||||
@@ -238,12 +347,6 @@ abstract class PhraseanetTestCase extends WebTestCase
|
||||
|
||||
parent::tearDown();
|
||||
|
||||
// $duration = (microtime(true) - $this->start);
|
||||
// if ($duration > 0.75) {
|
||||
// echo "test in " . get_class($this) . " last " . $duration . "\n";
|
||||
// }
|
||||
$this->start = null;
|
||||
|
||||
//In case some executed script modify 'max_execution_time' ini var
|
||||
//Initialize set_time_limit(0) which is the default value for PHP CLI
|
||||
|
||||
@@ -805,96 +908,62 @@ abstract class PhraseanetTestCase extends WebTestCase
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the sql tables with the current schema.
|
||||
*/
|
||||
private static function updateTablesSchema(Application $application)
|
||||
protected static function resetUsersRights(Application $app, \User_Adapter $user)
|
||||
{
|
||||
if (!self::$updated) {
|
||||
if (file_exists(Setup_Upgrade::get_lock_file())) {
|
||||
unlink(Setup_Upgrade::get_lock_file());
|
||||
}
|
||||
|
||||
$upgrader = new Setup_Upgrade($application);
|
||||
$application['phraseanet.appbox']->forceUpgrade($upgrader, $application);
|
||||
unset($upgrader);
|
||||
|
||||
$command = __DIR__ . '/../../bin/developer orm:schema-tool:update --force';
|
||||
|
||||
try {
|
||||
$process = new Symfony\Component\Process\Process('php ' . $command);
|
||||
$process->run();
|
||||
|
||||
if (!$process->isSuccessful()) {
|
||||
throw new \RuntimeException($process->getErrorOutput());
|
||||
}
|
||||
|
||||
self::$updated = true;
|
||||
} catch (\RuntimeException $e) {
|
||||
echo "\033[0;31mUnable to validate ORM schema\033[0;37m\n";
|
||||
exit(1);
|
||||
}
|
||||
switch ($user->get_login()) {
|
||||
case 'test_phpunit':
|
||||
self::giveRightsToUser($app, $user);
|
||||
$app['acl']->get($user)->set_admin(true);
|
||||
$app['acl']->get(self::$DI['user'])->revoke_access_from_bases([self::$DI['collection_no_access']->get_base_id()]);
|
||||
$app['acl']->get(self::$DI['user'])->set_masks_on_base(self::$DI['collection_no_access_by_status']->get_base_id(), '00000000000000000000000000010000', '00000000000000000000000000010000', '00000000000000000000000000010000', '00000000000000000000000000010000');
|
||||
break;
|
||||
case 'test_phpunit_not_admin':
|
||||
case 'test_phpunit_alt2':
|
||||
case 'test_phpunit_alt1':
|
||||
self::giveRightsToUser(self::$DI['app'], $user);
|
||||
$app['acl']->get($user)->set_admin(false);
|
||||
$app['acl']->get(self::$DI['user'])->revoke_access_from_bases([self::$DI['collection_no_access']->get_base_id()]);
|
||||
$app['acl']->get(self::$DI['user'])->set_masks_on_base(self::$DI['collection_no_access_by_status']->get_base_id(), '00000000000000000000000000010000', '00000000000000000000000000010000', '00000000000000000000000000010000', '00000000000000000000000000010000');
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException(sprintf('User %s not found', $user->get_login()));
|
||||
}
|
||||
|
||||
set_time_limit(3600);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a set of users for the test suite.
|
||||
*
|
||||
* self::$DI['user']
|
||||
* self::$DI['user_alt1']
|
||||
* self::$DI['user_alt2']
|
||||
*/
|
||||
private static function createSetOfUserTests(Application $application)
|
||||
private function createSetOfUserTests(Application $application)
|
||||
{
|
||||
self::$DI['user'] = self::$DI->share(function ($DI) use ($application) {
|
||||
$usr_id = User_Adapter::get_usr_id_from_login($application, 'test_phpunit');
|
||||
|
||||
if (!$usr_id) {
|
||||
$user = User_Adapter::create($application, 'test_phpunit', random::generatePassword(), 'noone@example.com', false);
|
||||
$usr_id = $user->get_id();
|
||||
}
|
||||
|
||||
if (false === $usr_id = User_Adapter::get_usr_id_from_login($application, 'test_phpunit')) {
|
||||
$user = User_Adapter::create($application, 'test_phpunit', random::generatePassword(), 'noone@example.com', false);
|
||||
$usr_id = $user->get_id();
|
||||
} else {
|
||||
$user = User_Adapter::getInstance($usr_id, $application);
|
||||
}
|
||||
$user->set_email('valid@phraseanet.com');
|
||||
|
||||
return $user;
|
||||
});
|
||||
self::$fixtureIds['user']['test_phpunit'] = $usr_id;
|
||||
|
||||
self::$DI['user_notAdmin'] = self::$DI->share(function () use ($application) {
|
||||
$usr_id = User_Adapter::get_usr_id_from_login($application, 'test_phpunit_not_admin');
|
||||
if (false === $usr_id = User_Adapter::get_usr_id_from_login($application, 'test_phpunit_not_admin')) {
|
||||
$user = User_Adapter::create($application, 'test_phpunit_not_admin', random::generatePassword(), 'noone_not_admin@example.com', false);
|
||||
$usr_id = $user->get_id();
|
||||
} else {
|
||||
$user = User_Adapter::getInstance($usr_id, $application);
|
||||
}
|
||||
|
||||
if (!$usr_id) {
|
||||
$user = User_Adapter::create($application, 'test_phpunit_not_admin', random::generatePassword(), 'noone_not_admin@example.com', false);
|
||||
$usr_id = $user->get_id();
|
||||
}
|
||||
self::$fixtureIds['user']['test_phpunit_not_admin'] = $usr_id;
|
||||
|
||||
return User_Adapter::getInstance($usr_id, $application);
|
||||
});
|
||||
if (false === $usr_id = User_Adapter::get_usr_id_from_login($application, 'test_phpunit_alt1')) {
|
||||
$user = User_Adapter::create($application, 'test_phpunit_alt1', random::generatePassword(), 'noonealt1@example.com', false);
|
||||
$usr_id = $user->get_id();
|
||||
}
|
||||
|
||||
self::$DI['user_alt1'] = self::$DI->share(function () use ($application) {
|
||||
$usr_id = User_Adapter::get_usr_id_from_login($application, 'test_phpunit_alt1');
|
||||
self::$fixtureIds['user']['test_phpunit_alt1'] = $usr_id;
|
||||
|
||||
if (!$usr_id) {
|
||||
$user = User_Adapter::create($application, 'test_phpunit_alt1', random::generatePassword(), 'noonealt1@example.com', false);
|
||||
$usr_id = $user->get_id();
|
||||
}
|
||||
if (false === $usr_id = User_Adapter::get_usr_id_from_login($application, 'test_phpunit_alt2')) {
|
||||
$user = User_Adapter::create($application, 'test_phpunit_alt2', random::generatePassword(), 'noonealt2@example.com', false);
|
||||
$usr_id = $user->get_id();
|
||||
}
|
||||
|
||||
return User_Adapter::getInstance($usr_id, $application);
|
||||
});
|
||||
|
||||
self::$DI['user_alt2'] = self::$DI->share(function () use ($application) {
|
||||
$usr_id = User_Adapter::get_usr_id_from_login($application, 'test_phpunit_alt2');
|
||||
|
||||
if (!$usr_id) {
|
||||
$user = User_Adapter::create($application, 'test_phpunit_alt2', random::generatePassword(), 'noonealt2@example.com', false);
|
||||
$usr_id = $user->get_id();
|
||||
}
|
||||
|
||||
return User_Adapter::getInstance($usr_id, $application);
|
||||
});
|
||||
self::$fixtureIds['user']['test_phpunit_alt2'] = $usr_id;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -902,7 +971,7 @@ abstract class PhraseanetTestCase extends WebTestCase
|
||||
*
|
||||
* @param \User_Adapter $user
|
||||
*/
|
||||
public static function giveRightsToUser(Application $app, \User_Adapter $user)
|
||||
public static function giveRightsToUser(Application $app, \User_Adapter $user, $base_ids = null)
|
||||
{
|
||||
$app['acl']->get($user)->give_access_to_sbas(array_keys($app['phraseanet.appbox']->get_databoxes()));
|
||||
|
||||
@@ -918,6 +987,10 @@ abstract class PhraseanetTestCase extends WebTestCase
|
||||
$app['acl']->get($user)->update_rights_to_sbas($databox->get_sbas_id(), $rights);
|
||||
|
||||
foreach ($databox->get_collections() as $collection) {
|
||||
if (null !== $base_ids && !in_array($collection->get_base_id(), (array) $base_ids, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$base_id = $collection->get_base_id();
|
||||
|
||||
$app['acl']->get($user)->give_access_to_base([$base_id]);
|
||||
@@ -958,7 +1031,6 @@ abstract class PhraseanetTestCase extends WebTestCase
|
||||
$coll = $collection_no_acces = $collection_no_acces_by_status = $db = null;
|
||||
|
||||
foreach ($application['phraseanet.appbox']->get_databoxes() as $databox) {
|
||||
$db = $databox;
|
||||
foreach ($databox->get_collections() as $collection) {
|
||||
if ($collection_no_acces instanceof collection && !$collection_no_acces_by_status) {
|
||||
$collection_no_acces_by_status = $collection;
|
||||
@@ -977,138 +1049,18 @@ abstract class PhraseanetTestCase extends WebTestCase
|
||||
}
|
||||
}
|
||||
|
||||
if (!$coll instanceof collection) {
|
||||
self::fail('Unable to find a collection');
|
||||
self::$fixtureIds['databox']['records'] = $coll->get_databox()->get_sbas_id();
|
||||
self::$fixtureIds['collection']['coll'] = $coll->get_base_id();
|
||||
|
||||
if (!$collection_no_acces instanceof collection) {
|
||||
$collection_no_acces = collection::create($application, $databox, $application['phraseanet.appbox'], 'BIBOO', self::$DI['user']);
|
||||
}
|
||||
self::$fixtureIds['collection']['coll_no_access'] = $collection_no_acces->get_base_id();
|
||||
|
||||
self::$DI['collection'] = $coll;
|
||||
|
||||
self::$DI['collection_no_access'] = self::$DI->share(function ($DI) use ($application, $databox, $collection_no_acces) {
|
||||
if (!$collection_no_acces instanceof collection) {
|
||||
$collection_no_acces = collection::create($application, $databox, $application['phraseanet.appbox'], 'BIBOO', $DI['user']);
|
||||
}
|
||||
|
||||
$DI['user'] = $DI->share(
|
||||
$DI->extend('user', function ($user, $DI) use ($collection_no_acces) {
|
||||
$DI['app']['acl']->get($user)->revoke_access_from_bases([$collection_no_acces->get_base_id()]);
|
||||
$DI['client'] = new Client($DI['app'], []);
|
||||
|
||||
return $user;
|
||||
})
|
||||
);
|
||||
|
||||
$DI['user'];
|
||||
|
||||
return $collection_no_acces;
|
||||
});
|
||||
|
||||
self::$DI['collection_no_access_by_status'] = self::$DI->share(function ($DI) use ($application, $databox, $collection_no_acces_by_status) {
|
||||
if (!$collection_no_acces_by_status instanceof collection) {
|
||||
$collection_no_acces_by_status = collection::create($application, $databox, $application['phraseanet.appbox'], 'BIBOONOACCESBYSTATUS', $DI['user']);
|
||||
}
|
||||
|
||||
$DI['user'] = $DI->share(
|
||||
$DI->extend('user', function ($user, $DI) use ($collection_no_acces_by_status) {
|
||||
$DI['app']['acl']->get($user)->set_masks_on_base($collection_no_acces_by_status->get_base_id(), '0000000000000000000000000000000000000000000000000001000000000000', '0000000000000000000000000000000000000000000000000001000000000000', '0000000000000000000000000000000000000000000000000001000000000000', '0000000000000000000000000000000000000000000000000001000000000000');
|
||||
$DI['client'] = new Client($DI['app'], []);
|
||||
|
||||
return $user;
|
||||
})
|
||||
);
|
||||
|
||||
$DI['user'];
|
||||
|
||||
return $collection_no_acces_by_status;
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a set of records for the current tests suites.
|
||||
*/
|
||||
private static function generateRecords(Application $app)
|
||||
{
|
||||
if (self::$recordsInitialized === false) {
|
||||
|
||||
$logger = new \Monolog\Logger('tests');
|
||||
$logger->pushHandler(new \Monolog\Handler\NullHandler());
|
||||
self::$recordsInitialized = [];
|
||||
|
||||
$resolvePathfile = function ($i) {
|
||||
$finder = new Symfony\Component\Finder\Finder();
|
||||
|
||||
$name = $i < 10 ? 'test00' . $i . '.*' : 'test0' . $i . '.*';
|
||||
|
||||
$finder->name($name)->in(__DIR__ . '/../files/');
|
||||
|
||||
foreach ($finder as $file) {
|
||||
return $file;
|
||||
}
|
||||
|
||||
throw new Exception(sprintf('File %d not found', $i));
|
||||
};
|
||||
|
||||
foreach (range(1, 24) as $i) {
|
||||
self::$DI['record_' . $i] = self::$DI->share(function ($DI) use ($logger, $resolvePathfile, $i) {
|
||||
|
||||
\PhraseanetTestCase::$recordsInitialized[] = $i;
|
||||
|
||||
$file = new File($DI['app'], $DI['app']['mediavorus']->guess($resolvePathfile($i)->getPathname()), $DI['collection']);
|
||||
|
||||
$record = record_adapter::createFromFile($file, $DI['app']);
|
||||
|
||||
$record->generate_subdefs($record->get_databox(), $DI['app']);
|
||||
|
||||
return $record;
|
||||
});
|
||||
}
|
||||
|
||||
foreach (range(1, 2) as $i) {
|
||||
self::$DI['record_story_' . $i] = self::$DI->share(function ($DI) use ($i) {
|
||||
|
||||
\PhraseanetTestCase::$recordsInitialized[] = 'story_' . $i;
|
||||
|
||||
return record_adapter::createStory($DI['app'], $DI['collection']);
|
||||
});
|
||||
}
|
||||
|
||||
self::$DI['record_no_access'] = self::$DI->share(function ($DI) {
|
||||
|
||||
\PhraseanetTestCase::$recordsInitialized[] = 'no_access';
|
||||
|
||||
$file = new File($DI['app'], $DI['app']['mediavorus']->guess(__DIR__ . '/../files/cestlafete.jpg'), $DI['collection_no_access']);
|
||||
|
||||
return \record_adapter::createFromFile($file, $DI['app']);
|
||||
});
|
||||
|
||||
self::$DI['record_no_access_by_status'] = self::$DI->share(function ($DI) {
|
||||
|
||||
\PhraseanetTestCase::$recordsInitialized[] = 'no_access_by_status';
|
||||
|
||||
$file = new File($DI['app'], $DI['app']['mediavorus']->guess(__DIR__ . '/../files/cestlafete.jpg'), $DI['collection_no_access']);
|
||||
|
||||
return \record_adapter::createFromFile($file, $DI['app']);
|
||||
});
|
||||
|
||||
self::$DI['user'] = self::$DI->share(
|
||||
self::$DI->extend('user', function ($user, $DI) use ($app) {
|
||||
\PhraseanetTestCase::giveRightsToUser($app, $user);
|
||||
$app['acl']->get($user)->set_admin(true);
|
||||
|
||||
return $user;
|
||||
})
|
||||
);
|
||||
|
||||
self::$DI['user_notAdmin'] = self::$DI->share(
|
||||
self::$DI->extend('user_notAdmin', function ($user, $DI) use ($app) {
|
||||
\PhraseanetTestCase::giveRightsToUser($app, $user);
|
||||
$app['acl']->get($user)->set_admin(false);
|
||||
|
||||
return $user;
|
||||
})
|
||||
);
|
||||
if (!$collection_no_acces_by_status instanceof collection) {
|
||||
$collection_no_acces_by_status = collection::create($application, $databox, $application['phraseanet.appbox'], 'BIBOONOACCESBYSTATUS', self::$DI['user']);
|
||||
}
|
||||
self::$fixtureIds['collection']['coll_no_status'] = $collection_no_acces_by_status->get_base_id();
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -1118,18 +1070,6 @@ abstract class PhraseanetTestCase extends WebTestCase
|
||||
*/
|
||||
private static function deleteResources()
|
||||
{
|
||||
$skipped = \PhraseanetPHPUnitListener::getSkipped();
|
||||
|
||||
if ($skipped) {
|
||||
echo "\nSkipped test : \n\n";
|
||||
foreach ($skipped as $skipped_test) {
|
||||
echo $skipped_test . "\n";
|
||||
}
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
\PhraseanetPHPUnitListener::resetSkipped();
|
||||
|
||||
if (self::$recordsInitialized !== false) {
|
||||
foreach (self::$recordsInitialized as $i) {
|
||||
self::$DI['record_' . $i]->delete();
|
||||
|
@@ -14,10 +14,9 @@ class collectionTest extends \PhraseanetAuthenticatedTestCase
|
||||
*/
|
||||
private static $objectDisable;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
public function bootTestCase()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
$application = new Application('test');
|
||||
$application = self::$DI['app'];
|
||||
|
||||
$found = false;
|
||||
foreach ($application['phraseanet.appbox']->get_databoxes() as $databox) {
|
||||
|
@@ -23,14 +23,8 @@ class media_subdefTest extends \PhraseanetTestCase
|
||||
*/
|
||||
private static $recordonbleu;
|
||||
|
||||
/**
|
||||
* @covers media_subdef::__construct
|
||||
* @covers media_subdef::create
|
||||
*/
|
||||
public static function setUpBeforeClass()
|
||||
public function bootTestCase()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
$file = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess(__DIR__ . "/../../files/iphone_pic.jpg"), self::$DI['collection']);
|
||||
|
||||
self::$recordonbleu = record_adapter::createFromFile($file, self::$DI['app']);
|
||||
|
@@ -2,7 +2,6 @@
|
||||
|
||||
class unitTestsTest extends \PhraseanetTestCase
|
||||
{
|
||||
|
||||
public function testFiles()
|
||||
{
|
||||
$reserved = [
|
||||
|
Reference in New Issue
Block a user