Add improvements to unit tests

This commit is contained in:
Romain Neutron
2013-12-19 12:08:59 +01:00
parent 49ea64b1c3
commit 6c45e8d40a
39 changed files with 583 additions and 689 deletions

View File

@@ -80,6 +80,7 @@ class RegenerateSqliteDb extends Command
$DI = new \Pimple();
$this->generateUsers($this->container['EM'], $DI);
$this->insertOauthApps($DI);
$this->generateCollection($DI);
$this->generateRecord($DI);
$this->insertOneStoryInWz($this->container['EM'], $DI);
@@ -96,6 +97,9 @@ class RegenerateSqliteDb extends Command
$fixtures['user']['test_phpunit_alt1'] = $DI['user_alt1']->get_id();
$fixtures['user']['test_phpunit_alt2'] = $DI['user_alt2']->get_id();
$fixtures['oauth']['user'] = $DI['app-user']->get_id();
$fixtures['oauth']['user_notAdmin'] = $DI['app-user_notAdmin']->get_id();
$fixtures['databox']['records'] = $DI['databox']->get_sbas_id();
$fixtures['collection']['coll'] = $DI['coll']->get_base_id();
$fixtures['collection']['coll_no_access'] = $DI['coll_no_access']->get_base_id();
@@ -103,6 +107,7 @@ class RegenerateSqliteDb extends Command
$fixtures['record']['record_story_1'] = $DI['record_story_1']->get_record_id();
$fixtures['record']['record_story_2'] = $DI['record_story_2']->get_record_id();
$fixtures['record']['record_story_3'] = $DI['record_story_3']->get_record_id();
$fixtures['record']['record_1'] = $DI['record_1']->get_record_id();
$fixtures['record']['record_2'] = $DI['record_2']->get_record_id();
@@ -143,6 +148,19 @@ class RegenerateSqliteDb extends Command
return 0;
}
private function insertOauthApps(\Pimple $DI)
{
$DI['app-user'] = \API_OAuth2_Application::create($this->container, $DI['user'], 'test application for user');
$DI['app-user']->set_redirect_uri('http://callback.com/callback/');
$DI['app-user']->set_website('http://website.com/');
$DI['app-user']->set_type(\API_OAuth2_Application::WEB_TYPE);
$DI['app-user_notAdmin'] = \API_OAuth2_Application::create($this->container, $DI['user_notAdmin'], 'test application for user not admin');
$DI['app-user_notAdmin']->set_redirect_uri('http://callback.com/callback/');
$DI['app-user_notAdmin']->set_website('http://website.com/');
$DI['app-user_notAdmin']->set_type(\API_OAuth2_Application::WEB_TYPE);
}
private function insertAuthFailures(EntityManager $em, \Pimple $DI)
{
$ip = '192.168.16.178';
@@ -276,10 +294,12 @@ class RegenerateSqliteDb extends Command
$media = $this->container['mediavorus']->guess($this->container['root.path'] . '/tests/files/cestlafete.jpg');
foreach (range(1, 2) as $i) {
foreach (range(1, 3) as $i) {
$story = \record_adapter::createStory($this->container, $DI['coll']);
if ($i < 3) {
$story->substitute_subdef('preview', $media, $this->container);
$story->substitute_subdef('thumbnail', $media, $this->container);
}
$DI['record_story_' . $i] = $story;
}
}

View File

@@ -142,7 +142,7 @@ class API_OAuth2_Token
$stmt->execute($params);
$stmt->closeCursor();
$this->session_id = (int) $session_id;
$this->session_id = $session_id !== null ? (int) $session_id : $session_id;
return $this;
}

View File

@@ -28,5 +28,11 @@
<directory>vendor</directory>
</blacklist>
</filter>
<!--
<listeners>
<listener class="PhraseanetPHPUnitListener" file="tests/classes/PhraseanetPHPUnitListener.php"></listener>
</listeners>
-->
</phpunit>

View File

@@ -9,53 +9,42 @@ class BasketACLTest extends \PhraseanetTestCase
public function testOwnerIsOwner()
{
$basket = self::$DI['app']['EM']->find('Alchemy\Phrasea\Model\Entities\Basket', 4);
$acl = new BasketACL();
$this->assertTrue($acl->isOwner($basket, self::$DI['user']));
$this->assertTrue((new BasketACL())->isOwner($basket, self::$DI['user']));
}
public function testParticipantIsNotAnOwner()
{
$basket = self::$DI['app']['EM']->find('Alchemy\Phrasea\Model\Entities\Basket', 4);
$acl = new BasketACL();
$this->assertFalse($acl->isOwner($basket, self::$DI['user_alt1']));
$this->assertFalse((new BasketACL())->isOwner($basket, self::$DI['user_alt1']));
}
public function testUserIsNotTheOwner()
{
$basket = self::$DI['app']['EM']->find('Alchemy\Phrasea\Model\Entities\Basket', 1);
$acl = new BasketACL();
$this->assertFalse($acl->isOwner($basket, self::$DI['user_alt1']));
$this->assertFalse((new BasketACL())->isOwner($basket, self::$DI['user_alt1']));
}
public function testOwnerHasAccessInValidationEnv()
{
$basket = self::$DI['app']['EM']->find('Alchemy\Phrasea\Model\Entities\Basket', 4);
$acl = new BasketACL();
$this->assertTrue($acl->hasAccess($basket, self::$DI['user']));
$this->assertTrue((new BasketACL())->hasAccess($basket, self::$DI['user']));
}
public function testOwnerHasAccess()
{
$basket = self::$DI['app']['EM']->find('Alchemy\Phrasea\Model\Entities\Basket', 1);
$acl = new BasketACL();
$this->assertTrue($acl->hasAccess($basket, self::$DI['user']));
$this->assertTrue((new BasketACL())->hasAccess($basket, self::$DI['user']));
}
public function testParticipantHasAccess()
{
$basket = self::$DI['app']['EM']->find('Alchemy\Phrasea\Model\Entities\Basket', 4);
$acl = new BasketACL();
$this->assertTrue($acl->hasAccess($basket, self::$DI['user_alt1']));
$this->assertTrue((new BasketACL())->hasAccess($basket, self::$DI['user_alt1']));
}
public function testUserHasNotAccess()
{
$basket = self::$DI['app']['EM']->find('Alchemy\Phrasea\Model\Entities\Basket', 1);
$acl = new BasketACL();
$this->assertFalse($acl->hasAccess($basket, self::$DI['user_alt1']));
$this->assertFalse((new BasketACL())->hasAccess($basket, self::$DI['user_alt1']));
}
}

View File

