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(); $DI = new \Pimple();
$this->generateUsers($this->container['EM'], $DI); $this->generateUsers($this->container['EM'], $DI);
$this->insertOauthApps($DI);
$this->generateCollection($DI); $this->generateCollection($DI);
$this->generateRecord($DI); $this->generateRecord($DI);
$this->insertOneStoryInWz($this->container['EM'], $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_alt1'] = $DI['user_alt1']->get_id();
$fixtures['user']['test_phpunit_alt2'] = $DI['user_alt2']->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['databox']['records'] = $DI['databox']->get_sbas_id();
$fixtures['collection']['coll'] = $DI['coll']->get_base_id(); $fixtures['collection']['coll'] = $DI['coll']->get_base_id();
$fixtures['collection']['coll_no_access'] = $DI['coll_no_access']->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_1'] = $DI['record_story_1']->get_record_id();
$fixtures['record']['record_story_2'] = $DI['record_story_2']->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_1'] = $DI['record_1']->get_record_id();
$fixtures['record']['record_2'] = $DI['record_2']->get_record_id(); $fixtures['record']['record_2'] = $DI['record_2']->get_record_id();
@@ -143,6 +148,19 @@ class RegenerateSqliteDb extends Command
return 0; 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) private function insertAuthFailures(EntityManager $em, \Pimple $DI)
{ {
$ip = '192.168.16.178'; $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'); $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']); $story = \record_adapter::createStory($this->container, $DI['coll']);
$story->substitute_subdef('preview', $media, $this->container); if ($i < 3) {
$story->substitute_subdef('thumbnail', $media, $this->container); $story->substitute_subdef('preview', $media, $this->container);
$story->substitute_subdef('thumbnail', $media, $this->container);
}
$DI['record_story_' . $i] = $story; $DI['record_story_' . $i] = $story;
} }
} }

View File

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

View File

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

View File

