Fix tests, add entity name in API responses

This commit is contained in:
Romain Neutron
2012-12-20 01:27:20 +01:00
parent 52a7f58a31
commit e22c70a130
2 changed files with 32 additions and 4 deletions

View File

@@ -41,6 +41,9 @@ class API_V1_adapter extends API_V1_Abstract
*/
protected $core;
const OBJECT_TYPE_STORY = 'http://api.phraseanet.com/api/objects/story';
const OBJECT_TYPE_STORY_METADATA_BAG = 'http://api.phraseanet.com/api/objects/story-metadata-bag';
/**
* API constructor
*
@@ -1990,6 +1993,7 @@ class API_V1_adapter extends API_V1_Abstract
};
return array(
'@entity@' => self::OBJECT_TYPE_STORY,
'databox_id' => $story->get_sbas_id(),
'story_id' => $story->get_record_id(),
'updated_on' => $story->get_modification_date()->format(DATE_ATOM),
@@ -1998,6 +2002,7 @@ class API_V1_adapter extends API_V1_Abstract
'thumbnail' => $this->list_embedable_media($story->get_thumbnail(), registry::get_instance()),
'uuid' => $story->get_uuid(),
'metadatas' => array(
'@entity@' => self::OBJECT_TYPE_STORY_METADATA_BAG,
'dc:contributor' => $format($caption, databox_Field_DCESAbstract::Contributor),
'dc:coverage' => $format($caption, databox_Field_DCESAbstract::Coverage),
'dc:creator' => $format($caption, databox_Field_DCESAbstract::Creator),

View File

@@ -800,6 +800,9 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->evaluateSearchResponse($response);
$this->assertArrayHasKey('stories', $response['results']);
$this->assertArrayHasKey('records', $response['results']);
$found = false;
foreach ($response['results']['records'] as $record) {
@@ -833,6 +836,9 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->evaluateSearchResponse($response);
$this->assertArrayHasKey('stories', $response['results']);
$this->assertArrayHasKey('records', $response['results']);
$found = false;
foreach ($response['results']['stories'] as $story) {
@@ -990,6 +996,10 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
{
$this->setToken(self::$token);
$media = self::$core['mediavorus']->guess(new \SplFileInfo(__DIR__ . '/../../../testfiles/cestlafete.jpg'));
static::$records['record_story_1']->substitute_subdef('preview', $media);
static::$records['record_story_1']->substitute_subdef('thumbnail', $media);
$keys = array_keys(static::$records['record_story_1']->get_subdefs());
$route = '/stories/' . static::$records['record_story_1']->get_sbas_id() . '/' . static::$records['record_story_1']->get_record_id() . '/embed/';
@@ -2180,7 +2190,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->assertArrayHasKey('response', $content);
$this->assertTrue(is_array($content['meta']), 'Le bloc meta est un array');
$this->assertTrue(is_array($content['response']), 'Le bloc reponse est un array');
$this->assertEquals('1.2', $content['meta']['api_version']);
$this->assertEquals('1.3', $content['meta']['api_version']);
$this->assertNotNull($content['meta']['response_time']);
$this->assertEquals('UTF-8', $content['meta']['charset']);
}
@@ -2354,6 +2364,8 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->assertTrue(is_int($story['collection_id']));
$this->assertArrayHasKey('thumbnail', $story);
$this->assertArrayHasKey('uuid', $story);
$this->assertArrayHasKey('@entity@', $story);
$this->assertEquals(\API_V1_adapter::OBJECT_TYPE_STORY, $story['@entity@']);
$this->assertTrue(\uuid::is_valid($story['uuid']));
if ( ! is_null($story['thumbnail'])) {
@@ -2374,6 +2386,20 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->assertArrayHasKey('records', $story);
$this->assertInternalType('array', $story['records']);
foreach ($story['metadatas'] as $key => $metadata) {
if (null !== $metadata) {
$this->assertInternalType('string', $metadata);
}
if ($key === '@entity@') {
continue;
}
$this->assertEquals(0, strpos($key, 'dc:'));
}
$this->assertArrayHasKey('@entity@', $story['metadatas']);
$this->assertEquals(\API_V1_adapter::OBJECT_TYPE_STORY_METADATA_BAG, $story['metadatas']['@entity@']);
foreach ($story['records'] as $record) {
$this->evaluateGoodRecord($record);
}
@@ -2493,8 +2519,5 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->assertTrue(is_array($response['suggestions']));
$this->assertTrue(is_array($response['results']));
$this->assertTrue(is_string($response['query']));
$this->assertArrayHasKey('stories', $response['results']);
$this->assertArrayHasKey('records', $response['results']);
}
}