@@ -30,14 +30,14 @@ class ApiJSONPApplication extends ApiTestCase
$this->assertEquals(200, $response->getStatusCode(), 'Test status code 405 ' . $response->getContent());
}
public function getParameters(array $parameters = [])
protected function getParameters(array $parameters = [])
{
$parameters['callback'] = 'jsFunction';
return $parameters;
}
public function unserialize($data)
protected function unserialize($data)
{
if (strpos($data, 'jsFunction(') !== 0) {
$this->fail('Invalid JSONP response');
@@ -50,7 +50,7 @@ class ApiJSONPApplication extends ApiTestCase
return json_decode(substr($data, 11, -1), true);
}
public function getAcceptMimeType()
protected function getAcceptMimeType()
{
return 'application/json';
}

View File

@@ -4,18 +4,17 @@ namespace Alchemy\Tests\Phrasea\Application;
class ApiJsonApplication extends ApiTestCase
{
public function getParameters(array $parameters = [])
protected function getParameters(array $parameters = [])
{
return $parameters;
}
public function unserialize($data)
protected function unserialize($data)
{
return json_decode($data, true);
}
public function getAcceptMimeType()
protected function getAcceptMimeType()
{
return 'application/json';
}

View File

@@ -9,7 +9,7 @@ class ApiRootTest extends \PhraseanetWebTestCase
{
/**
*
* @var Symfony\Component\HttpKernel\Client
* @var \Symfony\Component\HttpKernel\Client
*/
protected $client;
@@ -17,15 +17,9 @@ class ApiRootTest extends \PhraseanetWebTestCase
{
parent::setUp();
self::$DI['app'] = self::$DI->share(function () {
$environment = 'test';
$app = require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Api.php';
$app['debug'] = true;
return $app;
self::$DI['app'] = self::$DI->share(function ($DI) {
return $this->loadApp('/lib/Alchemy/Phrasea/Application/Api.php');
});
}
public function testRoot()

View File

@@ -7,6 +7,7 @@ use Alchemy\Phrasea\Border\File;
use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\Authentication\Context;
use Alchemy\Phrasea\Model\Entities\Task;
use Guzzle\Common\Exception\GuzzleException;
use Symfony\Component\HttpKernel\Client;
use Symfony\Component\HttpFoundation\Response;
@@ -37,12 +38,11 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
* @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();
abstract protected function getParameters(array $parameters = []);
abstract protected function unserialize($data);
abstract protected function getAcceptMimeType();
public function tearDown()
{
@@ -59,33 +59,19 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
});
if (!self::$apiInitialized) {
self::$oauthApplication = \API_OAuth2_Application::create(self::$DI['app'], self::$DI['user_notAdmin'], 'test API v1');
self::$account = \API_OAuth2_Account::load_with_user(self::$DI['app'], self::$oauthApplication, self::$DI['user_notAdmin']);
self::$account = \API_OAuth2_Account::load_with_user(self::$DI['app'], self::$DI['oauth2-app-user_notAdmin'], self::$DI['user_notAdmin']);
self::$token = self::$account->get_token()->get_value();
self::$adminToken = null;
self::$adminApplication = \API_OAuth2_Application::create(self::$DI['app'], self::$DI['user'], 'test2 API v1');
self::$adminAccount = \API_OAuth2_Account::load_with_user(self::$DI['app'], self::$adminApplication, self::$DI['user']);
self::$adminAccount = \API_OAuth2_Account::load_with_user(self::$DI['app'], self::$DI['oauth2-app-user'], self::$DI['user']);
self::$adminToken = self::$adminAccount->get_token()->get_value();
self::$apiInitialized = true;
}
}
public static function tearDownAfterClass()
{
//delete database entry
self::$account->delete();
self::$oauthApplication->delete();
if (self::$adminToken) {
self::$adminAccount->delete();
self::$adminApplication->delete();
}
self::$apiInitialized = false;
self::$databoxe_ids = [];
self::$token = self::$account = self::$oauthApplication = self::$adminToken
= self::$adminAccount = self::$adminApplication = null;
@@ -168,7 +154,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
$this->assertArrayHasKey('de', $databox['labels']);
$this->assertArrayHasKey('nl', $databox['labels']);
$this->assertArrayHasKey('version', $databox);
self::$databoxe_ids[] = $databox['databox_id'];
break;
}
}
@@ -596,11 +582,11 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
public function testDataboxCollectionRoute()
{
$this->setToken(self::$token);
foreach (self::$databoxe_ids as $databox_id) {
$databox_id = self::$DI['record_1']->get_sbas_id();
$route = '/api/v1/databoxes/' . $databox_id . '/collections/';
$this->evaluateMethodNotAllowedRoute($route, ['POST', 'PUT', 'DELETE']);
$crawler = self::$DI['client']->request('GET', $route, $this->getParameters(), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
self::$DI['client']->request('GET', $route, $this->getParameters(), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
$content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
$this->evaluateResponse200(self::$DI['client']->getResponse());
$this->evaluateMeta200($content);
@@ -623,7 +609,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
$this->assertGreaterThan(0, $collection['collection_id']);
$this->assertTrue(is_string($collection['name']));
$this->assertTrue(is_int($collection['record_amount']));
}
break;
}
$route = '/api/v1/databoxes/24892534/collections/';
$this->evaluateNotFoundRoute($route, ['GET']);
@@ -640,13 +626,13 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
public function testDataboxStatusRoute()
{
$this->setToken(self::$token);
foreach (self::$databoxe_ids as $databox_id) {
$databox_id = self::$DI['record_1']->get_sbas_id();
$databox = self::$DI['app']['phraseanet.appbox']->get_databox($databox_id);
$ref_status = $databox->get_statusbits();
$route = '/api/v1/databoxes/' . $databox_id . '/status/';
$this->evaluateMethodNotAllowedRoute($route, ['POST', 'PUT', 'DELETE']);
$crawler = self::$DI['client']->request('GET', $route, $this->getParameters(), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
self::$DI['client']->request('GET', $route, $this->getParameters(), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
$content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
$this->evaluateResponse200(self::$DI['client']->getResponse());
$this->evaluateMeta200($content);
@@ -676,7 +662,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
$this->assertTrue($status['label_on'] === $ref_status[$status['bit']]['labelon']);
$this->assertTrue($status['img_off'] === $ref_status[$status['bit']]['img_off']);
$this->assertTrue($status['img_on'] === $ref_status[$status['bit']]['img_on']);
}
break;
}
$route = '/api/v1/databoxes/24892534/status/';
$this->evaluateNotFoundRoute($route, ['GET']);
@@ -694,7 +680,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
public function testDataboxMetadatasRoute()
{
$this->setToken(self::$token);
foreach (self::$databoxe_ids as $databox_id) {
$databox_id = self::$DI['record_1']->get_sbas_id();
$databox = self::$DI['app']['phraseanet.appbox']->get_databox($databox_id);
$ref_structure = $databox->get_meta_structure();
@@ -708,7 +694,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
$route = '/api/v1/databoxes/' . $databox_id . '/metadatas/';
$this->evaluateMethodNotAllowedRoute($route, ['POST', 'PUT', 'DELETE']);
$crawler = self::$DI['client']->request('GET', $route, $this->getParameters(), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
self::$DI['client']->request('GET', $route, $this->getParameters(), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
$content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
$this->evaluateResponse200(self::$DI['client']->getResponse());
$this->evaluateMeta200($content);
@@ -764,7 +750,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
$this->assertTrue($element->get_tag()->getName() === $metadatas['tagname']);
$this->assertTrue($element->get_tag()->getTagname() === $metadatas['source']);
$this->assertTrue($element->get_tag()->getGroupName() === $metadatas['namespace']);
}
break;
}
$route = '/api/v1/databoxes/24892534/metadatas/';
$this->evaluateNotFoundRoute($route, ['GET']);
@@ -782,7 +768,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
public function testDataboxTermsOfUseRoute()
{
$this->setToken(self::$token);
foreach (self::$databoxe_ids as $databox_id) {
$databox_id = self::$DI['record_1']->get_sbas_id();
$route = '/api/v1/databoxes/' . $databox_id . '/termsOfUse/';
$this->evaluateMethodNotAllowedRoute($route, ['POST', 'PUT', 'DELETE']);
@@ -797,7 +783,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
$this->assertArrayHasKey('locale', $terms);
$this->assertTrue(in_array($terms['locale'], array_keys(Application::getAvailableLanguages())));
$this->assertArrayHasKey('terms', $terms);
}
break;
}
$route = '/api/v1/databoxes/24892534/termsOfUse/';
$this->evaluateNotFoundRoute($route, ['GET']);
@@ -815,7 +801,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
public function testSearchRoute()
{
$this->setToken(self::$token);
$crawler = self::$DI['client']->request('POST', '/api/v1/search/', $this->getParameters(), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
self::$DI['client']->request('POST', '/api/v1/search/', $this->getParameters(), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
$content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
$this->evaluateResponse200(self::$DI['client']->getResponse());
@@ -852,7 +838,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
self::$DI['record_story_1'];
$crawler = self::$DI['client']->request('POST', '/api/v1/search/', $this->getParameters(['search_type' => 1]), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
self::$DI['client']->request('POST', '/api/v1/search/', $this->getParameters(['search_type' => 1]), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
$content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
$this->evaluateResponse200(self::$DI['client']->getResponse());
@@ -885,7 +871,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
public function testRecordsSearchRoute()
{
$this->setToken(self::$token);
$crawler = self::$DI['client']->request('POST', '/api/v1/records/search/', $this->getParameters(), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
self::$DI['client']->request('POST', '/api/v1/records/search/', $this->getParameters(), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
$content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
$this->evaluateResponse200(self::$DI['client']->getResponse());
@@ -897,6 +883,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
foreach ($response['results'] as $record) {
$this->evaluateGoodRecord($record);
break;
}
}
@@ -915,7 +902,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
->disableOriginalConstructor()
->getMock()
));
$crawler = self::$DI['client']->request($method, '/api/v1/records/search/', $this->getParameters(['query' => 'koala']), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
self::$DI['client']->request($method, '/api/v1/records/search/', $this->getParameters(['query' => 'koala']), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
}
public function provideAvailableSearchMethods()
@@ -1013,8 +1000,6 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
{
$this->setToken(self::$token);
$keys = array_keys(self::$DI['record_1']->get_subdefs());
$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']);
@@ -1078,14 +1063,12 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
$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()]);
self::$DI['client']->request('GET', $route, $this->getParameters(['mimes' => ['image/png']]), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
$content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
$this->assertArrayHasKey('embed', $content['response']);
foreach ($content['response']['embed'] as $embed) {
$this->checkEmbed($embed, self::$DI['record_1']);
}
$this->assertEquals(0, count($content['response']['embed']));
}
/**
@@ -1213,7 +1196,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
}
$this->evaluateMethodNotAllowedRoute($route, ['GET', 'PUT', 'DELETE']);
$crawler = self::$DI['client']->request('POST', $route, $this->getParameters(['status' => $tochange]), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
self::$DI['client']->request('POST', $route, $this->getParameters(['status' => $tochange]), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
$content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
/**
@@ -1235,7 +1218,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
$tochange[$n] = $value == '0' ? '1' : '0';
}
$crawler = self::$DI['client']->request('POST', $route, $this->getParameters(['status' => $tochange]), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
self::$DI['client']->request('POST', $route, $this->getParameters(['status' => $tochange]), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
$content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
/**
@@ -1394,7 +1377,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
$this->evaluateMethodNotAllowedRoute($route, ['GET', 'PUT', 'DELETE']);
$crawler = self::$DI['client']->request('POST', $route, $this->getParameters(['name' => 'un Joli Nom']), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
self::$DI['client']->request('POST', $route, $this->getParameters(['name' => 'un Joli Nom']), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
$content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
$this->evaluateResponse200(self::$DI['client']->getResponse());
@@ -1406,7 +1389,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
$this->assertEquals($content['response']['basket']['name'], 'un Joli Nom');
$crawler = self::$DI['client']->request('POST', $route, $this->getParameters(['name' => 'un Joli Nom']), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
self::$DI['client']->request('POST', $route, $this->getParameters(['name' => 'un Joli Nom']), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
$content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
$this->evaluateResponse200(self::$DI['client']->getResponse());
@@ -1420,7 +1403,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
$this->assertEquals($content['response']['basket']['name'], 'un Joli Nom');
$crawler = self::$DI['client']->request('POST', $route, $this->getParameters(['name' => '<strong>aéaa']), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
self::$DI['client']->request('POST', $route, $this->getParameters(['name' => '<strong>aéaa']), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
$content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
$this->evaluateResponse200(self::$DI['client']->getResponse());
@@ -1660,8 +1643,6 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
*/
public function testFeedList()
{
$title = 'Yellow title';
$created_feed = self::$DI['app']['EM']->find('Alchemy\Phrasea\Model\Entities\Feed', 1);
$this->setToken(self::$token);
@@ -2063,7 +2044,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
protected function evaluateNotFoundRoute($route, $methods)
{
foreach ($methods as $method) {
$crawler = self::$DI['client']->request($method, $route, $this->getParameters(), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
self::$DI['client']->request($method, $route, $this->getParameters(), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
$content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
$this->evaluateResponseNotFound(self::$DI['client']->getResponse());
@@ -2076,32 +2057,36 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
if ($embed['filesize'] === 0) {
var_dump($embed);
}
$subdef = $record->get_subdef($embed['name']);
$this->assertArrayHasKey("name", $embed);
$this->assertArrayHasKey("permalink", $embed);
$this->checkPermalink($embed['permalink'], $record->get_subdef($embed['name']));
$this->checkPermalink($embed['permalink'], $subdef);
$this->assertArrayHasKey("height", $embed);
$this->assertEquals($embed['height'], $record->get_subdef($embed['name'])->get_height());
$this->assertEquals($embed['height'], $subdef->get_height());
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_INT, $embed['height']);
$this->assertArrayHasKey("width", $embed);
$this->assertEquals($embed['width'], $record->get_subdef($embed['name'])->get_width());
$this->assertEquals($embed['width'], $subdef->get_width());
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_INT, $embed['width']);
$this->assertArrayHasKey("filesize", $embed);
$this->assertEquals($embed['filesize'], $record->get_subdef($embed['name'])->get_size());
$this->assertEquals($embed['filesize'], $subdef->get_size());
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_INT, $embed['filesize']);
$this->assertArrayHasKey("player_type", $embed);
$this->assertEquals($embed['player_type'], $record->get_subdef($embed['name'])->get_type());
$this->assertEquals($embed['player_type'], $subdef->get_type());
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $embed['player_type']);
$this->assertArrayHasKey("mime_type", $embed);
$this->assertEquals($embed['mime_type'], $record->get_subdef($embed['name'])->get_mime());
$this->assertEquals($embed['mime_type'], $subdef->get_mime());
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $embed['mime_type']);
$this->assertArrayHasKey("devices", $embed);
$this->assertEquals($embed['devices'], $record->get_subdef($embed['name'])->getDevices());
$this->assertEquals($embed['devices'], $subdef->getDevices());
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $embed['devices']);
}
protected function checkPermalink($permalink, \media_subdef $subdef)
{
if ($subdef->is_physically_present()) {
if (!$subdef->is_physically_present()) {
return;
}
$start = microtime(true);
$this->assertNotNull($subdef->get_permalink());
$this->assertInternalType('array', $permalink);
$this->assertArrayHasKey("created_on", $permalink);
@@ -2140,45 +2125,74 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
$this->checkUrlCode200($permalink['download_url']);
$this->assertPermalinkHeaders($permalink['download_url'], $subdef, "download_url");
}
private function executeRequest($url)
{
static $request = [];
if (isset($request[$url])) {
return $request[$url];
}
static $webserver;
if (null === $webserver) {
try {
$code = self::$DI['local-guzzle']->head('/api/')->send()->getStatusCode();
} catch (GuzzleException $e) {
$code = null;
}
$webserver = ($code < 200 || $code >= 400) ? false : rtrim(self::$DI['app']['phraseanet.registry']->get('GV_ServerName'), '/');
}
if (false === $webserver) {
$this->markTestSkipped('Install does not seem to rely on a webserver');
}
if (0 === strpos($url, $webserver)) {
$url = substr($url, strlen($webserver));
}
return $request[$url] = self::$DI['local-guzzle']->head($url)->send();
}
protected function assertPermalinkHeaders($url, \media_subdef $subdef, $type_url = "page_url")
{
$headers = \http_query::getHttpHeaders($url);
$this->assertEquals(200, $headers["http_code"]);
$response = $this->executeRequest($url);
$this->assertEquals(200, $response->getStatusCode());
switch ($type_url) {
case "page_url" :
$this->assertTrue(strpos($headers['content_type'], "text/html") === 0);
$this->assertNotEquals($subdef->get_size(), $headers["download_content_length"]);
$this->assertTrue(strpos((string) $response->getHeader('content-type'), "text/html") === 0);
if ($response->hasHeader('content-length')) {
$this->assertNotEquals($subdef->get_size(), (string) $response->getHeader('content-length'));
}
break;
case "url" :
$this->assertTrue(strpos($headers['content_type'], $subdef->get_mime()) === 0, 'Verify that header ' . $headers['content_type'] . ' contains subdef mime type ' . $subdef->get_mime());
$this->assertEquals($subdef->get_size(), $headers["download_content_length"]);
$this->assertTrue(strpos((string) $response->getHeader('content-type'), $subdef->get_mime()) === 0, 'Verify that header ' . (string) $response->getHeader('content-type') . ' contains subdef mime type ' . $subdef->get_mime());
if ($response->hasHeader('content-length')) {
$this->assertEquals($subdef->get_size(), (string) $response->getHeader('content-length'));
}
break;
case "download_url" :
$this->assertTrue(strpos($headers['content_type'], $subdef->get_mime()) === 0, 'Verify that header ' . $headers['content_type'] . ' contains subdef mime type ' . $subdef->get_mime());
$this->assertEquals($subdef->get_size(), $headers["download_content_length"]);
$this->assertTrue(strpos((string) $response->getHeader('content-type'), $subdef->get_mime()) === 0, 'Verify that header ' . (string) $response->getHeader('content-type') . ' contains subdef mime type ' . $subdef->get_mime());
if ($response->hasHeader('content-length')) {
$this->assertEquals($subdef->get_size(), (string) $response->getHeader('content-length'));
}
break;
}
}
protected function checkUrlCode200($url)
{
$code = \http_query::getHttpCodeFromUrl(self::$DI['app']['phraseanet.registry']->get('GV_ServerName'));
if ($code == 0) {
$this->markTestSkipped('Install does not seem to rely on a webserver');
}
$code = \http_query::getHttpCodeFromUrl($url);
$response = $this->executeRequest($url);
$code = $response->getStatusCode();
$this->assertEquals(200, $code, sprintf('verification de url %s', $url));
}
protected function evaluateMethodNotAllowedRoute($route, $methods)
{
foreach ($methods as $method) {
$crawler = self::$DI['client']->request($method, $route, $this->getParameters(), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
self::$DI['client']->request($method, $route, $this->getParameters(), [], ['HTTP_Accept' => $this->getAcceptMimeType()]);
$content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
$this->assertTrue(self::$DI['client']->getResponse()->headers->has('Allow'));
$this->evaluateResponseMethodNotAllowed(self::$DI['client']->getResponse());

View File

@@ -2,26 +2,21 @@
namespace Alchemy\Tests\Phrasea\Application;
use Symfony\Component\Yaml\Yaml;
class ApiYamlApplication extends ApiTestCase
{
public function getParameters(array $parameters = [])
protected function getParameters(array $parameters = [])
{
return $parameters;
}
public function unserialize($data)
protected function unserialize($data)
{
try {
$ret = \Symfony\Component\Yaml\Yaml::parse($data);
} catch (\Exception $e) {
$this->fail("Unable to parse data : \n" . $data . "\nexception : " . $e->getMessage() . "\n");
return Yaml::parse($data);
}
return $ret;
}
public function getAcceptMimeType()
protected function getAcceptMimeType()
{
return 'text/yaml';
}

View File

@@ -4,7 +4,6 @@ namespace Alchemy\Tests\Phrasea\Application;
class LightboxTest extends \PhraseanetAuthenticatedWebTestCase
{
protected $client;
protected $feed;
protected $entry;
@@ -20,11 +19,6 @@ class LightboxTest extends \PhraseanetAuthenticatedWebTestCase
->getMock();
}
public function tearDown()
{
parent::tearDown();
}
public function testRouteSlash()
{
$this->authenticate(self::$DI['app']);

View File

@@ -15,47 +15,35 @@ class oauthv2_application_test extends \PhraseanetAuthenticatedWebTestCase
*
* @var API_OAuth2_Application
*/
public static $appli;
public static $account_id;
public static $account;
public $oauth;
protected $client;
protected $queryParameters;
public function bootTestCase()
{
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/')
->set_type(\API_OAuth2_Application::WEB_TYPE);
}
public static function tearDownAfterClass()
{
if (self::$appli !== false) {
self::deleteInsertedRow(self::$DI['app']['phraseanet.appbox'], self::$appli);
}
self::$appli = null;
parent::tearDownAfterClass();
}
public function setUp()
{
parent::setUp();
$environment = 'test';
self::$DI['app'] = require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Api.php';
self::$DI['app'] = self::$DI->share(function ($DI) {
return $this->loadApp('/lib/Alchemy/Phrasea/Application/Api.php');
});
$this->queryParameters = [
"response_type" => "code",
"client_id" => self::$appli->get_client_id(),
"redirect_uri" => self::$appli->get_redirect_uri(),
"client_id" => self::$DI['oauth2-app-user']->get_client_id(),
"redirect_uri" => self::$DI['oauth2-app-user']->get_redirect_uri(),
"scope" => "",
"state" => "valueTest"
];
}
public static function tearDownAfterClass()
{
self::$account_id = self::$account = null;
parent::tearDownAfterClass();
}
public static function deleteInsertedRow(\appbox $appbox, \API_OAuth2_Application $app)
{
$conn = $appbox->get_connection();
@@ -121,7 +109,7 @@ class oauthv2_application_test extends \PhraseanetAuthenticatedWebTestCase
public static function getAccount()
{
$sql = "SELECT api_account_id FROM api_accounts WHERE application_id = :app_id AND usr_id = :usr_id";
$t = [":app_id" => self::$appli->get_id(), ":usr_id" => self::$DI['user']->get_id()];
$t = [":app_id" => self::$DI['oauth2-app-user']->get_id(), ":usr_id" => self::$DI['user']->get_id()];
$conn = self::$DI['app']['phraseanet.appbox']->get_connection();
$stmt = $conn->prepare($sql);
$stmt->execute($t);
@@ -146,7 +134,7 @@ class oauthv2_application_test extends \PhraseanetAuthenticatedWebTestCase
//session off
$apps = \API_OAuth2_Application::load_authorized_app_by_user(self::$DI['app'], self::$DI['user']);
foreach ($apps as $app) {
if ($app->get_client_id() == self::$appli->get_client_id()) {
if ($app->get_client_id() == self::$DI['oauth2-app-user']->get_client_id()) {
$authorize = true;
self::$DI['client']->followRedirects();
@@ -159,10 +147,10 @@ class oauthv2_application_test extends \PhraseanetAuthenticatedWebTestCase
$acc = self::getAccount();
$acc->set_revoked(true); // revoked to show form
$crawler = self::$DI['client']->request('GET', '/api/oauthv2/authorize', $this->queryParameters);
self::$DI['client']->request('GET', '/api/oauthv2/authorize', $this->queryParameters);
$this->assertTrue(self::$DI['client']->getResponse()->isSuccessful());
$this->assertRegExp("/" . self::$appli->get_client_id() . "/", self::$DI['client']->getResponse()->getContent());
$this->assertRegExp("/" . str_replace("/", '\/', self::$appli->get_redirect_uri()) . "/", self::$DI['client']->getResponse()->getContent());
$this->assertRegExp("/" . self::$DI['oauth2-app-user']->get_client_id() . "/", self::$DI['client']->getResponse()->getContent());
$this->assertRegExp("/" . str_replace("/", '\/', self::$DI['oauth2-app-user']->get_redirect_uri()) . "/", self::$DI['client']->getResponse()->getContent());
$this->assertRegExp("/" . $this->queryParameters["response_type"] . "/", self::$DI['client']->getResponse()->getContent());
$this->assertRegExp("/" . $this->queryParameters["scope"] . "/", self::$DI['client']->getResponse()->getContent());
$this->assertRegExp("/" . $this->queryParameters["state"] . "/", self::$DI['client']->getResponse()->getContent());

View File

@@ -27,13 +27,9 @@ class OverviewTest extends \PhraseanetAuthenticatedWebTestCase
public function testEtag()
{
$tmp = tempnam(sys_get_temp_dir(), 'testEtag');
copy(__DIR__ . '/../../../../files/cestlafete.jpg', $tmp);
$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/');
self::$DI['client']->request('GET', '/datafiles/' . $record->get_sbas_id() . '/' . $record->get_record_id() . '/preview/');
$response = self::$DI['client']->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */
@@ -44,8 +40,6 @@ class OverviewTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertEquals(0, $response->getTtl());
$this->assertGreaterThanOrEqual(0, $response->getAge());
$this->assertNull($response->getExpires());
unlink($tmp);
}
public function testDatafilesRouteNotAuthenticated()

View File

@@ -7,40 +7,13 @@ use Alchemy\Phrasea\Border\Attribute\AttributeInterface;
class StoryTest extends \PhraseanetTestCase
{
/**
* @var Story
*/
protected $object;
protected $story;
/**
* @covers Alchemy\Phrasea\Border\Attribute\Attribute
* @covers Alchemy\Phrasea\Border\Attribute\Story::__construct
*/
public function setUp()
{
parent::setUp();
$this->story = \record_adapter::createStory(self::$DI['app'], self::$DI['collection']);;
$this->object = new Story($this->story);
}
/**
* @covers Alchemy\Phrasea\Border\Attribute\Story::__destruct
*/
public function tearDown()
{
$this->story->delete();
$this->object = null;
parent::tearDown();
}
/**
* @covers Alchemy\Phrasea\Border\Attribute\Story::getName
* @todo Implement testGetName().
*/
public function testGetName()
{
$this->assertEquals(AttributeInterface::NAME_STORY, $this->object->getName());
$story = new Story(self::$DI['record_story_1']);
$this->assertEquals(AttributeInterface::NAME_STORY, $story->getName());
}
/**
@@ -48,7 +21,9 @@ class StoryTest extends \PhraseanetTestCase
*/
public function testGetValue()
{
$this->assertSame($this->story, $this->object->getValue());
$record = self::$DI['record_story_1'];
$story = new Story($record);
$this->assertSame($record, $story->getValue());
}
/**
@@ -56,7 +31,8 @@ class StoryTest extends \PhraseanetTestCase
*/
public function testAsString()
{
$this->assertInternalType('string', $this->object->asString());
$story = new Story(self::$DI['record_story_1']);
$this->assertInternalType('string', $story->asString());
}
/**
@@ -64,9 +40,9 @@ class StoryTest extends \PhraseanetTestCase
*/
public function testLoadFromString()
{
$loaded = Story::loadFromString(self::$DI['app'], $this->object->asString());
$this->assertEquals($this->object, $loaded);
$story = new Story(self::$DI['record_story_1']);
$loaded = Story::loadFromString(self::$DI['app'], $story->asString());
$this->assertEquals($story, $loaded);
}
/**

View File

@@ -8,6 +8,12 @@ class Module_Admin_Route_PublicationTest extends \PhraseanetAuthenticatedWebTest
public static $api = null;
protected $client;
public static function tearDownAfterClass()
{
self::$account = self::$api = null;
parent::tearDownAfterClass();
}
public function testList()
{
$crawler = self::$DI['client']->request('GET', '/admin/publications/list/');

View File

@@ -37,6 +37,12 @@ class BridgeApplication extends \PhraseanetAuthenticatedWebTestCase
parent::tearDown();
}
public static function tearDownAfterClass()
{
self::$api = self::$account = null;
parent::tearDownAfterClass();
}
/**
* @todo create a new basket dont take an existing one
*/

View File

@@ -13,7 +13,6 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
* @return Client A Client instance
*/
protected $client;
private static $need_records = false;
public function tearDown()
{

View File

@@ -4,16 +4,12 @@ namespace Alchemy\Tests\Phrasea\Controller\Prod;
class ControllerRootTest extends \PhraseanetAuthenticatedWebTestCase
{
protected $client;
/**
* Default route test
*/
public function testRouteSlash()
{
$this->authenticate(self::$DI['app']);
$crawler = self::$DI['client']->request('GET', '/prod/');
self::$DI['client']->request('GET', '/prod/');
$response = self::$DI['client']->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */

View File

@@ -16,7 +16,6 @@ class UploadTest extends \PhraseanetAuthenticatedWebTestCase
*/
protected $client;
protected $tmpFile;
private static $need_records = false;
public function setUp()
{

View File

@@ -7,26 +7,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class AccountTest extends \PhraseanetAuthenticatedWebTestCase
{
private static $authorizedApp;
public function bootTestCase()
{
try {
self::$authorizedApp = \API_OAuth2_Application::create(self::$DI['app'], self::$DI['user'], 'test API v1');
} catch (\Exception $e) {
}
}
public static function tearDownAfterClass()
{
if (self::$authorizedApp) {
self::$authorizedApp->delete();
}
parent::tearDownAfterClass();
}
/**
* @covers \Alchemy\Phrasea\Controller\Root\Account::displayAccount
* @covers \Alchemy\Phrasea\Controller\Root\Account::call
@@ -351,11 +331,7 @@ class AccountTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testAUthorizedAppGrantAccessSuccessfull($revoke, $expected)
{
if (null === self::$authorizedApp) {
$this->markTestSkipped('Application could not be created');
}
self::$DI['client']->request('GET', '/account/security/application/' . self::$authorizedApp->get_id() . '/grant/', [
self::$DI['client']->request('GET', '/account/security/application/' . self::$DI['oauth2-app-user']->get_id() . '/grant/', [
'revoke' => $revoke
], [], [
'HTTP_ACCEPT' => 'application/json',
@@ -372,7 +348,7 @@ class AccountTest extends \PhraseanetAuthenticatedWebTestCase
$account = \API_OAuth2_Account::load_with_user(
self::$DI['app']
, self::$authorizedApp
, self::$DI['oauth2-app-user']
, self::$DI['user']
);

View File

@@ -89,10 +89,9 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testGetApp()
{
$oauthApp = \API_OAuth2_Application::create(self::$DI['app'], self::$DI['user'], 'test app');
$oauthApp = self::$DI['oauth2-app-user'];
self::$DI['client']->request('GET', '/developers/application/' . $oauthApp->get_id() . '/');
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
$oauthApp->delete();
}
/**
@@ -123,9 +122,7 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase
public function testDeleteApp()
{
$oauthApp = \API_OAuth2_Application::create(self::$DI['app'], self::$DI['user'], 'test app');
$this->XMLHTTPRequest('DELETE', '/developers/application/' . $oauthApp->get_id() . '/');
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
try {
@@ -165,10 +162,8 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testRenewAppCallbackError2()
{
$oauthApp = \API_OAuth2_Application::create(self::$DI['app'], self::$DI['user'], 'test app');
$oauthApp = self::$DI['oauth2-app-user'];
$this->XMLHTTPRequest('POST', '/developers/application/'.$oauthApp->get_id().'/callback/');
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
$content = json_decode(self::$DI['client']->getResponse()->getContent());
$this->assertFalse($content->success);
@@ -179,7 +174,7 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testRenewAppCallback()
{
$oauthApp = \API_OAuth2_Application::create(self::$DI['app'], self::$DI['user'], 'test app');
$oauthApp = self::$DI['oauth2-app-user'];
$this->XMLHTTPRequest('POST', '/developers/application/' . $oauthApp->get_id() . '/callback/', [
'callback' => 'my.callback.com'
@@ -222,7 +217,7 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testRenewAccessToken()
{
$oauthApp = \API_OAuth2_Application::create(self::$DI['app'], self::$DI['user'], 'test app');
$oauthApp = self::$DI['oauth2-app-user'];
$this->XMLHTTPRequest('POST', '/developers/application/' . $oauthApp->get_id() . '/access_token/');
@@ -261,7 +256,7 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase
*/
public function testAuthorizeGrantpasswordToken()
{
$oauthApp = \API_OAuth2_Application::create(self::$DI['app'], self::$DI['user'], 'test app');
$oauthApp = self::$DI['oauth2-app-user'];
$this->XMLHTTPRequest('POST', '/developers/application/' . $oauthApp->get_id() . '/authorize_grant_password/', [
'grant' => '1'

View File

@@ -53,6 +53,12 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
parent::tearDown();
}
public static function tearDownAfterClass()
{
self::$demands = self::$collections = self::$login = self::$email = null;
parent::tearDownAfterClass();
}
public function testRegisterWithNoTou()
{
$this->logout(self::$DI['app']);

View File

@@ -12,19 +12,6 @@ use Symfony\Component\HttpFoundation\Response;
class RssFeedTest extends \PhraseanetWebTestCase
{
private static $initialized = false;
public function setUp()
{
parent::setUp();
if (!self::$initialized) {
@unlink('/tmp/db.sqlite');
copy(__DIR__ . '/../../../../../db-ref.sqlite', '/tmp/db.sqlite');
}
}
public function testPublicFeedAggregated()
{
self::$DI['app']['EM']->find('Alchemy\Phrasea\Model\Entities\Feed', 2);

View File

@@ -35,6 +35,7 @@ class DisplaySettingServiceTest extends \PhraseanetTestCase
self::$DI['app']['conf']->set('registry', self::$appSettings);
}
self::$userSettings = self::$appSettings = null;
parent::tearDownAfterClass();
}

View File

@@ -51,6 +51,12 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
self::$searchEngine->setOptions($options);
}
public static function tearDownAfterClass()
{
self::$searchEngine = self::$searchEngineClass = self::$initialized = null;
parent::tearDownAfterClass();
}
/**
* @return SearchEngineOptions
*/

View File

@@ -105,6 +105,7 @@ class SphinxSearchEngineTest extends SearchEngineAbstractTest
unlink(self::$config);
}
self::$skipped = self::$config = self::$searchd = null;
parent::tearDownAfterClass();
}

View File

@@ -28,6 +28,7 @@ class ACLTest extends \PhraseanetAuthenticatedTestCase
}
self::resetUsersRights(self::$DI['app'], self::$DI['user']);
self::$object = null;
parent::tearDownAfterClass();
}

View File

@@ -44,6 +44,7 @@ class Bridge_Api_AbstractTest extends \PhraseanetWebTestCase
if (self::$account instanceof Bridge_Account) {
self::$account->delete();
}
self::$api = self::$account = null;
parent::tearDownAfterClass();
}

View File

@@ -53,6 +53,9 @@ class Bridge_AccountTest extends \PhraseanetAuthenticatedTestCase
if (self::$api) {
self::$api->delete();
}
self::$object = self::$api = self::$dist_id = self::$named = self::$id = null;
parent::tearDownAfterClass();
}

View File

@@ -2,28 +2,27 @@
class PhraseanetPHPUnitListener implements PHPUnit_Framework_TestListener
{
private static $enableDurationCapture = false;
private static $skipped = [];
private static $duration = [];
private static $csv = [];
private static $durationByTest = [];
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
{
return;
}
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
{
return;
}
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
{
return;
}
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
{
static::$skipped[] = get_class($test) . ':' . $test->getName() . ' - ' . $e->getMessage();
return;
}
public static function getSkipped()
@@ -31,30 +30,89 @@ class PhraseanetPHPUnitListener implements PHPUnit_Framework_TestListener
return static::$skipped;
}
public static function getDuration()
{
return static::$duration;
}
public static function getCsv()
{
return static::$csv;
}
public static function getDurationByTest()
{
return static::$durationByTest;
}
public static function resetSkipped()
{
static::$skipped = [];
}
return;
public static function resetDuration()
{
static::$duration = [];
static::$durationByTest = [];
static::$csv = [];
}
public function startTest(PHPUnit_Framework_Test $test)
{
if (!static::$enableDurationCapture) {
return;
}
if (!isset(static::$durationByTest[get_class($test)]['executions'])) {
static::$durationByTest[get_class($test)]['executions'] = 0;
}
static::$durationByTest[get_class($test)]['executions']++;
static::$duration[self::generateName($test)] = microtime(true);
static::$csv[self::generateName($test)] = [
'duration' => microtime(true),
'test' => get_class($test),
'name' => $test->getName(),
];
}
public function endTest(PHPUnit_Framework_Test $test, $time)
{
if (!static::$enableDurationCapture) {
return;
}
$name = self::generateName($test);
static::$duration[$name] = microtime(true) - static::$duration[$name];
static::$csv[self::generateName($test)]['duration'] = microtime(true) - static::$csv[self::generateName($test)]['duration'];
}
public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
{
if (!static::$enableDurationCapture) {
return;
}
if (!class_exists($suite->getName())) {
return;
}
static::$durationByTest[$suite->getName()]['time'] = microtime(true);
}
public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
{
if (!static::$enableDurationCapture) {
return;
}
if (!class_exists($suite->getName())) {
return;
}
static::$durationByTest[$suite->getName()]['time'] = microtime(true) - static::$durationByTest[$suite->getName()]['time'];
}
private static function generateName(PHPUnit_Framework_Test $test)
{
return get_class($test) . '::' . $test->getName();
}
}

View File

@@ -16,6 +16,7 @@ use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
use Symfony\Component\Routing\RequestContext;
use Alchemy\Tests\Tools\TranslatorMockTrait;
use Guzzle\Http\Client as Guzzle;
abstract class PhraseanetTestCase extends WebTestCase
{
@@ -86,6 +87,10 @@ abstract class PhraseanetTestCase extends WebTestCase
return $this->loadCLI();
});
self::$DI['local-guzzle'] = self::$DI->share(function ($DI) {
return new Guzzle(self::$DI['app']['phraseanet.registry']->get('GV_ServerName'));
});
self::$DI['client'] = self::$DI->share(function ($DI) {
return new Client($DI['app'], []);
});
@@ -109,6 +114,14 @@ abstract class PhraseanetTestCase extends WebTestCase
return User_Adapter::getInstance(self::$fixtureIds['user']['test_phpunit_alt2'], $DI['app']);
});
self::$DI['oauth2-app-user'] = self::$DI->share(function ($DI) {
return new \API_OAuth2_Application($DI['app'], self::$fixtureIds['oauth']['user']);
});
self::$DI['oauth2-app-user_notAdmin'] = self::$DI->share(function ($DI) {
return new \API_OAuth2_Application($DI['app'], self::$fixtureIds['oauth']['user_notAdmin']);
});
self::$DI['logger'] = self::$DI->share(function () {
$logger = new Logger('tests');
$logger->pushHandler(new NullHandler());
@@ -152,7 +165,7 @@ abstract class PhraseanetTestCase extends WebTestCase
});
}
foreach (range(1, 2) as $i) {
foreach (range(1, 3) as $i) {
self::$DI['record_story_' . $i] = self::$DI->share(function ($DI) use ($i) {
return new \record_adapter($DI['app'], self::$fixtureIds['databox']['records'], self::$fixtureIds['record']['record_story_'.$i]);
});
@@ -207,6 +220,7 @@ abstract class PhraseanetTestCase extends WebTestCase
public static function tearDownAfterClass()
{
self::$testCaseBooted = false;
parent::tearDownAfterClass();
}
protected function bootTestCase()
@@ -448,6 +462,26 @@ abstract class PhraseanetTestCase extends WebTestCase
self::$recordsInitialized = [];
}
$duration = PhraseanetPHPUnitListener::getDurationByTest();
$tests = array();
foreach ($duration as $name => $data) {
$tests[$name . '(total : '.$data['time'].' and '.$data['executions'].' executions)'] = $data['time'] / $data['executions'];
}
asort($tests);
$csvData = PhraseanetPHPUnitListener::getCsv();
if (count($csvData) > 0) {
foreach ($csvData as $data) {
file_put_contents(__DIR__ . '/../../report.csv', "\"".implode('","', array_map(function ($value) {
return str_replace('"', '""', $value);
}, $data))."\"\n", FILE_APPEND);
}
}
PhraseanetPHPUnitListener::resetDuration();
return;
}

View File

@@ -14,21 +14,12 @@ class API_OAuth2_AuthCodeTest extends \PhraseanetTestCase
public function setUp()
{
parent::setUp();
$this->application = API_OAuth2_Application::create(self::$DI['app'], self::$DI['user'], 'test app');
$this->account = API_OAuth2_Account::load_with_user(self::$DI['app'], $this->application, self::$DI['user']);
$this->account = API_OAuth2_Account::load_with_user(self::$DI['app'], self::$DI['oauth2-app-user'], self::$DI['user']);
$expires = time() + 100;
$this->code = random::generatePassword(8);
$this->object = API_OAuth2_AuthCode::create(self::$DI['app'], $this->account, $this->code, $expires);
}
public function tearDown()
{
$this->application->delete();
parent::tearDown();
}
public function testGet_code()
{
$this->assertEquals($this->code, $this->object->get_code());

View File

@@ -14,8 +14,7 @@ class API_OAuth2_RefreshTokenTest extends \PhraseanetTestCase
public function setUp()
{
parent::setUp();
$this->application = API_OAuth2_Application::create(self::$DI['app'], self::$DI['user'], 'test app');
$this->account = API_OAuth2_Account::load_with_user(self::$DI['app'], $this->application, self::$DI['user']);
$this->account = API_OAuth2_Account::load_with_user(self::$DI['app'], self::$DI['oauth2-app-user'], self::$DI['user']);
$expires = time() + 100;
$this->token = random::generatePassword(8);
@@ -24,12 +23,6 @@ class API_OAuth2_RefreshTokenTest extends \PhraseanetTestCase
$this->object = API_OAuth2_RefreshToken::create(self::$DI['app'], $this->account, $expires, $this->token, $this->scope);
}
public function tearDown()
{
$this->application->delete();
parent::tearDown();
}
public function testGet_value()
{
$this->assertEquals($this->token, $this->object->get_value());

View File

@@ -2,7 +2,6 @@
class API_OAuth2_AccountTest extends \PhraseanetTestCase
{
/**
* @var API_OAuth2_Account
*/
@@ -11,65 +10,36 @@ class API_OAuth2_AccountTest extends \PhraseanetTestCase
public function setUp()
{
parent::setUp();
$this->application = API_OAuth2_Application::create(self::$DI['app'], self::$DI['user'], 'test app');
$this->object = API_OAuth2_Account::load_with_user(self::$DI['app'], $this->application, self::$DI['user']);
$this->object = API_OAuth2_Account::load_with_user(self::$DI['app'], self::$DI['oauth2-app-user'], self::$DI['user']);
}
public function tearDown()
{
$this->application->delete();
parent::tearDown();
}
public function testGet_id()
public function testGettersAndSetters()
{
$this->assertTrue(is_int($this->object->get_id()));
}
public function testGet_user()
{
$this->assertInstanceOf('User_Adapter', $this->object->get_user());
$this->assertEquals(self::$DI['user']->get_id(), $this->object->get_user()->get_id());
}
public function testGet_api_version()
{
$this->assertEquals('1.0', $this->object->get_api_version());
}
public function testIs_revoked()
{
$this->assertTrue(is_bool($this->object->is_revoked()));
$this->assertFalse($this->object->is_revoked());
}
public function testSet_revoked()
{
$this->object->set_revoked(true);
$this->assertTrue($this->object->is_revoked());
$this->object->set_revoked(false);
$this->assertFalse($this->object->is_revoked());
}
public function testGet_created_on()
{
$this->assertInstanceOf('DateTime', $this->object->get_created_on());
}
public function testGet_token()
{
$this->assertInstanceOf('API_OAuth2_Token', $this->object->get_token());
}
public function testGet_application()
{
$this->assertInstanceOf('API_OAuth2_Application', $this->object->get_application());
$this->assertEquals($this->application, $this->object->get_application());
$this->assertEquals(self::$DI['oauth2-app-user'], $this->object->get_application());
}
public function testLoad_with_user()
{
$loaded = API_OAuth2_Account::load_with_user(self::$DI['app'], $this->application, self::$DI['user']);
$loaded = API_OAuth2_Account::load_with_user(self::$DI['app'], self::$DI['oauth2-app-user'], self::$DI['user']);
$this->assertInstanceOf('API_OAuth2_Account', $loaded);
$this->assertEquals($this->object, $loaded);
}

View File

@@ -2,29 +2,12 @@
class API_OAuth2_ApplicationTest extends \PhraseanetTestCase
{
/**
* @var API_OAuth2_Application
*/
protected $object;
public function setUp()
{
parent::setUp();
$this->object = API_OAuth2_Application::create(self::$DI['app'], self::$DI['user'], 'test app');
}
public function tearDown()
{
$this->object->delete();
parent::tearDown();
}
public function testLoad_from_client_id()
{
$client_id = $this->object->get_client_id();
$client_id = self::$DI['oauth2-app-user']->get_client_id();
$loaded = API_OAuth2_Application::load_from_client_id(self::$DI['app'], $client_id);
$this->assertInstanceOf('API_OAuth2_Application', $loaded);
$this->assertEquals($this->object, $loaded);
$this->assertEquals(self::$DI['oauth2-app-user'], $loaded);
}
public function testLoad_dev_app_by_user()
@@ -34,7 +17,7 @@ class API_OAuth2_ApplicationTest extends \PhraseanetTestCase
$this->assertTrue(count($apps) > 0);
$found = false;
foreach ($apps as $app) {
if ($app->get_id() === $this->object->get_id())
if ($app->get_id() === self::$DI['oauth2-app-user']->get_id())
$found = true;
$this->assertInstanceOf('API_OAuth2_Application', $app);
}
@@ -51,7 +34,7 @@ class API_OAuth2_ApplicationTest extends \PhraseanetTestCase
$found = false;
foreach ($apps as $app) {
if ($app->get_id() === $this->object->get_id())
if ($app->get_id() === self::$DI['oauth2-app-user']->get_id())
$found = true;
$this->assertInstanceOf('API_OAuth2_Application', $app);
}
@@ -60,133 +43,78 @@ class API_OAuth2_ApplicationTest extends \PhraseanetTestCase
$this->fail();
}
public function testGet_id()
public function testGettersAndSetters()
{
$this->assertTrue(is_int($this->object->get_id()));
}
$this->assertTrue(is_int(self::$DI['oauth2-app-user']->get_id()));
$this->assertInstanceOf('User_Adapter', self::$DI['oauth2-app-user']->get_creator());
$this->assertEquals(self::$DI['user']->get_id(), self::$DI['oauth2-app-user']->get_creator()->get_id());
public function testGet_creator()
{
$this->assertInstanceOf('User_Adapter', $this->object->get_creator());
}
$this->assertTrue(in_array(self::$DI['oauth2-app-user']->get_type(), [API_OAuth2_Application::DESKTOP_TYPE, API_OAuth2_Application::WEB_TYPE]));
public function testGet_type()
{
$this->assertTrue(in_array($this->object->get_type(), [API_OAuth2_Application::DESKTOP_TYPE, API_OAuth2_Application::WEB_TYPE]));
}
$this->assertTrue(is_string(self::$DI['oauth2-app-user']->get_nonce()));
$this->assertTrue(strlen(self::$DI['oauth2-app-user']->get_nonce()) === 6);
public function testGet_nonce()
{
$this->assertTrue(is_string($this->object->get_nonce()));
$this->assertTrue(strlen($this->object->get_nonce()) === 6);
}
public function testSet_type()
{
try {
$this->object->set_type('prout');
self::$DI['oauth2-app-user']->set_type('prout');
$this->fail();
} catch (Exception_InvalidArgument $e) {
}
$this->object->set_type(API_OAuth2_Application::WEB_TYPE);
$this->assertEquals(API_OAuth2_Application::WEB_TYPE, $this->object->get_type());
$this->object->set_type(API_OAuth2_Application::DESKTOP_TYPE);
$this->assertEquals(API_OAuth2_Application::DESKTOP_TYPE, $this->object->get_type());
$this->assertEquals(API_OAuth2_Application::NATIVE_APP_REDIRECT_URI, $this->object->get_redirect_uri());
}
self::$DI['oauth2-app-user']->set_type(API_OAuth2_Application::WEB_TYPE);
$this->assertEquals(API_OAuth2_Application::WEB_TYPE, self::$DI['oauth2-app-user']->get_type());
self::$DI['oauth2-app-user']->set_type(API_OAuth2_Application::DESKTOP_TYPE);
$this->assertEquals(API_OAuth2_Application::DESKTOP_TYPE, self::$DI['oauth2-app-user']->get_type());
$this->assertEquals(API_OAuth2_Application::NATIVE_APP_REDIRECT_URI, self::$DI['oauth2-app-user']->get_redirect_uri());
self::$DI['oauth2-app-user']->set_type(API_OAuth2_Application::WEB_TYPE);
public function testGet_name()
{
$this->assertEquals('test app', $this->object->get_name());
}
public function testSet_name()
{
$this->object->set_name('prout');
$this->assertEquals('prout', $this->object->get_name());
}
self::$DI['oauth2-app-user']->set_name('prout');
$this->assertEquals('prout', self::$DI['oauth2-app-user']->get_name());
self::$DI['oauth2-app-user']->set_name('test application for user');
$this->assertEquals('test application for user', self::$DI['oauth2-app-user']->get_name());
public function testGet_description()
{
$this->assertEquals('', $this->object->get_description());
}
public function testSet_description()
{
$desc = 'prouti prouto prout prout';
$this->object->set_description($desc);
$this->assertEquals($desc, $this->object->get_description());
}
self::$DI['oauth2-app-user']->set_description($desc);
$this->assertEquals($desc, self::$DI['oauth2-app-user']->get_description());
self::$DI['oauth2-app-user']->set_description('');
$this->assertEquals('', self::$DI['oauth2-app-user']->get_description());
public function testGet_website()
{
$this->assertEquals('', $this->object->get_website());
}
public function testSet_website()
{
$site = 'http://www.example.com/';
$this->object->set_website($site);
$this->assertEquals($site, $this->object->get_website());
}
self::$DI['oauth2-app-user']->set_website($site);
$this->assertEquals($site, self::$DI['oauth2-app-user']->get_website());
self::$DI['oauth2-app-user']->set_website('');
$this->assertEquals('', self::$DI['oauth2-app-user']->get_website());
public function testGet_created_on()
{
$this->assertInstanceOf('DateTime', $this->object->get_created_on());
}
$this->assertInstanceOf('DateTime', self::$DI['oauth2-app-user']->get_created_on());
public function testGet_last_modified()
{
$this->assertInstanceOf('DateTime', $this->object->get_last_modified());
$this->assertInstanceOf('DateTime', self::$DI['oauth2-app-user']->get_last_modified());
$this->assertMd5(self::$DI['oauth2-app-user']->get_client_id());
$client_id = md5('prouto');
self::$DI['oauth2-app-user']->set_client_id($client_id);
$this->assertEquals($client_id, self::$DI['oauth2-app-user']->get_client_id());
$this->assertMd5(self::$DI['oauth2-app-user']->get_client_id());
$this->assertMd5(self::$DI['oauth2-app-user']->get_client_secret());
$client_secret = md5('prouto');
self::$DI['oauth2-app-user']->set_client_secret($client_secret);
$this->assertEquals($client_secret, self::$DI['oauth2-app-user']->get_client_secret());
$this->assertMd5(self::$DI['oauth2-app-user']->get_client_secret());
$uri = 'http://www.example.com/callback/';
self::$DI['oauth2-app-user']->set_redirect_uri($uri);
$this->assertEquals($uri, self::$DI['oauth2-app-user']->get_redirect_uri());
$this->assertInstanceOf('API_OAuth2_Account', self::$DI['oauth2-app-user']->get_user_account(self::$DI['user']));
}
private function assertmd5($md5)
{
$this->assertTrue((count(preg_match('/[a-z0-9]{32}/', $md5)) === 1));
}
public function testGet_client_id()
{
$this->assertMd5($this->object->get_client_id());
}
public function testSet_client_id()
{
$client_id = md5('prouto');
$this->object->set_client_id($client_id);
$this->assertEquals($client_id, $this->object->get_client_id());
$this->assertMd5($this->object->get_client_id());
}
public function testGet_client_secret()
{
$this->assertMd5($this->object->get_client_secret());
}
public function testSet_client_secret()
{
$client_secret = md5('prouto');
$this->object->set_client_secret($client_secret);
$this->assertEquals($client_secret, $this->object->get_client_secret());
$this->assertMd5($this->object->get_client_secret());
}
public function testGet_redirect_uri()
{
$this->assertEquals('', $this->object->get_redirect_uri());
}
public function testSet_redirect_uri()
{
$uri = 'http://www.example.com/callback/';
$this->object->set_redirect_uri($uri);
$this->assertEquals($uri, $this->object->get_redirect_uri());
}
public function testGet_user_account()
{
$this->assertInstanceOf('API_OAuth2_Account', $this->object->get_user_account(self::$DI['user']));
}
}

View File

@@ -2,7 +2,6 @@
class API_OAuth2_TokenTest extends \PhraseanetTestCase
{
/**
* @var API_OAuth2_Token
*/
@@ -11,8 +10,7 @@ class API_OAuth2_TokenTest extends \PhraseanetTestCase
public function setUp()
{
parent::setUp();
$this->application = API_OAuth2_Application::create(self::$DI['app'], self::$DI['user'], 'test app');
$account = API_OAuth2_Account::load_with_user(self::$DI['app'], $this->application, self::$DI['user']);
$account = API_OAuth2_Account::load_with_user(self::$DI['app'], self::$DI['oauth2-app-user'], self::$DI['user']);
try {
new API_OAuth2_Token(self::$DI['app']['phraseanet.appbox'], $account);
@@ -26,7 +24,7 @@ class API_OAuth2_TokenTest extends \PhraseanetTestCase
public function tearDown()
{
$this->application->delete();
$this->object->delete();
parent::tearDown();
}
@@ -35,59 +33,38 @@ class API_OAuth2_TokenTest extends \PhraseanetTestCase
$this->assertTrue((count(preg_match('/[a-z0-9]{32}/', $md5)) === 1));
}
public function testGet_value()
public function testGettersAndSetters()
{
$this->assertmd5($this->object->get_value());
}
public function testSet_value()
{
$value = md5('prout');
$this->object->set_value($value);
$this->assertEquals($value, $this->object->get_value());
}
public function testGet_session_id()
{
$this->object->set_session_id(null);
$this->assertNull($this->object->get_session_id());
}
public function testSet_session_id()
{
$this->object->set_session_id(458);
$this->assertEquals(458, $this->object->get_session_id());
}
public function testGet_expires()
{
$expire = time() + 3600;
$this->object->set_expires($expire);
$diff = (int) $this->object->get_expires() - time();
$this->assertInternalType('string', $this->object->get_expires(), "expiration timestamp is string : " . $this->object->get_expires());
$this->assertSame($expire, $this->object->get_expires(), "expiration timestamp is string : " . $this->object->get_expires());
$this->assertTrue($diff > 3500, "expire value $diff should be more than 3500 seconds ");
$this->assertTrue($diff < 3700, "expire value $diff should be less than 3700 seconds ");
}
public function testSet_expires()
{
$date = time() + 7200;
$this->object->set_expires($date);
$this->assertEquals($date, $this->object->get_expires());
}
public function testGet_scope()
{
$this->assertNull($this->object->get_scope());
}
public function testset_scope()
{
$this->assertNull($this->object->get_scope());
$scope = "prout";
$this->object->set_scope($scope);
$this->assertEquals($scope, $this->object->get_scope());
}
public function testGet_account()
{
$this->assertInstanceOf('API_OAuth2_Account', $this->object->get_account());
}

View File

@@ -40,8 +40,8 @@ class collectionTest extends \PhraseanetAuthenticatedTestCase
public static function tearDownAfterClass()
{
self::$object->delete();
self::$object = self::$objectDisable = null;
parent::tearDownAfterClass();
}

View File

@@ -5,46 +5,42 @@ class media_Permalink_AdapterTest extends \PhraseanetTestCase
/**
* @var media_Permalink_Adapter
*/
public static $object;
public static $subdef;
private $object;
public function setUp()
{
parent::setUp();
$databox = self::$DI['record_1']->get_databox();
self::$subdef = self::$DI['record_1']->get_subdef('document');
self::$object = media_Permalink_Adapter::getPermalink(self::$DI['app'], $databox, self::$subdef);
$this->object = media_Permalink_Adapter::getPermalink(self::$DI['app'], self::$DI['record_1']->get_databox(), self::$DI['record_1']->get_subdef('document'));
}
public function testGet_label()
{
$this->assertInternalType('string', self::$object->get_label());
$this->assertEquals('test001', self::$object->get_label());
$this->assertSame('test001', $this->object->get_label());
}
public function testGetPermalink()
{
$this->assertTrue((self::$object instanceof media_Permalink_Adapter));
$this->assertTrue(($this->object instanceof media_Permalink_Adapter));
}
public function testSet_is_activated()
{
self::$object->set_is_activated(true);
$this->assertTrue(self::$object->get_is_activated());
self::$object->set_is_activated(false);
$this->assertFalse(self::$object->get_is_activated());
self::$object->set_is_activated(true);
$this->assertTrue(self::$object->get_is_activated());
$this->object->set_is_activated(true);
$this->assertTrue($this->object->get_is_activated());
$this->object->set_is_activated(false);
$this->assertFalse($this->object->get_is_activated());
$this->object->set_is_activated(true);
$this->assertTrue($this->object->get_is_activated());
}
public function testSet_label()
{
self::$object->set_label('coucou les chicos');
$this->assertEquals('coucou-les-chicos', self::$object->get_label());
self::$object->set_label('');
$this->assertEquals('untitled', self::$object->get_label());
self::$object->set_label('JE ANp ra&é"\/,;:!§/.?%µ*ù$]@^\[{#~234567890°+\'(-è_çà');
$this->assertEquals('JE-ANp-raeu234567890-e_ca', self::$object->get_label());
$this->object->set_label('coucou les chicos');
$this->assertEquals('coucou-les-chicos', $this->object->get_label());
$this->object->set_label('');
$this->assertEquals('untitled', $this->object->get_label());
$this->object->set_label('JE ANp ra&é"\/,;:!§/.?%µ*ù$]@^\[{#~234567890°+\'(-è_çà');
$this->assertEquals('JE-ANp-raeu234567890-e_ca', $this->object->get_label());
}
public function testGet_url()
@@ -52,11 +48,11 @@ class media_Permalink_AdapterTest extends \PhraseanetTestCase
$url = rtrim(self::$DI['app']['phraseanet.registry']->get('GV_ServerName'), '/') . '/permalink/v1/'
. self::$DI['record_1']->get_sbas_id() . '/'
. self::$DI['record_1']->get_record_id()
. '/document/' . self::$object->get_label()
. '/document/' . $this->object->get_label()
. '.' . pathinfo(self::$DI['record_1']->get_subdef('document')->get_file(), PATHINFO_EXTENSION)
. '?token=' . self::$object->get_token();
. '?token=' . $this->object->get_token();
$this->assertEquals($url, self::$object->get_url());
$this->assertEquals($url, $this->object->get_url());
}
public function testGet_Previewurl()
@@ -81,34 +77,34 @@ class media_Permalink_AdapterTest extends \PhraseanetTestCase
. self::$DI['record_1']->get_sbas_id() . '/'
. self::$DI['record_1']->get_record_id()
. '/document/'
. '?token=' . self::$object->get_token();
. '?token=' . $this->object->get_token();
$this->assertEquals($url, self::$object->get_page());
$this->assertEquals($url, $this->object->get_page());
}
public function testGet_id()
{
$this->assertInternalType('integer', self::$object->get_id());
$this->assertInternalType('integer', $this->object->get_id());
}
public function testGet_token()
{
$this->assertInternalType('string', self::$object->get_token());
$this->assertInternalType('string', $this->object->get_token());
}
public function testGet_is_activated()
{
$this->assertInternalType('boolean', self::$object->get_is_activated());
$this->assertInternalType('boolean', $this->object->get_is_activated());
}
public function testGet_created_on()
{
$this->assertInstanceOf('DateTime', self::$object->get_created_on());
$this->assertInstanceOf('DateTime', $this->object->get_created_on());
}
public function testGet_last_modified()
{
$this->assertInstanceOf('DateTime', self::$object->get_last_modified());
$this->assertInstanceOf('DateTime', $this->object->get_last_modified());
}
/**
@@ -116,7 +112,6 @@ class media_Permalink_AdapterTest extends \PhraseanetTestCase
*/
public function testCreateAPermalinkAlreadyCreated()
{
$databox = self::$DI['record_1']->get_databox();
media_Permalink_Adapter::create(self::$DI['app'], $databox, self::$DI['record_1']->get_subdef('document'));
media_Permalink_Adapter::create(self::$DI['app'], self::$DI['record_1']->get_databox(), self::$DI['record_1']->get_subdef('document'));
}
}

View File

@@ -8,10 +8,6 @@ class media_subdefTest extends \PhraseanetTestCase
* @var \media_subdef
*/
private static $objectPresent;
/**
* @var \media_subdef
*/
private static $storyPresent;
/**
* @var \media_subdef
@@ -46,10 +42,13 @@ class media_subdefTest extends \PhraseanetTestCase
}
}
$story = \record_adapter::createStory(self::$DI['app'], self::$DI['collection']);
self::$objectNotPresent->remove_file();
self::$storyPresent = $story->get_subdef('thumbnail');
}
public static function tearDownAfterClass()
{
self::$objectPresent = self::$objectNotPresent = self::$recordonbleu = null;
parent::tearDownAfterClass();
}
/**
@@ -66,7 +65,7 @@ class media_subdefTest extends \PhraseanetTestCase
*/
public function testStoryIsNotPhysicallyPresent()
{
$this->assertFalse(self::$storyPresent->is_physically_present());
$this->assertFalse(self::$DI['record_story_3']->get_subdef('thumbnail')->is_physically_present());
}
/**

View File

@@ -2,21 +2,12 @@
class record_adapterTest extends \PhraseanetAuthenticatedTestCase
{
/**
* @var record_adapter
*/
private static $grouping;
private static $initialized;
private static $thumbtitled = false;
public function setUp()
{
parent::setUp();
if (self::$initialized) {
return;
}
/**
* Reset thumbtitle in order to have consistent tests (testGet_title)
*/
@@ -30,6 +21,12 @@ class record_adapterTest extends \PhraseanetAuthenticatedTestCase
}
}
public static function tearDownAfterClass()
{
self::$thumbtitled = null;
parent::tearDownAfterClass();
}
/**
* Check whether a record is delete from order_elements when
* record::delete is call