@@ -9,53 +9,42 @@ class BasketACLTest extends \PhraseanetTestCase
public function testOwnerIsOwner() public function testOwnerIsOwner()
{ {
$basket = self::$DI['app']['EM']->find('Alchemy\Phrasea\Model\Entities\Basket', 4); $basket = self::$DI['app']['EM']->find('Alchemy\Phrasea\Model\Entities\Basket', 4);
$this->assertTrue((new BasketACL())->isOwner($basket, self::$DI['user']));
$acl = new BasketACL();
$this->assertTrue($acl->isOwner($basket, self::$DI['user']));
} }
public function testParticipantIsNotAnOwner() public function testParticipantIsNotAnOwner()
{ {
$basket = self::$DI['app']['EM']->find('Alchemy\Phrasea\Model\Entities\Basket', 4); $basket = self::$DI['app']['EM']->find('Alchemy\Phrasea\Model\Entities\Basket', 4);
$this->assertFalse((new BasketACL())->isOwner($basket, self::$DI['user_alt1']));
$acl = new BasketACL();
$this->assertFalse($acl->isOwner($basket, self::$DI['user_alt1']));
} }
public function testUserIsNotTheOwner() public function testUserIsNotTheOwner()
{ {
$basket = self::$DI['app']['EM']->find('Alchemy\Phrasea\Model\Entities\Basket', 1); $basket = self::$DI['app']['EM']->find('Alchemy\Phrasea\Model\Entities\Basket', 1);
$acl = new BasketACL(); $this->assertFalse((new BasketACL())->isOwner($basket, self::$DI['user_alt1']));
$this->assertFalse($acl->isOwner($basket, self::$DI['user_alt1']));
} }
public function testOwnerHasAccessInValidationEnv() public function testOwnerHasAccessInValidationEnv()
{ {
$basket = self::$DI['app']['EM']->find('Alchemy\Phrasea\Model\Entities\Basket', 4); $basket = self::$DI['app']['EM']->find('Alchemy\Phrasea\Model\Entities\Basket', 4);
$this->assertTrue((new BasketACL())->hasAccess($basket, self::$DI['user']));
$acl = new BasketACL();
$this->assertTrue($acl->hasAccess($basket, self::$DI['user']));
} }
public function testOwnerHasAccess() public function testOwnerHasAccess()
{ {
$basket = self::$DI['app']['EM']->find('Alchemy\Phrasea\Model\Entities\Basket', 1); $basket = self::$DI['app']['EM']->find('Alchemy\Phrasea\Model\Entities\Basket', 1);
$acl = new BasketACL(); $this->assertTrue((new BasketACL())->hasAccess($basket, self::$DI['user']));
$this->assertTrue($acl->hasAccess($basket, self::$DI['user']));
} }
public function testParticipantHasAccess() public function testParticipantHasAccess()
{ {
$basket = self::$DI['app']['EM']->find('Alchemy\Phrasea\Model\Entities\Basket', 4); $basket = self::$DI['app']['EM']->find('Alchemy\Phrasea\Model\Entities\Basket', 4);
$this->assertTrue((new BasketACL())->hasAccess($basket, self::$DI['user_alt1']));
$acl = new BasketACL();
$this->assertTrue($acl->hasAccess($basket, self::$DI['user_alt1']));
} }
public function testUserHasNotAccess() public function testUserHasNotAccess()
{ {
$basket = self::$DI['app']['EM']->find('Alchemy\Phrasea\Model\Entities\Basket', 1); $basket = self::$DI['app']['EM']->find('Alchemy\Phrasea\Model\Entities\Basket', 1);
$acl = new BasketACL(); $this->assertFalse((new BasketACL())->hasAccess($basket, self::$DI['user_alt1']));
$this->assertFalse($acl->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()); $this->assertEquals(200, $response->getStatusCode(), 'Test status code 405 ' . $response->getContent());
} }
public function getParameters(array $parameters = []) protected function getParameters(array $parameters = [])
{ {
$parameters['callback'] = 'jsFunction'; $parameters['callback'] = 'jsFunction';
return $parameters; return $parameters;
} }
public function unserialize($data) protected function unserialize($data)
{ {
if (strpos($data, 'jsFunction(') !== 0) { if (strpos($data, 'jsFunction(') !== 0) {
$this->fail('Invalid JSONP response'); $this->fail('Invalid JSONP response');
@@ -50,7 +50,7 @@ class ApiJSONPApplication extends ApiTestCase
return json_decode(substr($data, 11, -1), true); return json_decode(substr($data, 11, -1), true);
} }
public function getAcceptMimeType() protected function getAcceptMimeType()
{ {
return 'application/json'; return 'application/json';
} }

View File

@@ -4,18 +4,17 @@ namespace Alchemy\Tests\Phrasea\Application;
class ApiJsonApplication extends ApiTestCase class ApiJsonApplication extends ApiTestCase
{ {
protected function getParameters(array $parameters = [])
public function getParameters(array $parameters = [])
{ {
return $parameters; return $parameters;
} }
public function unserialize($data) protected function unserialize($data)
{ {
return json_decode($data, true); return json_decode($data, true);
} }
public function getAcceptMimeType() protected function getAcceptMimeType()
{ {
return 'application/json'; 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; protected $client;
@@ -17,15 +17,9 @@ class ApiRootTest extends \PhraseanetWebTestCase
{ {
parent::setUp(); parent::setUp();
self::$DI['app'] = self::$DI->share(function () { self::$DI['app'] = self::$DI->share(function ($DI) {
$environment = 'test'; return $this->loadApp('/lib/Alchemy/Phrasea/Application/Api.php');
$app = require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Api.php';
$app['debug'] = true;
return $app;
}); });
} }
public function testRoot() public function testRoot()

View File

@@ -7,6 +7,7 @@ use Alchemy\Phrasea\Border\File;
use Alchemy\Phrasea\Core\PhraseaEvents; use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\Authentication\Context; use Alchemy\Phrasea\Authentication\Context;
use Alchemy\Phrasea\Model\Entities\Task; use Alchemy\Phrasea\Model\Entities\Task;
use Guzzle\Common\Exception\GuzzleException;
use Symfony\Component\HttpKernel\Client; use Symfony\Component\HttpKernel\Client;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
@@ -37,12 +38,11 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
* @var \API_OAuth2_Application * @var \API_OAuth2_Application
*/ */
private static $adminApplication; private static $adminApplication;
private static $databoxe_ids = [];
private static $apiInitialized = false; private static $apiInitialized = false;
abstract public function getParameters(array $parameters = []); abstract protected function getParameters(array $parameters = []);
abstract public function unserialize($data); abstract protected function unserialize($data);
abstract public function getAcceptMimeType(); abstract protected function getAcceptMimeType();
public function tearDown() public function tearDown()
{ {
@@ -59,33 +59,19 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
}); });
if (!self::$apiInitialized) { 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::$DI['oauth2-app-user_notAdmin'], self::$DI['user_notAdmin']);
self::$account = \API_OAuth2_Account::load_with_user(self::$DI['app'], self::$oauthApplication, self::$DI['user_notAdmin']);
self::$token = self::$account->get_token()->get_value(); self::$token = self::$account->get_token()->get_value();
self::$adminToken = null; self::$adminAccount = \API_OAuth2_Account::load_with_user(self::$DI['app'], self::$DI['oauth2-app-user'], self::$DI['user']);
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::$adminToken = self::$adminAccount->get_token()->get_value(); self::$adminToken = self::$adminAccount->get_token()->get_value();
self::$apiInitialized = true; self::$apiInitialized = true;
} }
} }
public static function tearDownAfterClass() 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::$apiInitialized = false;
self::$databoxe_ids = [];
self::$token = self::$account = self::$oauthApplication = self::$adminToken self::$token = self::$account = self::$oauthApplication = self::$adminToken
= self::$adminAccount = self::$adminApplication = null; = self::$adminAccount = self::$adminApplication = null;
@@ -168,7 +154,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
$this->assertArrayHasKey('de', $databox['labels']); $this->assertArrayHasKey('de', $databox['labels']);
$this->assertArrayHasKey('nl', $databox['labels']); $this->assertArrayHasKey('nl', $databox['labels']);
$this->assertArrayHasKey('version', $databox); $this->assertArrayHasKey('version', $databox);
self::$databoxe_ids[] = $databox['databox_id']; break;
} }
} }
@@ -596,34 +582,34 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
public function testDataboxCollectionRoute() public function testDataboxCollectionRoute()
{ {
$this->setToken(self::$token); $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/'; $route = '/api/v1/databoxes/' . $databox_id . '/collections/';
$this->evaluateMethodNotAllowedRoute($route, ['POST', 'PUT', 'DELETE']); $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()); $content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
$this->evaluateResponse200(self::$DI['client']->getResponse()); $this->evaluateResponse200(self::$DI['client']->getResponse());
$this->evaluateMeta200($content); $this->evaluateMeta200($content);
$this->assertArrayHasKey('collections', $content['response']); $this->assertArrayHasKey('collections', $content['response']);
foreach ($content['response']['collections'] as $collection) { foreach ($content['response']['collections'] as $collection) {
$this->assertTrue(is_array($collection), 'Une collection est un objet'); $this->assertTrue(is_array($collection), 'Une collection est un objet');
$this->assertArrayHasKey('base_id', $collection); $this->assertArrayHasKey('base_id', $collection);
$this->assertArrayHasKey('collection_id', $collection); $this->assertArrayHasKey('collection_id', $collection);
$this->assertArrayHasKey('name', $collection); $this->assertArrayHasKey('name', $collection);
$this->assertArrayHasKey('labels', $collection); $this->assertArrayHasKey('labels', $collection);
$this->assertArrayHasKey('fr', $collection['labels']); $this->assertArrayHasKey('fr', $collection['labels']);
$this->assertArrayHasKey('en', $collection['labels']); $this->assertArrayHasKey('en', $collection['labels']);
$this->assertArrayHasKey('de', $collection['labels']); $this->assertArrayHasKey('de', $collection['labels']);
$this->assertArrayHasKey('nl', $collection['labels']); $this->assertArrayHasKey('nl', $collection['labels']);
$this->assertArrayHasKey('record_amount', $collection); $this->assertArrayHasKey('record_amount', $collection);
$this->assertTrue(is_int($collection['base_id'])); $this->assertTrue(is_int($collection['base_id']));
$this->assertGreaterThan(0, $collection['base_id']); $this->assertGreaterThan(0, $collection['base_id']);
$this->assertTrue(is_int($collection['collection_id'])); $this->assertTrue(is_int($collection['collection_id']));
$this->assertGreaterThan(0, $collection['collection_id']); $this->assertGreaterThan(0, $collection['collection_id']);
$this->assertTrue(is_string($collection['name'])); $this->assertTrue(is_string($collection['name']));
$this->assertTrue(is_int($collection['record_amount'])); $this->assertTrue(is_int($collection['record_amount']));
} break;
} }
$route = '/api/v1/databoxes/24892534/collections/'; $route = '/api/v1/databoxes/24892534/collections/';
$this->evaluateNotFoundRoute($route, ['GET']); $this->evaluateNotFoundRoute($route, ['GET']);
@@ -640,43 +626,43 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
public function testDataboxStatusRoute() public function testDataboxStatusRoute()
{ {
$this->setToken(self::$token); $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); $databox = self::$DI['app']['phraseanet.appbox']->get_databox($databox_id);
$ref_status = $databox->get_statusbits(); $ref_status = $databox->get_statusbits();
$route = '/api/v1/databoxes/' . $databox_id . '/status/'; $route = '/api/v1/databoxes/' . $databox_id . '/status/';
$this->evaluateMethodNotAllowedRoute($route, ['POST', 'PUT', 'DELETE']); $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()); $content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
$this->evaluateResponse200(self::$DI['client']->getResponse()); $this->evaluateResponse200(self::$DI['client']->getResponse());
$this->evaluateMeta200($content); $this->evaluateMeta200($content);
$this->assertArrayHasKey('status', $content['response']); $this->assertArrayHasKey('status', $content['response']);
foreach ($content['response']['status'] as $status) { foreach ($content['response']['status'] as $status) {
$this->assertTrue(is_array($status), 'Un bloc status est un objet'); $this->assertTrue(is_array($status), 'Un bloc status est un objet');
$this->assertArrayHasKey('bit', $status); $this->assertArrayHasKey('bit', $status);
$this->assertTrue(is_int($status['bit'])); $this->assertTrue(is_int($status['bit']));
$this->assertGreaterThan(3, $status['bit']); $this->assertGreaterThan(3, $status['bit']);
$this->assertLessThan(65, $status['bit']); $this->assertLessThan(65, $status['bit']);
$this->assertArrayHasKey('label_on', $status); $this->assertArrayHasKey('label_on', $status);
$this->assertArrayHasKey('label_off', $status); $this->assertArrayHasKey('label_off', $status);
$this->assertArrayHasKey('labels', $status); $this->assertArrayHasKey('labels', $status);
$this->assertArrayHasKey('fr', $status['labels']); $this->assertArrayHasKey('fr', $status['labels']);
$this->assertArrayHasKey('en', $status['labels']); $this->assertArrayHasKey('en', $status['labels']);
$this->assertArrayHasKey('de', $status['labels']); $this->assertArrayHasKey('de', $status['labels']);
$this->assertArrayHasKey('nl', $status['labels']); $this->assertArrayHasKey('nl', $status['labels']);
$this->assertArrayHasKey('img_on', $status); $this->assertArrayHasKey('img_on', $status);
$this->assertArrayHasKey('img_off', $status); $this->assertArrayHasKey('img_off', $status);
$this->assertArrayHasKey('searchable', $status); $this->assertArrayHasKey('searchable', $status);
$this->assertArrayHasKey('printable', $status); $this->assertArrayHasKey('printable', $status);
$this->assertTrue(is_bool($status['searchable'])); $this->assertTrue(is_bool($status['searchable']));
$this->assertTrue($status['searchable'] === (bool) $ref_status[$status['bit']]['searchable']); $this->assertTrue($status['searchable'] === (bool) $ref_status[$status['bit']]['searchable']);
$this->assertTrue(is_bool($status['printable'])); $this->assertTrue(is_bool($status['printable']));
$this->assertTrue($status['printable'] === (bool) $ref_status[$status['bit']]['printable']); $this->assertTrue($status['printable'] === (bool) $ref_status[$status['bit']]['printable']);
$this->assertTrue($status['label_on'] === $ref_status[$status['bit']]['labelon']); $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_off'] === $ref_status[$status['bit']]['img_off']);
$this->assertTrue($status['img_on'] === $ref_status[$status['bit']]['img_on']); $this->assertTrue($status['img_on'] === $ref_status[$status['bit']]['img_on']);
} break;
} }
$route = '/api/v1/databoxes/24892534/status/'; $route = '/api/v1/databoxes/24892534/status/';
$this->evaluateNotFoundRoute($route, ['GET']); $this->evaluateNotFoundRoute($route, ['GET']);
@@ -694,77 +680,77 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
public function testDataboxMetadatasRoute() public function testDataboxMetadatasRoute()
{ {
$this->setToken(self::$token); $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); $databox = self::$DI['app']['phraseanet.appbox']->get_databox($databox_id);
$ref_structure = $databox->get_meta_structure(); $ref_structure = $databox->get_meta_structure();
try { try {
$ref_structure->get_element('idbarbouze'); $ref_structure->get_element('idbarbouze');
$this->fail('An expected exception has not been raised.'); $this->fail('An expected exception has not been raised.');
} catch (\Exception_Databox_FieldNotFound $e) { } catch (\Exception_Databox_FieldNotFound $e) {
}
$route = '/api/v1/databoxes/' . $databox_id . '/metadatas/';
$this->evaluateMethodNotAllowedRoute($route, ['POST', 'PUT', 'DELETE']);
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);
$this->assertArrayHasKey('document_metadatas', $content['response']);
foreach ($content['response']['document_metadatas'] as $metadatas) {
$this->assertTrue(is_array($metadatas), 'Un bloc metadata est un objet');
$this->assertArrayHasKey('id', $metadatas);
$this->assertArrayHasKey('namespace', $metadatas);
$this->assertArrayHasKey('source', $metadatas);
$this->assertArrayHasKey('tagname', $metadatas);
$this->assertArrayHasKey('name', $metadatas);
$this->assertArrayHasKey('separator', $metadatas);
$this->assertArrayHasKey('thesaurus_branch', $metadatas);
$this->assertArrayHasKey('type', $metadatas);
$this->assertArrayHasKey('labels', $metadatas);
$this->assertArrayHasKey('indexable', $metadatas);
$this->assertArrayHasKey('multivalue', $metadatas);
$this->assertArrayHasKey('readonly', $metadatas);
$this->assertArrayHasKey('required', $metadatas);
$this->assertTrue(is_int($metadatas['id']));
$this->assertTrue(is_string($metadatas['namespace']));
$this->assertTrue(is_string($metadatas['name']));
$this->assertTrue(is_array($metadatas['labels']));
$this->assertTrue(is_null($metadatas['source']) || is_string($metadatas['source']));
$this->assertTrue(is_string($metadatas['tagname']));
$this->assertTrue((strlen($metadatas['name']) > 0));
$this->assertTrue(is_string($metadatas['separator']));
$this->assertEquals(['fr', 'en', 'de', 'nl'], array_keys($metadatas['labels']));
if ($metadatas['multivalue']) {
$this->assertTrue((strlen($metadatas['separator']) > 0));
} }
$route = '/api/v1/databoxes/' . $databox_id . '/metadatas/'; $this->assertTrue(is_string($metadatas['thesaurus_branch']));
$this->evaluateMethodNotAllowedRoute($route, ['POST', 'PUT', 'DELETE']); $this->assertTrue(in_array($metadatas['type'], [\databox_field::TYPE_DATE, \databox_field::TYPE_STRING, \databox_field::TYPE_NUMBER, \databox_field::TYPE_TEXT]));
$this->assertTrue(is_bool($metadatas['indexable']));
$this->assertTrue(is_bool($metadatas['multivalue']));
$this->assertTrue(is_bool($metadatas['readonly']));
$this->assertTrue(is_bool($metadatas['required']));
$crawler = self::$DI['client']->request('GET', $route, $this->getParameters(), [], ['HTTP_Accept' => $this->getAcceptMimeType()]); $element = $ref_structure->get_element($metadatas['id']);
$content = $this->unserialize(self::$DI['client']->getResponse()->getContent()); $this->assertTrue($element->is_indexable() === $metadatas['indexable']);
$this->evaluateResponse200(self::$DI['client']->getResponse()); $this->assertTrue($element->is_required() === $metadatas['required']);
$this->evaluateMeta200($content); $this->assertTrue($element->is_readonly() === $metadatas['readonly']);
$this->assertTrue($element->is_multi() === $metadatas['multivalue']);
$this->assertArrayHasKey('document_metadatas', $content['response']); $this->assertTrue($element->get_type() === $metadatas['type']);
foreach ($content['response']['document_metadatas'] as $metadatas) { $this->assertTrue($element->get_tbranch() === $metadatas['thesaurus_branch']);
$this->assertTrue(is_array($metadatas), 'Un bloc metadata est un objet'); $this->assertTrue($element->get_separator() === $metadatas['separator']);
$this->assertArrayHasKey('id', $metadatas); $this->assertTrue($element->get_name() === $metadatas['name']);
$this->assertArrayHasKey('namespace', $metadatas); $this->assertTrue($element->get_tag()->getName() === $metadatas['tagname']);
$this->assertArrayHasKey('source', $metadatas); $this->assertTrue($element->get_tag()->getTagname() === $metadatas['source']);
$this->assertArrayHasKey('tagname', $metadatas); $this->assertTrue($element->get_tag()->getGroupName() === $metadatas['namespace']);
$this->assertArrayHasKey('name', $metadatas); break;
$this->assertArrayHasKey('separator', $metadatas);
$this->assertArrayHasKey('thesaurus_branch', $metadatas);
$this->assertArrayHasKey('type', $metadatas);
$this->assertArrayHasKey('labels', $metadatas);
$this->assertArrayHasKey('indexable', $metadatas);
$this->assertArrayHasKey('multivalue', $metadatas);
$this->assertArrayHasKey('readonly', $metadatas);
$this->assertArrayHasKey('required', $metadatas);
$this->assertTrue(is_int($metadatas['id']));
$this->assertTrue(is_string($metadatas['namespace']));
$this->assertTrue(is_string($metadatas['name']));
$this->assertTrue(is_array($metadatas['labels']));
$this->assertTrue(is_null($metadatas['source']) || is_string($metadatas['source']));
$this->assertTrue(is_string($metadatas['tagname']));
$this->assertTrue((strlen($metadatas['name']) > 0));
$this->assertTrue(is_string($metadatas['separator']));
$this->assertEquals(['fr', 'en', 'de', 'nl'], array_keys($metadatas['labels']));
if ($metadatas['multivalue']) {
$this->assertTrue((strlen($metadatas['separator']) > 0));
}
$this->assertTrue(is_string($metadatas['thesaurus_branch']));
$this->assertTrue(in_array($metadatas['type'], [\databox_field::TYPE_DATE, \databox_field::TYPE_STRING, \databox_field::TYPE_NUMBER, \databox_field::TYPE_TEXT]));
$this->assertTrue(is_bool($metadatas['indexable']));
$this->assertTrue(is_bool($metadatas['multivalue']));
$this->assertTrue(is_bool($metadatas['readonly']));
$this->assertTrue(is_bool($metadatas['required']));
$element = $ref_structure->get_element($metadatas['id']);
$this->assertTrue($element->is_indexable() === $metadatas['indexable']);
$this->assertTrue($element->is_required() === $metadatas['required']);
$this->assertTrue($element->is_readonly() === $metadatas['readonly']);
$this->assertTrue($element->is_multi() === $metadatas['multivalue']);
$this->assertTrue($element->get_type() === $metadatas['type']);
$this->assertTrue($element->get_tbranch() === $metadatas['thesaurus_branch']);
$this->assertTrue($element->get_separator() === $metadatas['separator']);
$this->assertTrue($element->get_name() === $metadatas['name']);
$this->assertTrue($element->get_tag()->getName() === $metadatas['tagname']);
$this->assertTrue($element->get_tag()->getTagname() === $metadatas['source']);
$this->assertTrue($element->get_tag()->getGroupName() === $metadatas['namespace']);
}
} }
$route = '/api/v1/databoxes/24892534/metadatas/'; $route = '/api/v1/databoxes/24892534/metadatas/';
$this->evaluateNotFoundRoute($route, ['GET']); $this->evaluateNotFoundRoute($route, ['GET']);
@@ -782,22 +768,22 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
public function testDataboxTermsOfUseRoute() public function testDataboxTermsOfUseRoute()
{ {
$this->setToken(self::$token); $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/'; $route = '/api/v1/databoxes/' . $databox_id . '/termsOfUse/';
$this->evaluateMethodNotAllowedRoute($route, ['POST', 'PUT', 'DELETE']); $this->evaluateMethodNotAllowedRoute($route, ['POST', 'PUT', 'DELETE']);
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()); $content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
$this->evaluateResponse200(self::$DI['client']->getResponse()); $this->evaluateResponse200(self::$DI['client']->getResponse());
$this->evaluateMeta200($content); $this->evaluateMeta200($content);
$this->assertArrayHasKey('termsOfUse', $content['response']); $this->assertArrayHasKey('termsOfUse', $content['response']);
foreach ($content['response']['termsOfUse'] as $terms) { foreach ($content['response']['termsOfUse'] as $terms) {
$this->assertTrue(is_array($terms), 'Une bloc cgu est un objet'); $this->assertTrue(is_array($terms), 'Une bloc cgu est un objet');
$this->assertArrayHasKey('locale', $terms); $this->assertArrayHasKey('locale', $terms);
$this->assertTrue(in_array($terms['locale'], array_keys(Application::getAvailableLanguages()))); $this->assertTrue(in_array($terms['locale'], array_keys(Application::getAvailableLanguages())));
$this->assertArrayHasKey('terms', $terms); $this->assertArrayHasKey('terms', $terms);
} break;
} }
$route = '/api/v1/databoxes/24892534/termsOfUse/'; $route = '/api/v1/databoxes/24892534/termsOfUse/';
$this->evaluateNotFoundRoute($route, ['GET']); $this->evaluateNotFoundRoute($route, ['GET']);
@@ -815,7 +801,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
public function testSearchRoute() public function testSearchRoute()
{ {
$this->setToken(self::$token); $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()); $content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
$this->evaluateResponse200(self::$DI['client']->getResponse()); $this->evaluateResponse200(self::$DI['client']->getResponse());
@@ -852,7 +838,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
self::$DI['record_story_1']; 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()); $content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
$this->evaluateResponse200(self::$DI['client']->getResponse()); $this->evaluateResponse200(self::$DI['client']->getResponse());
@@ -885,7 +871,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
public function testRecordsSearchRoute() public function testRecordsSearchRoute()
{ {
$this->setToken(self::$token); $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()); $content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
$this->evaluateResponse200(self::$DI['client']->getResponse()); $this->evaluateResponse200(self::$DI['client']->getResponse());
@@ -897,6 +883,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
foreach ($response['results'] as $record) { foreach ($response['results'] as $record) {
$this->evaluateGoodRecord($record); $this->evaluateGoodRecord($record);
break;
} }
} }
@@ -915,7 +902,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock() ->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() public function provideAvailableSearchMethods()
@@ -1013,8 +1000,6 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
{ {
$this->setToken(self::$token); $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/'; $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']); $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/'; $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()); $content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
$this->assertArrayHasKey('embed', $content['response']); $this->assertArrayHasKey('embed', $content['response']);
foreach ($content['response']['embed'] as $embed) { $this->assertEquals(0, count($content['response']['embed']));
$this->checkEmbed($embed, self::$DI['record_1']);
}
} }
/** /**
@@ -1213,7 +1196,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
} }
$this->evaluateMethodNotAllowedRoute($route, ['GET', 'PUT', 'DELETE']); $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()); $content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
/** /**
@@ -1235,7 +1218,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
$tochange[$n] = $value == '0' ? '1' : '0'; $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()); $content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
/** /**
@@ -1394,7 +1377,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
$this->evaluateMethodNotAllowedRoute($route, ['GET', 'PUT', 'DELETE']); $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()); $content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
$this->evaluateResponse200(self::$DI['client']->getResponse()); $this->evaluateResponse200(self::$DI['client']->getResponse());
@@ -1406,7 +1389,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
$this->assertEquals($content['response']['basket']['name'], 'un Joli Nom'); $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()); $content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
$this->evaluateResponse200(self::$DI['client']->getResponse()); $this->evaluateResponse200(self::$DI['client']->getResponse());
@@ -1420,7 +1403,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
$this->assertEquals($content['response']['basket']['name'], 'un Joli Nom'); $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()); $content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
$this->evaluateResponse200(self::$DI['client']->getResponse()); $this->evaluateResponse200(self::$DI['client']->getResponse());
@@ -1660,8 +1643,6 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
*/ */
public function testFeedList() public function testFeedList()
{ {
$title = 'Yellow title';
$created_feed = self::$DI['app']['EM']->find('Alchemy\Phrasea\Model\Entities\Feed', 1); $created_feed = self::$DI['app']['EM']->find('Alchemy\Phrasea\Model\Entities\Feed', 1);
$this->setToken(self::$token); $this->setToken(self::$token);
@@ -2063,7 +2044,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
protected function evaluateNotFoundRoute($route, $methods) protected function evaluateNotFoundRoute($route, $methods)
{ {
foreach ($methods as $method) { 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()); $content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
$this->evaluateResponseNotFound(self::$DI['client']->getResponse()); $this->evaluateResponseNotFound(self::$DI['client']->getResponse());
@@ -2076,109 +2057,142 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
if ($embed['filesize'] === 0) { if ($embed['filesize'] === 0) {
var_dump($embed); var_dump($embed);
} }
$subdef = $record->get_subdef($embed['name']);
$this->assertArrayHasKey("name", $embed); $this->assertArrayHasKey("name", $embed);
$this->assertArrayHasKey("permalink", $embed); $this->assertArrayHasKey("permalink", $embed);
$this->checkPermalink($embed['permalink'], $record->get_subdef($embed['name'])); $this->checkPermalink($embed['permalink'], $subdef);
$this->assertArrayHasKey("height", $embed); $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->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_INT, $embed['height']);
$this->assertArrayHasKey("width", $embed); $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->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_INT, $embed['width']);
$this->assertArrayHasKey("filesize", $embed); $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->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_INT, $embed['filesize']);
$this->assertArrayHasKey("player_type", $embed); $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->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $embed['player_type']);
$this->assertArrayHasKey("mime_type", $embed); $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->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $embed['mime_type']);
$this->assertArrayHasKey("devices", $embed); $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']); $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $embed['devices']);
} }
protected function checkPermalink($permalink, \media_subdef $subdef) protected function checkPermalink($permalink, \media_subdef $subdef)
{ {
if ($subdef->is_physically_present()) { if (!$subdef->is_physically_present()) {
$this->assertNotNull($subdef->get_permalink()); return;
$this->assertInternalType('array', $permalink);
$this->assertArrayHasKey("created_on", $permalink);
$now = new \Datetime($permalink['created_on']);
$interval = $now->diff($subdef->get_permalink()->get_created_on());
$this->assertTrue(abs($interval->format('U')) < 2);
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['created_on']);
$this->assertDateAtom($permalink['created_on']);
$this->assertArrayHasKey("id", $permalink);
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_INT, $permalink['id']);
$this->assertEquals($subdef->get_permalink()->get_id(), $permalink['id']);
$this->assertArrayHasKey("is_activated", $permalink);
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_BOOL, $permalink['is_activated']);
$this->assertEquals($subdef->get_permalink()->get_is_activated(), $permalink['is_activated']);
$this->assertArrayHasKey("label", $permalink);
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['label']);
$this->assertArrayHasKey("updated_on", $permalink);
$this->assertEquals($subdef->get_permalink()->get_last_modified()->format(DATE_ATOM), $permalink['updated_on']);
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['updated_on']);
$this->assertDateAtom($permalink['updated_on']);
$this->assertArrayHasKey("page_url", $permalink);
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['page_url']);
$this->assertEquals($subdef->get_permalink()->get_page(self::$DI['app']['phraseanet.registry']), $permalink['page_url']);
$this->checkUrlCode200($permalink['page_url']);
$this->assertPermalinkHeaders($permalink['page_url'], $subdef);
$this->assertArrayHasKey("url", $permalink);
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['url']);
$this->assertEquals($subdef->get_permalink()->get_url(), $permalink['url']);
$this->checkUrlCode200($permalink['url']);
$this->assertPermalinkHeaders($permalink['url'], $subdef, "url");
$this->assertArrayHasKey("download_url", $permalink);
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['download_url']);
$this->assertEquals($subdef->get_permalink()->get_url() . '&download', $permalink['download_url']);
$this->checkUrlCode200($permalink['download_url']);
$this->assertPermalinkHeaders($permalink['download_url'], $subdef, "download_url");
} }
$start = microtime(true);
$this->assertNotNull($subdef->get_permalink());
$this->assertInternalType('array', $permalink);
$this->assertArrayHasKey("created_on", $permalink);
$now = new \Datetime($permalink['created_on']);
$interval = $now->diff($subdef->get_permalink()->get_created_on());
$this->assertTrue(abs($interval->format('U')) < 2);
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['created_on']);
$this->assertDateAtom($permalink['created_on']);
$this->assertArrayHasKey("id", $permalink);
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_INT, $permalink['id']);
$this->assertEquals($subdef->get_permalink()->get_id(), $permalink['id']);
$this->assertArrayHasKey("is_activated", $permalink);
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_BOOL, $permalink['is_activated']);
$this->assertEquals($subdef->get_permalink()->get_is_activated(), $permalink['is_activated']);
$this->assertArrayHasKey("label", $permalink);
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['label']);
$this->assertArrayHasKey("updated_on", $permalink);
$this->assertEquals($subdef->get_permalink()->get_last_modified()->format(DATE_ATOM), $permalink['updated_on']);
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['updated_on']);
$this->assertDateAtom($permalink['updated_on']);
$this->assertArrayHasKey("page_url", $permalink);
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['page_url']);
$this->assertEquals($subdef->get_permalink()->get_page(self::$DI['app']['phraseanet.registry']), $permalink['page_url']);
$this->checkUrlCode200($permalink['page_url']);
$this->assertPermalinkHeaders($permalink['page_url'], $subdef);
$this->assertArrayHasKey("url", $permalink);
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['url']);
$this->assertEquals($subdef->get_permalink()->get_url(), $permalink['url']);
$this->checkUrlCode200($permalink['url']);
$this->assertPermalinkHeaders($permalink['url'], $subdef, "url");
$this->assertArrayHasKey("download_url", $permalink);
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['download_url']);
$this->assertEquals($subdef->get_permalink()->get_url() . '&download', $permalink['download_url']);
$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") protected function assertPermalinkHeaders($url, \media_subdef $subdef, $type_url = "page_url")
{ {
$headers = \http_query::getHttpHeaders($url); $response = $this->executeRequest($url);
$this->assertEquals(200, $headers["http_code"]);
$this->assertEquals(200, $response->getStatusCode());
switch ($type_url) { switch ($type_url) {
case "page_url" : case "page_url" :
$this->assertTrue(strpos($headers['content_type'], "text/html") === 0); $this->assertTrue(strpos((string) $response->getHeader('content-type'), "text/html") === 0);
$this->assertNotEquals($subdef->get_size(), $headers["download_content_length"]); if ($response->hasHeader('content-length')) {
$this->assertNotEquals($subdef->get_size(), (string) $response->getHeader('content-length'));
}
break; break;
case "url" : 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->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());
$this->assertEquals($subdef->get_size(), $headers["download_content_length"]); if ($response->hasHeader('content-length')) {
$this->assertEquals($subdef->get_size(), (string) $response->getHeader('content-length'));
}
break; break;
case "download_url" : 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->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());
$this->assertEquals($subdef->get_size(), $headers["download_content_length"]); if ($response->hasHeader('content-length')) {
$this->assertEquals($subdef->get_size(), (string) $response->getHeader('content-length'));
}
break; break;
} }
} }
protected function checkUrlCode200($url) protected function checkUrlCode200($url)
{ {
$code = \http_query::getHttpCodeFromUrl(self::$DI['app']['phraseanet.registry']->get('GV_ServerName')); $response = $this->executeRequest($url);
$code = $response->getStatusCode();
if ($code == 0) {
$this->markTestSkipped('Install does not seem to rely on a webserver');
}
$code = \http_query::getHttpCodeFromUrl($url);
$this->assertEquals(200, $code, sprintf('verification de url %s', $url)); $this->assertEquals(200, $code, sprintf('verification de url %s', $url));
} }
protected function evaluateMethodNotAllowedRoute($route, $methods) protected function evaluateMethodNotAllowedRoute($route, $methods)
{ {
foreach ($methods as $method) { 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()); $content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
$this->assertTrue(self::$DI['client']->getResponse()->headers->has('Allow')); $this->assertTrue(self::$DI['client']->getResponse()->headers->has('Allow'));
$this->evaluateResponseMethodNotAllowed(self::$DI['client']->getResponse()); $this->evaluateResponseMethodNotAllowed(self::$DI['client']->getResponse());

View File

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

View File

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

View File

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

View File

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

View File

@@ -7,40 +7,13 @@ use Alchemy\Phrasea\Border\Attribute\AttributeInterface;
class StoryTest extends \PhraseanetTestCase 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 * @covers Alchemy\Phrasea\Border\Attribute\Story::getName
* @todo Implement testGetName().
*/ */
public function 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() 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() 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() public function testLoadFromString()
{ {
$loaded = Story::loadFromString(self::$DI['app'], $this->object->asString()); $story = new Story(self::$DI['record_story_1']);
$loaded = Story::loadFromString(self::$DI['app'], $story->asString());
$this->assertEquals($this->object, $loaded); $this->assertEquals($story, $loaded);
} }
/** /**

View File

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

View File

@@ -37,6 +37,12 @@ class BridgeApplication extends \PhraseanetAuthenticatedWebTestCase
parent::tearDown(); parent::tearDown();
} }
public static function tearDownAfterClass()
{
self::$api = self::$account = null;
parent::tearDownAfterClass();
}
/** /**
* @todo create a new basket dont take an existing one * @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 * @return Client A Client instance
*/ */
protected $client; protected $client;
private static $need_records = false;
public function tearDown() public function tearDown()
{ {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -12,19 +12,6 @@ use Symfony\Component\HttpFoundation\Response;
class RssFeedTest extends \PhraseanetWebTestCase 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() public function testPublicFeedAggregated()
{ {
self::$DI['app']['EM']->find('Alchemy\Phrasea\Model\Entities\Feed', 2); 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::$DI['app']['conf']->set('registry', self::$appSettings);
} }
self::$userSettings = self::$appSettings = null;
parent::tearDownAfterClass(); parent::tearDownAfterClass();
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -2,28 +2,27 @@
class PhraseanetPHPUnitListener implements PHPUnit_Framework_TestListener class PhraseanetPHPUnitListener implements PHPUnit_Framework_TestListener
{ {
private static $enableDurationCapture = false;
private static $skipped = []; private static $skipped = [];
private static $duration = [];
private static $csv = [];
private static $durationByTest = [];
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
{ {
return;
} }
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
{ {
return;
} }
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
{ {
return;
} }
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
{ {
static::$skipped[] = get_class($test) . ':' . $test->getName() . ' - ' . $e->getMessage(); static::$skipped[] = get_class($test) . ':' . $test->getName() . ' - ' . $e->getMessage();
return;
} }
public static function getSkipped() public static function getSkipped()
@@ -31,30 +30,89 @@ class PhraseanetPHPUnitListener implements PHPUnit_Framework_TestListener
return static::$skipped; 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() public static function resetSkipped()
{ {
static::$skipped = []; static::$skipped = [];
}
return; public static function resetDuration()
{
static::$duration = [];
static::$durationByTest = [];
static::$csv = [];
} }
public function startTest(PHPUnit_Framework_Test $test) public function startTest(PHPUnit_Framework_Test $test)
{ {
return; 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) public function endTest(PHPUnit_Framework_Test $test, $time)
{ {
return; 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) public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
{ {
return; if (!static::$enableDurationCapture) {
return;
}
if (!class_exists($suite->getName())) {
return;
}
static::$durationByTest[$suite->getName()]['time'] = microtime(true);
} }
public function endTestSuite(PHPUnit_Framework_TestSuite $suite) public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
{ {
return; 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 Symfony\Component\Routing\RequestContext;
use Alchemy\Tests\Tools\TranslatorMockTrait; use Alchemy\Tests\Tools\TranslatorMockTrait;
use Guzzle\Http\Client as Guzzle;
abstract class PhraseanetTestCase extends WebTestCase abstract class PhraseanetTestCase extends WebTestCase
{ {
@@ -86,6 +87,10 @@ abstract class PhraseanetTestCase extends WebTestCase
return $this->loadCLI(); 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) { self::$DI['client'] = self::$DI->share(function ($DI) {
return new Client($DI['app'], []); 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']); 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 () { self::$DI['logger'] = self::$DI->share(function () {
$logger = new Logger('tests'); $logger = new Logger('tests');
$logger->pushHandler(new NullHandler()); $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) { 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]); 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() public static function tearDownAfterClass()
{ {
self::$testCaseBooted = false; self::$testCaseBooted = false;
parent::tearDownAfterClass();
} }
protected function bootTestCase() protected function bootTestCase()
@@ -448,6 +462,26 @@ abstract class PhraseanetTestCase extends WebTestCase
self::$recordsInitialized = []; 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; return;
} }

View File

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

View File

@@ -14,8 +14,7 @@ class API_OAuth2_RefreshTokenTest extends \PhraseanetTestCase
public function setUp() public function setUp()
{ {
parent::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'], self::$DI['oauth2-app-user'], self::$DI['user']);
$this->account = API_OAuth2_Account::load_with_user(self::$DI['app'], $this->application, self::$DI['user']);
$expires = time() + 100; $expires = time() + 100;
$this->token = random::generatePassword(8); $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); $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() public function testGet_value()
{ {
$this->assertEquals($this->token, $this->object->get_value()); $this->assertEquals($this->token, $this->object->get_value());

View File

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

View File

@@ -2,29 +2,12 @@
class API_OAuth2_ApplicationTest extends \PhraseanetTestCase 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() 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); $loaded = API_OAuth2_Application::load_from_client_id(self::$DI['app'], $client_id);
$this->assertInstanceOf('API_OAuth2_Application', $loaded); $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() public function testLoad_dev_app_by_user()
@@ -34,7 +17,7 @@ class API_OAuth2_ApplicationTest extends \PhraseanetTestCase
$this->assertTrue(count($apps) > 0); $this->assertTrue(count($apps) > 0);
$found = false; $found = false;
foreach ($apps as $app) { 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; $found = true;
$this->assertInstanceOf('API_OAuth2_Application', $app); $this->assertInstanceOf('API_OAuth2_Application', $app);
} }
@@ -51,7 +34,7 @@ class API_OAuth2_ApplicationTest extends \PhraseanetTestCase
$found = false; $found = false;
foreach ($apps as $app) { 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; $found = true;
$this->assertInstanceOf('API_OAuth2_Application', $app); $this->assertInstanceOf('API_OAuth2_Application', $app);
} }
@@ -60,133 +43,78 @@ class API_OAuth2_ApplicationTest extends \PhraseanetTestCase
$this->fail(); $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->assertTrue(in_array(self::$DI['oauth2-app-user']->get_type(), [API_OAuth2_Application::DESKTOP_TYPE, API_OAuth2_Application::WEB_TYPE]));
{
$this->assertInstanceOf('User_Adapter', $this->object->get_creator());
}
public function testGet_type() $this->assertTrue(is_string(self::$DI['oauth2-app-user']->get_nonce()));
{ $this->assertTrue(strlen(self::$DI['oauth2-app-user']->get_nonce()) === 6);
$this->assertTrue(in_array($this->object->get_type(), [API_OAuth2_Application::DESKTOP_TYPE, API_OAuth2_Application::WEB_TYPE]));
}
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 { try {
$this->object->set_type('prout'); self::$DI['oauth2-app-user']->set_type('prout');
$this->fail(); $this->fail();
} catch (Exception_InvalidArgument $e) { } catch (Exception_InvalidArgument $e) {
} }
$this->object->set_type(API_OAuth2_Application::WEB_TYPE); self::$DI['oauth2-app-user']->set_type(API_OAuth2_Application::WEB_TYPE);
$this->assertEquals(API_OAuth2_Application::WEB_TYPE, $this->object->get_type()); $this->assertEquals(API_OAuth2_Application::WEB_TYPE, self::$DI['oauth2-app-user']->get_type());
$this->object->set_type(API_OAuth2_Application::DESKTOP_TYPE); self::$DI['oauth2-app-user']->set_type(API_OAuth2_Application::DESKTOP_TYPE);
$this->assertEquals(API_OAuth2_Application::DESKTOP_TYPE, $this->object->get_type()); $this->assertEquals(API_OAuth2_Application::DESKTOP_TYPE, self::$DI['oauth2-app-user']->get_type());
$this->assertEquals(API_OAuth2_Application::NATIVE_APP_REDIRECT_URI, $this->object->get_redirect_uri()); $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() self::$DI['oauth2-app-user']->set_name('prout');
{ $this->assertEquals('prout', self::$DI['oauth2-app-user']->get_name());
$this->object->set_name('prout'); self::$DI['oauth2-app-user']->set_name('test application for user');
$this->assertEquals('prout', $this->object->get_name()); $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'; $desc = 'prouti prouto prout prout';
$this->object->set_description($desc); self::$DI['oauth2-app-user']->set_description($desc);
$this->assertEquals($desc, $this->object->get_description()); $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/'; $site = 'http://www.example.com/';
$this->object->set_website($site); self::$DI['oauth2-app-user']->set_website($site);
$this->assertEquals($site, $this->object->get_website()); $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', self::$DI['oauth2-app-user']->get_created_on());
{
$this->assertInstanceOf('DateTime', $this->object->get_created_on());
}
public function testGet_last_modified() $this->assertInstanceOf('DateTime', self::$DI['oauth2-app-user']->get_last_modified());
{
$this->assertInstanceOf('DateTime', $this->object->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) private function assertmd5($md5)
{ {
$this->assertTrue((count(preg_match('/[a-z0-9]{32}/', $md5)) === 1)); $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 class API_OAuth2_TokenTest extends \PhraseanetTestCase
{ {
/** /**
* @var API_OAuth2_Token * @var API_OAuth2_Token
*/ */
@@ -11,8 +10,7 @@ class API_OAuth2_TokenTest extends \PhraseanetTestCase
public function setUp() public function setUp()
{ {
parent::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'], self::$DI['oauth2-app-user'], self::$DI['user']);
$account = API_OAuth2_Account::load_with_user(self::$DI['app'], $this->application, self::$DI['user']);
try { try {
new API_OAuth2_Token(self::$DI['app']['phraseanet.appbox'], $account); new API_OAuth2_Token(self::$DI['app']['phraseanet.appbox'], $account);
@@ -26,7 +24,7 @@ class API_OAuth2_TokenTest extends \PhraseanetTestCase
public function tearDown() public function tearDown()
{ {
$this->application->delete(); $this->object->delete();
parent::tearDown(); parent::tearDown();
} }
@@ -35,59 +33,38 @@ class API_OAuth2_TokenTest extends \PhraseanetTestCase
$this->assertTrue((count(preg_match('/[a-z0-9]{32}/', $md5)) === 1)); $this->assertTrue((count(preg_match('/[a-z0-9]{32}/', $md5)) === 1));
} }
public function testGet_value() public function testGettersAndSetters()
{ {
$this->assertmd5($this->object->get_value()); $this->assertmd5($this->object->get_value());
}
public function testSet_value()
{
$value = md5('prout'); $value = md5('prout');
$this->object->set_value($value); $this->object->set_value($value);
$this->assertEquals($value, $this->object->get_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()); $this->assertNull($this->object->get_session_id());
}
public function testSet_session_id()
{
$this->object->set_session_id(458); $this->object->set_session_id(458);
$this->assertEquals(458, $this->object->get_session_id()); $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(); $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 > 3500, "expire value $diff should be more than 3500 seconds ");
$this->assertTrue($diff < 3700, "expire value $diff should be less than 3700 seconds "); $this->assertTrue($diff < 3700, "expire value $diff should be less than 3700 seconds ");
}
public function testSet_expires()
{
$date = time() + 7200; $date = time() + 7200;
$this->object->set_expires($date); $this->object->set_expires($date);
$this->assertEquals($date, $this->object->get_expires()); $this->assertEquals($date, $this->object->get_expires());
}
public function testGet_scope()
{
$this->assertNull($this->object->get_scope()); $this->assertNull($this->object->get_scope());
}
public function testset_scope()
{
$this->assertNull($this->object->get_scope()); $this->assertNull($this->object->get_scope());
$scope = "prout"; $scope = "prout";
$this->object->set_scope($scope); $this->object->set_scope($scope);
$this->assertEquals($scope, $this->object->get_scope()); $this->assertEquals($scope, $this->object->get_scope());
}
public function testGet_account()
{
$this->assertInstanceOf('API_OAuth2_Account', $this->object->get_account()); $this->assertInstanceOf('API_OAuth2_Account', $this->object->get_account());
} }

View File

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

View File

@@ -5,46 +5,42 @@ class media_Permalink_AdapterTest extends \PhraseanetTestCase
/** /**
* @var media_Permalink_Adapter * @var media_Permalink_Adapter
*/ */
public static $object; private $object;
public static $subdef;
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
$databox = self::$DI['record_1']->get_databox(); $this->object = media_Permalink_Adapter::getPermalink(self::$DI['app'], self::$DI['record_1']->get_databox(), self::$DI['record_1']->get_subdef('document'));
self::$subdef = self::$DI['record_1']->get_subdef('document');
self::$object = media_Permalink_Adapter::getPermalink(self::$DI['app'], $databox, self::$subdef);
} }
public function testGet_label() public function testGet_label()
{ {
$this->assertInternalType('string', self::$object->get_label()); $this->assertSame('test001', $this->object->get_label());
$this->assertEquals('test001', self::$object->get_label());
} }
public function testGetPermalink() public function testGetPermalink()
{ {
$this->assertTrue((self::$object instanceof media_Permalink_Adapter)); $this->assertTrue(($this->object instanceof media_Permalink_Adapter));
} }
public function testSet_is_activated() public function testSet_is_activated()
{ {
self::$object->set_is_activated(true); $this->object->set_is_activated(true);
$this->assertTrue(self::$object->get_is_activated()); $this->assertTrue($this->object->get_is_activated());
self::$object->set_is_activated(false); $this->object->set_is_activated(false);
$this->assertFalse(self::$object->get_is_activated()); $this->assertFalse($this->object->get_is_activated());
self::$object->set_is_activated(true); $this->object->set_is_activated(true);
$this->assertTrue(self::$object->get_is_activated()); $this->assertTrue($this->object->get_is_activated());
} }
public function testSet_label() public function testSet_label()
{ {
self::$object->set_label('coucou les chicos'); $this->object->set_label('coucou les chicos');
$this->assertEquals('coucou-les-chicos', self::$object->get_label()); $this->assertEquals('coucou-les-chicos', $this->object->get_label());
self::$object->set_label(''); $this->object->set_label('');
$this->assertEquals('untitled', self::$object->get_label()); $this->assertEquals('untitled', $this->object->get_label());
self::$object->set_label('JE ANp ra&é"\/,;:!§/.?%µ*ù$]@^\[{#~234567890°+\'(-è_çà'); $this->object->set_label('JE ANp ra&é"\/,;:!§/.?%µ*ù$]@^\[{#~234567890°+\'(-è_çà');
$this->assertEquals('JE-ANp-raeu234567890-e_ca', self::$object->get_label()); $this->assertEquals('JE-ANp-raeu234567890-e_ca', $this->object->get_label());
} }
public function testGet_url() 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/' $url = rtrim(self::$DI['app']['phraseanet.registry']->get('GV_ServerName'), '/') . '/permalink/v1/'
. self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_sbas_id() . '/'
. self::$DI['record_1']->get_record_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) . '.' . 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() 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_sbas_id() . '/'
. self::$DI['record_1']->get_record_id() . self::$DI['record_1']->get_record_id()
. '/document/' . '/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() public function testGet_id()
{ {
$this->assertInternalType('integer', self::$object->get_id()); $this->assertInternalType('integer', $this->object->get_id());
} }
public function testGet_token() public function testGet_token()
{ {
$this->assertInternalType('string', self::$object->get_token()); $this->assertInternalType('string', $this->object->get_token());
} }
public function testGet_is_activated() 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() 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() 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() public function testCreateAPermalinkAlreadyCreated()
{ {
$databox = self::$DI['record_1']->get_databox(); media_Permalink_Adapter::create(self::$DI['app'], self::$DI['record_1']->get_databox(), self::$DI['record_1']->get_subdef('document'));
media_Permalink_Adapter::create(self::$DI['app'], $databox, self::$DI['record_1']->get_subdef('document'));
} }
} }

View File

@@ -8,10 +8,6 @@ class media_subdefTest extends \PhraseanetTestCase
* @var \media_subdef * @var \media_subdef
*/ */
private static $objectPresent; private static $objectPresent;
/**
* @var \media_subdef
*/
private static $storyPresent;
/** /**
* @var \media_subdef * @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::$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() 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 class record_adapterTest extends \PhraseanetAuthenticatedTestCase
{ {
/**
* @var record_adapter
*/
private static $grouping;
private static $initialized;
private static $thumbtitled = false; private static $thumbtitled = false;
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
if (self::$initialized) {
return;
}
/** /**
* Reset thumbtitle in order to have consistent tests (testGet_title) * 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 * Check whether a record is delete from order_elements when
* record::delete is call * record::delete is call