update API

revert bad merge

fix cs
This commit is contained in:
Nicolas Le Goff
2012-07-06 20:10:21 +02:00
parent 9ab4e0c1c4
commit b4ff14f3e4
6 changed files with 123 additions and 165 deletions

View File

@@ -14,8 +14,8 @@ namespace Alchemy\Phrasea\Application;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Silex\Provider\ValidatorServiceProvider;
/** /**
* *
@@ -37,6 +37,8 @@ return call_user_func(function() {
return \appbox::get_instance($app['Core']); return \appbox::get_instance($app['Core']);
}; };
$app->register(new ValidatorServiceProvider());
$app['oauth'] = function($app) { $app['oauth'] = function($app) {
return new \API_OAuth2_Adapter($app['appbox']); return new \API_OAuth2_Adapter($app['appbox']);
}; };
@@ -60,7 +62,7 @@ return call_user_func(function() {
return $response; return $response;
}); });
/* * ******************************************************************* /********************************************************************
* AUTHENTIFICATION API * AUTHENTIFICATION API
*/ */
@@ -201,7 +203,7 @@ return call_user_func(function() {
return; return;
}); });
/****************************************************************** /* ****************************************************************
* MANAGEMENT APPS * MANAGEMENT APPS
* *
* *
@@ -238,35 +240,34 @@ return call_user_func(function() {
$route = "/applications/dev/create"; $route = "/applications/dev/create";
$app->post($route, function() use ($app) { $app->post($route, function() use ($app) {
$submit = false; $submit = false;
if ($app['request']->get("type") == "desktop") { if ($app['request']->get("type") == "desktop") {
$post = new \API_OAuth2_Form_DevAppDesktop($app['request']); $post = new \API_OAuth2_Form_DevAppDesktop($app['request']);
} else { } else {
$post = new \API_OAuth2_Form_DevAppInternet($app['request']); $post = new \API_OAuth2_Form_DevAppInternet($app['request']);
} }
$violations = $app['validator']->validate($post); $violations = $app['validator']->validate($post);
if ($violations->count() == 0) if ($violations->count() == 0)
$submit = true; $submit = true;
$request = $app['request']; $request = $app['request'];
if ($submit) { if ($submit) {
$application = \API_OAuth2_Application::create($app['appbox'], $app['Core']->getAuthenticatedUser(), $post->getName()); $application = \API_OAuth2_Application::create($app['appbox'], $app['Core']->getAuthenticatedUser(), $post->getName());
$application->set_description($post->getDescription()) $application->set_description($post->getDescription())
->set_redirect_uri($post->getSchemeCallback() . $post->getCallback()) ->set_redirect_uri($post->getSchemeCallback() . $post->getCallback())
->set_type($post->getType()) ->set_type($post->getType())
->set_website($post->getSchemeWebsite() . $post->getWebsite()); ->set_website($post->getSchemeWebsite() . $post->getWebsite());
return $app->redirect("/api/oauthv2/applications/dev/" . $application->get_id() . "/show"); return $app->redirect("/api/oauthv2/applications/dev/" . $application->get_id() . "/show");
} }
$var = array(
"violations" => $violations,
"form" => $post
);
$var = array(
"violations" => $violations,
"form" => $post
);
return $app['response']('api/auth/application_dev_new.twig', $var); return $app['response']('api/auth/application_dev_new.twig', $var);
}); });

View File

@@ -131,20 +131,8 @@ class MoveCollection extends RecordHelper
throw new \Exception_Unauthorized(sprintf("user id %s does not have the permission to move records to %s", $user->get_id(), \phrasea::bas_names($this->baseIdDestination))); throw new \Exception_Unauthorized(sprintf("user id %s does not have the permission to move records to %s", $user->get_id(), \phrasea::bas_names($this->baseIdDestination)));
} }
if ( ! $this->is_possible()) if ( ! $this->is_possible()) {
throw new \Exception('This action is not possible'); throw new \Exception('This action is not possible');
if ($request->get("chg_coll_son") == "1") {
foreach ($this->selection as $record) {
if ( ! $record->is_grouping())
continue;
foreach ($record->get_children() as $child) {
if ( ! $user->ACL()->has_right_on_base(
$child->get_base_id(), 'candeleterecord'))
continue;
$this->selection->add_element($child);
}
}
} }
$collection = \collection::get_from_base_id($base_dest); $collection = \collection::get_from_base_id($base_dest);

View File

@@ -168,19 +168,6 @@ class API_OAuth2_Adapter extends OAuth2
return $this->usr_id; return $this->usr_id;
} }
/**
*
* @param string $secret
* @param string $nonce
* @return string
*/
protected static function crypt_secret($secret, $nonce)
{
$registry = registry::get_instance();
return hash_hmac('sha512', $secret . $nonce, $registry->get('GV_sit'));
}
/** /**
* *
* Implements OAuth2::checkClientCredentials(). * Implements OAuth2::checkClientCredentials().
@@ -198,9 +185,7 @@ class API_OAuth2_Adapter extends OAuth2
return true; return true;
} }
$crypted = $this->crypt_secret($client_secret, $application->get_nonce()); return ($application->get_client_secret() === $client_secret);
return ($result["client_secret"] === $crypted);
} catch (Exception $e) { } catch (Exception $e) {
} }

View File

@@ -1063,7 +1063,7 @@ class API_V1_adapter extends API_V1_Abstract
} }
$record->set_metadatas($metadatas); $record->set_metadatas($metadatas);
$result->set_datas(array("metadatas" => $this->list_record_caption($record->get_caption()))); $result->set_datas(array("record_metadatas" => $this->list_record_caption($record->get_caption())));
} catch (Exception $e) { } catch (Exception $e) {
$result->set_error_message(API_V1_result::ERROR_BAD_REQUEST, _('An error occured')); $result->set_error_message(API_V1_result::ERROR_BAD_REQUEST, _('An error occured'));
} }
@@ -1817,7 +1817,7 @@ class API_V1_adapter extends API_V1_Abstract
'mime_type' => $record->get_mime(), 'mime_type' => $record->get_mime(),
'title' => $record->get_title(), 'title' => $record->get_title(),
'original_name' => $record->get_original_name(), 'original_name' => $record->get_original_name(),
'updated-on' => $record->get_modification_date()->format(DATE_ATOM), 'updated_on' => $record->get_modification_date()->format(DATE_ATOM),
'created_on' => $record->get_creation_date()->format(DATE_ATOM), 'created_on' => $record->get_creation_date()->format(DATE_ATOM),
'collection_id' => phrasea::collFromBas($record->get_base_id()), 'collection_id' => phrasea::collFromBas($record->get_base_id()),
'sha256' => $record->get_sha256(), 'sha256' => $record->get_sha256(),

View File

@@ -522,13 +522,13 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
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('coll_id', $collection); $this->assertArrayHasKey('collection_id', $collection);
$this->assertArrayHasKey('name', $collection); $this->assertArrayHasKey('name', $collection);
$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['coll_id'])); $this->assertTrue(is_int($collection['collection_id']));
$this->assertGreaterThan(0, $collection['coll_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']));
} }
@@ -572,13 +572,10 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$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_int($status['searchable'])); $this->assertTrue(is_bool($status['searchable']));
$this->assertTrue(in_array($status['searchable'], array(0, 1))); $this->assertTrue($status['searchable'] === (bool) $ref_status[$status['bit']]['searchable']);
$this->assertTrue($status['searchable'] === $ref_status[$status['bit']]['searchable']); $this->assertTrue(is_bool($status['printable']));
$this->assertTrue(is_int($status['printable'])); $this->assertTrue($status['printable'] === (bool) $ref_status[$status['bit']]['printable']);
$this->assertTrue(in_array($status['printable'], array(0, 1)));
$this->assertTrue($status['printable'] === $ref_status[$status['bit']]['printable']);
$this->assertTrue($status['label_off'] === $ref_status[$status['bit']]['labeloff']);
$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']);
@@ -608,7 +605,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$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 = '/databoxes/' . $databox_id . '/metadatas/'; $route = '/databoxes/' . $databox_id . '/metadatas/';
@@ -618,8 +615,9 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$content = $this->unserialize($this->client->getResponse()->getContent()); $content = $this->unserialize($this->client->getResponse()->getContent());
$this->evaluateResponse200($this->client->getResponse()); $this->evaluateResponse200($this->client->getResponse());
$this->evaluateMeta200($content); $this->evaluateMeta200($content);
$this->assertArrayHasKey('metadatas', $content['response']);
foreach ($content['response']['metadatas'] as $metadatas) { $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->assertTrue(is_array($metadatas), 'Un bloc metadata est un objet');
$this->assertArrayHasKey('id', $metadatas); $this->assertArrayHasKey('id', $metadatas);
$this->assertArrayHasKey('namespace', $metadatas); $this->assertArrayHasKey('namespace', $metadatas);
@@ -723,8 +721,6 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$response = $content['response']; $response = $content['response'];
$this->assertArrayHasKey('total_pages', $response);
$this->assertArrayHasKey('current_page', $response);
$this->assertArrayHasKey('available_results', $response); $this->assertArrayHasKey('available_results', $response);
$this->assertArrayHasKey('total_results', $response); $this->assertArrayHasKey('total_results', $response);
$this->assertArrayHasKey('error', $response); $this->assertArrayHasKey('error', $response);
@@ -736,8 +732,6 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->assertArrayHasKey('query', $response); $this->assertArrayHasKey('query', $response);
$this->assertTrue(is_int($response['total_pages']), 'Le nombre de page est un int');
$this->assertTrue(is_int($response['current_page']), 'Le nombre de la page courrante est un int');
$this->assertTrue(is_int($response['available_results']), 'Le nombre de results dispo est un int'); $this->assertTrue(is_int($response['available_results']), 'Le nombre de results dispo est un int');
$this->assertTrue(is_int($response['total_results']), 'Le nombre de results est un int'); $this->assertTrue(is_int($response['total_results']), 'Le nombre de results est un int');
$this->assertTrue(is_string($response['error']), 'Error est une string'); $this->assertTrue(is_string($response['error']), 'Error est une string');
@@ -855,11 +849,10 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->evaluateResponse200($this->client->getResponse()); $this->evaluateResponse200($this->client->getResponse());
$this->evaluateMeta200($content); $this->evaluateMeta200($content);
foreach ($content['response'] as $embed) { $this->assertArrayHasKey('embed', $content['response']);
foreach ($keys as $key) {
$this->assertArrayHasKey($key, $embed); foreach ($content['response']['embed'] as $embed) {
$this->checkEmbed($key, $embed[$key], static::$records['record_1']); $this->checkEmbed($embed, static::$records['record_1']);
}
} }
$route = '/records/24892534/51654651553/embed/'; $route = '/records/24892534/51654651553/embed/';
$this->evaluateNotFoundRoute($route, array('GET')); $this->evaluateNotFoundRoute($route, array('GET'));
@@ -881,11 +874,10 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->client->request('GET', $route, array('mimes' => array('image/jpg', 'image/jpeg')), array(), array('HTTP_Accept' => $this->getAcceptMimeType())); $this->client->request('GET', $route, array('mimes' => array('image/jpg', 'image/jpeg')), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
$content = $this->unserialize($this->client->getResponse()->getContent()); $content = $this->unserialize($this->client->getResponse()->getContent());
foreach ($content['response'] as $embed) { $this->assertArrayHasKey('embed', $content['response']);
foreach (array('thumbnail', 'preview') as $key) {
$this->assertArrayHasKey($key, $embed); foreach ($content['response']['embed'] as $embed) {
$this->checkEmbed($key, $embed[$key], static::$records['record_1']); $this->checkEmbed($embed, static::$records['record_1']);
}
} }
} }
@@ -974,9 +966,8 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->evaluateResponse200($this->client->getResponse()); $this->evaluateResponse200($this->client->getResponse());
$this->evaluateMeta200($content); $this->evaluateMeta200($content);
$caption = $record->get_caption(); $this->assertArrayHasKey("record_metadatas", $content['response']);
$this->assertEquals(count($caption->get_fields()), count($content['response']['record_metadatas']), 'Retrived metadatas are the same');
$this->assertEquals(count($caption->get_fields()), count($content['response']['metadatas']), 'Retrived metadatas are the same');
foreach ($caption->get_fields() as $field) { foreach ($caption->get_fields() as $field) {
foreach ($field->get_values() as $value) { foreach ($field->get_values() as $value) {
@@ -989,7 +980,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->evaluateRecordsMetadataResponse($content); $this->evaluateRecordsMetadataResponse($content);
foreach ($content['response']['metadatas'] as $metadata) { foreach ($content['response']['record_metadatas'] as $metadata) {
if ( ! in_array($metadata['meta_id'], array_keys($toupdate))) if ( ! in_array($metadata['meta_id'], array_keys($toupdate)))
continue; continue;
$saved_value = $toupdate[$metadata['meta_structure_id']]['value']; $saved_value = $toupdate[$metadata['meta_structure_id']]['value'];
@@ -1079,7 +1070,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
} }
} }
if ( ! $base_id) { if ( ! $base_id) {
continue; $this->markTestSkipped('No collection');
} }
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE')); $this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
@@ -1139,11 +1130,8 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->assertEquals(1, count($content['response'])); $this->assertEquals(1, count($content['response']));
$this->assertArrayHasKey("basket", $content['response']); $this->assertArrayHasKey("basket", $content['response']);
$this->evaluateGoodBasket($content['response']['basket']);
foreach ($content['response']['basket'] as $basket) { $this->assertEquals('un Joli Nom', $content['response']['basket']['name']);
$this->evaluateGoodBasket($basket);
$this->assertEquals('un Joli Nom', $basket['name']);
}
} }
/** /**
@@ -1168,24 +1156,21 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->evaluateResponse200($this->client->getResponse()); $this->evaluateResponse200($this->client->getResponse());
$this->evaluateMeta200($content); $this->evaluateMeta200($content);
$this->assertEquals(1, count((array) $content['response'])); $this->assertEquals(2, count((array) $content['response']));
$this->assertArrayHasKey("basket_elements", $content['response']); $this->assertArrayHasKey("basket_elements", $content['response']);
$this->assertArrayHasKey("basket", $content['response']);
$this->evaluateGoodBasket($content['response']['basket']);
foreach ($content['response']['basket_elements'] as $basket_str) { foreach ($content['response']['basket_elements'] as $basket_element) {
$this->evaluateGoodBasket($basket_str); $this->assertArrayHasKey('basket_element_id', $basket_element);
$this->assertArrayHasKey('order', $basket_element);
$this->assertEquals(count($basket->getElements()), count($basket_str['basket_elements'])); $this->assertArrayHasKey('record', $basket_element);
foreach ($basket_str['basket_elements'] as $basket_element) { $this->assertArrayHasKey('validation_item', $basket_element);
$this->assertArrayHasKey('basket_element_id', $basket_element); $this->assertTrue(is_bool($basket_element['validation_item']));
$this->assertArrayHasKey('order', $basket_element); $this->assertTrue(is_int($basket_element['order']));
$this->assertArrayHasKey('record', $basket_element); $this->assertTrue(is_int($basket_element['basket_element_id']));
$this->assertArrayHasKey('validation_item', $basket_element); $this->evaluateGoodRecord($basket_element['record']);
$this->assertTrue(is_bool($basket_element['validation_item']));
$this->assertTrue(is_int($basket_element['order']));
$this->assertTrue(is_int($basket_element['basket_element_id']));
$this->evaluateGoodRecord($basket_element['record']);
}
} }
} }
@@ -1212,13 +1197,11 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->assertEquals(1, count((array) $content['response'])); $this->assertEquals(1, count((array) $content['response']));
$this->assertArrayHasKey("basket", $content['response']); $this->assertArrayHasKey("basket", $content['response']);
foreach ($content['response']['basket'] as $basket_str) { $this->evaluateGoodBasket($content['response']['basket']);
$this->evaluateGoodBasket($basket_str);
$this->assertEquals($basket_str['name'], 'un Joli Nom'); $this->assertEquals($content['response']['basket']['name'], 'un Joli Nom');
}
$crawler = $this->client->request('POST', $route, array('name' => '<i>un Joli Nom<i>'), array(), array('HTTP_Accept' => $this->getAcceptMimeType())); $crawler = $this->client->request('POST', $route, array('name' => 'un Joli Nom'), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
$content = $this->unserialize($this->client->getResponse()->getContent()); $content = $this->unserialize($this->client->getResponse()->getContent());
$this->evaluateResponse200($this->client->getResponse()); $this->evaluateResponse200($this->client->getResponse());
@@ -1228,11 +1211,9 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->assertArrayHasKey("basket", $content['response']); $this->assertArrayHasKey("basket", $content['response']);
foreach ($content['response']['basket'] as $basket) { $this->evaluateGoodBasket($content['response']['basket']);
$this->evaluateGoodBasket($basket_str);
$this->assertEquals($basket_str['name'], 'un Joli Nom'); $this->assertEquals($content['response']['basket']['name'], 'un Joli Nom');
}
$crawler = $this->client->request('POST', $route, array('name' => '<strong>aéaa'), array(), array('HTTP_Accept' => $this->getAcceptMimeType())); $crawler = $this->client->request('POST', $route, array('name' => '<strong>aéaa'), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
$content = $this->unserialize($this->client->getResponse()->getContent()); $content = $this->unserialize($this->client->getResponse()->getContent());
@@ -1242,10 +1223,8 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->assertEquals(1, count((array) $content['response'])); $this->assertEquals(1, count((array) $content['response']));
$this->assertArrayHasKey("basket", $content['response']); $this->assertArrayHasKey("basket", $content['response']);
foreach ($content['response']['basket'] as $basket_str) { $this->evaluateGoodBasket($content['response']['basket']);
$this->evaluateGoodBasket($basket_str); $this->assertEquals($content['response']['basket']['name'], '<strong>aéaa');
$this->assertEquals($basket_str['name'], '<strong>aéaa');
}
} }
/** /**
@@ -1272,11 +1251,8 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->assertEquals(1, count((array) $content['response'])); $this->assertEquals(1, count((array) $content['response']));
$this->assertArrayHasKey("basket", $content['response']); $this->assertArrayHasKey("basket", $content['response']);
foreach ($content['response']['basket'] as $basket_str) { $this->evaluateGoodBasket($content['response']['basket']);
$this->evaluateGoodBasket($basket_str); $this->assertEquals($content['response']['basket']['description'], 'une belle desc');
$this->assertEquals($basket_str['description'], 'une belle desc');
}
} }
/** /**
@@ -1328,7 +1304,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->evaluateResponse200($this->client->getResponse()); $this->evaluateResponse200($this->client->getResponse());
$this->evaluateMeta200($content); $this->evaluateMeta200($content);
$datas = $content['response']; $datas = $content['response'];
$this->assertArrayHasKey('entity', $datas); $this->assertArrayHasKey('entity', $datas);
$this->assertArrayHasKey('url', $datas); $this->assertArrayHasKey('url', $datas);
} }
@@ -1501,11 +1477,11 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->assertArrayHasKey('feeds', $content['response']); $this->assertArrayHasKey('feeds', $content['response']);
$found = false; $found = false;
foreach ($content['response']['feeds'] as $feed_id => $feed) { foreach ($content['response']['feeds'] as $feed) {
$this->evaluateGoodFeed($feed); $this->evaluateGoodFeed($feed);
if ($feed_id == $created_feed->get_id()) { if ($feed['id'] == $created_feed->get_id()) {
$found = true; $found = true;
$this->assertEquals($title, $feed['title']); $this->assertEquals($title, $feed['title']);
$this->assertEquals($subtitle, $feed['subtitle']); $this->assertEquals($subtitle, $feed['subtitle']);
@@ -1564,10 +1540,10 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$found = false; $found = false;
foreach ($content['response']['entries'] as $entry_id => $entry) { foreach ($content['response']['entries'] as $entry) {
$this->assertGoodEntry($entry); $this->assertGoodEntry($entry);
if ($entry_id == $created_entry->get_id()) { if ($entry['id'] == $created_entry->get_id()) {
$found = true; $found = true;
$this->assertEquals($author_email, $entry['author_email']); $this->assertEquals($author_email, $entry['author_email']);
$this->assertEquals($author, $entry['author_name']); $this->assertEquals($author, $entry['author_name']);
@@ -1736,10 +1712,11 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->assertArrayHasKey('offset_start', $content['response']); $this->assertArrayHasKey('offset_start', $content['response']);
$this->assertArrayHasKey('per_page', $content['response']); $this->assertArrayHasKey('per_page', $content['response']);
$this->assertArrayHasKey('items', $content['response']); $this->assertArrayHasKey('quarantine_items', $content['response']);
$found = false; $found = false;
foreach ($content['response']['items'] as $item) {
foreach ($content['response']['quarantine_items'] as $item) {
$this->evaluateGoodQuarantineItem($item); $this->evaluateGoodQuarantineItem($item);
if ($item['id'] == $quarantineItemId) { if ($item['id'] == $quarantineItemId) {
$found = true; $found = true;
@@ -1767,10 +1744,10 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType())); $this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
$content = $this->unserialize($this->client->getResponse()->getContent()); $content = $this->unserialize($this->client->getResponse()->getContent());
$this->assertArrayHasKey('item', $content['response']); $this->assertArrayHasKey('quarantine_item', $content['response']);
$this->evaluateGoodQuarantineItem($content['response']['item']); $this->evaluateGoodQuarantineItem($content['response']['quarantine_item']);
$this->assertEquals($quarantineItemId, $content['response']['item']['id']); $this->assertEquals($quarantineItemId, $content['response']['quarantine_item']['id']);
} }
protected function getQuarantineItem() protected function getQuarantineItem()
@@ -1795,7 +1772,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
protected function evaluateGoodQuarantineItem($item) protected function evaluateGoodQuarantineItem($item)
{ {
$this->assertArrayHasKey('id', $item); $this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('session', $item); $this->assertArrayHasKey('quarantine_session', $item);
$this->assertArrayHasKey('base_id', $item); $this->assertArrayHasKey('base_id', $item);
$this->assertArrayHasKey('original_name', $item); $this->assertArrayHasKey('original_name', $item);
$this->assertArrayHasKey('sha256', $item); $this->assertArrayHasKey('sha256', $item);
@@ -1934,27 +1911,31 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
} }
} }
protected function checkEmbed($subdef_name, $embed, \record_adapter $record) protected function checkEmbed($embed, \record_adapter $record)
{ {
if ($embed['filesize'] === 0) {
var_dump($embed);
}
$this->assertArrayHasKey("name", $embed);
$this->assertArrayHasKey("permalink", $embed); $this->assertArrayHasKey("permalink", $embed);
$this->checkPermalink($embed['permalink'], $record->get_subdef($subdef_name)); $this->checkPermalink($embed['permalink'], $record->get_subdef($embed['name']));
$this->assertArrayHasKey("height", $embed); $this->assertArrayHasKey("height", $embed);
$this->assertEquals($embed['height'], $record->get_subdef($subdef_name)->get_height()); $this->assertEquals($embed['height'], $record->get_subdef($embed['name'])->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($subdef_name)->get_width()); $this->assertEquals($embed['width'], $record->get_subdef($embed['name'])->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($subdef_name)->get_size()); $this->assertEquals($embed['filesize'], $record->get_subdef($embed['name'])->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($subdef_name)->get_type()); $this->assertEquals($embed['player_type'], $record->get_subdef($embed['name'])->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($subdef_name)->get_mime()); $this->assertEquals($embed['mime_type'], $record->get_subdef($embed['name'])->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($subdef_name)->getDevices()); $this->assertEquals($embed['devices'], $record->get_subdef($embed['name'])->getDevices());
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $embed['devices']); $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $embed['devices']);
} }
@@ -1977,10 +1958,10 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->assertEquals($subdef->get_permalink()->get_is_activated(), $permalink['is_activated']); $this->assertEquals($subdef->get_permalink()->get_is_activated(), $permalink['is_activated']);
$this->assertArrayHasKey("label", $permalink); $this->assertArrayHasKey("label", $permalink);
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['label']); $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['label']);
$this->assertArrayHasKey("last_modified", $permalink); $this->assertArrayHasKey("updated_on", $permalink);
$this->assertEquals($subdef->get_permalink()->get_last_modified()->format(DATE_ATOM), $permalink['last_modified']); $this->assertEquals($subdef->get_permalink()->get_last_modified()->format(DATE_ATOM), $permalink['updated_on']);
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['last_modified']); $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['updated_on']);
$this->assertDateAtom($permalink['last_modified']); $this->assertDateAtom($permalink['updated_on']);
$this->assertArrayHasKey("page_url", $permalink); $this->assertArrayHasKey("page_url", $permalink);
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['page_url']); $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['page_url']);
$this->assertEquals($subdef->get_permalink()->get_page(\registry::get_instance()), $permalink['page_url']); $this->assertEquals($subdef->get_permalink()->get_page(\registry::get_instance()), $permalink['page_url']);
@@ -2133,7 +2114,6 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->assertArrayHasKey('description', $basket); $this->assertArrayHasKey('description', $basket);
$this->assertArrayHasKey('name', $basket); $this->assertArrayHasKey('name', $basket);
$this->assertArrayHasKey('pusher_usr_id', $basket); $this->assertArrayHasKey('pusher_usr_id', $basket);
$this->assertArrayHasKey('ssel_id', $basket);
$this->assertArrayHasKey('updated_on', $basket); $this->assertArrayHasKey('updated_on', $basket);
$this->assertArrayHasKey('unread', $basket); $this->assertArrayHasKey('unread', $basket);
@@ -2143,7 +2123,6 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->assertTrue(is_string($basket['name'])); $this->assertTrue(is_string($basket['name']));
$this->assertTrue(is_string($basket['description'])); $this->assertTrue(is_string($basket['description']));
$this->assertTrue(is_int($basket['ssel_id']));
$this->assertTrue(is_bool($basket['unread'])); $this->assertTrue(is_bool($basket['unread']));
$this->assertDateAtom($basket['created_on']); $this->assertDateAtom($basket['created_on']);
$this->assertDateAtom($basket['updated_on']); $this->assertDateAtom($basket['updated_on']);
@@ -2161,8 +2140,8 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->assertTrue(is_string($record['title'])); $this->assertTrue(is_string($record['title']));
$this->assertArrayHasKey('original_name', $record); $this->assertArrayHasKey('original_name', $record);
$this->assertTrue(is_string($record['original_name'])); $this->assertTrue(is_string($record['original_name']));
$this->assertArrayHasKey('last_modification', $record); $this->assertArrayHasKey('updated_on', $record);
$this->assertDateAtom($record['last_modification']); $this->assertDateAtom($record['updated_on']);
$this->assertArrayHasKey('created_on', $record); $this->assertArrayHasKey('created_on', $record);
$this->assertDateAtom($record['created_on']); $this->assertDateAtom($record['created_on']);
$this->assertArrayHasKey('collection_id', $record); $this->assertArrayHasKey('collection_id', $record);
@@ -2194,7 +2173,11 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->assertTrue(is_array($record['technical_informations'])); $this->assertTrue(is_array($record['technical_informations']));
foreach ($record['technical_informations'] as $key => $value) { foreach ($record['technical_informations'] as $technical) {
$this->assertArrayHasKey('value', $technical);
$this->assertArrayHasKey('name', $technical);
$value = $technical['value'];
if (is_string($value)) { if (is_string($value)) {
$this->assertFalse(ctype_digit($value)); $this->assertFalse(ctype_digit($value));
$this->assertEquals(0, preg_match('/[0-9]?\.[0-9]+/', $value)); $this->assertEquals(0, preg_match('/[0-9]?\.[0-9]+/', $value));
@@ -2210,7 +2193,8 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
protected function evaluateRecordsCaptionResponse($content) protected function evaluateRecordsCaptionResponse($content)
{ {
foreach ($content['response'] as $field) { $this->assertArrayHasKey('caption_metadatas', $content['response']);
foreach ($content['response']['caption_metadatas'] as $field) {
$this->assertTrue(is_array($field), 'Un bloc field est un objet'); $this->assertTrue(is_array($field), 'Un bloc field est un objet');
$this->assertArrayHasKey('meta_structure_id', $field); $this->assertArrayHasKey('meta_structure_id', $field);
$this->assertTrue(is_int($field['meta_structure_id'])); $this->assertTrue(is_int($field['meta_structure_id']));
@@ -2223,8 +2207,12 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
protected function evaluateRecordsMetadataResponse($content) protected function evaluateRecordsMetadataResponse($content)
{ {
$this->assertArrayHasKey("metadatas", $content['response']); if ( ! array_key_exists("record_metadatas", $content['response'])) {
foreach ($content['response']['metadatas'] as $meta) { var_dump($content['response']);
}
$this->assertArrayHasKey("record_metadatas", $content['response']);
foreach ($content['response']['record_metadatas'] as $meta) {
$this->assertTrue(is_array($meta), 'Un bloc meta est un objet'); $this->assertTrue(is_array($meta), 'Un bloc meta est un objet');
$this->assertArrayHasKey('meta_id', $meta); $this->assertArrayHasKey('meta_id', $meta);
$this->assertTrue(is_int($meta['meta_id'])); $this->assertTrue(is_int($meta['meta_id']));

View File

@@ -260,7 +260,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
$this->assertEquals($response['meta']['http_code'], 200); $this->assertEquals($response['meta']['http_code'], 200);
$this->checkResponseField($result, "metadatas", 'array'); $this->checkResponseField($result, "record_metadatas", 'array');
} }
public function testSet_record_status() public function testSet_record_status()
@@ -357,11 +357,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
$n = 0; $n = 0;
$response = json_decode($result->format(), true); $response = json_decode($result->format(), true);
foreach ($response['response']['basket'] as $ssel_id => $basket) { $this->assertArrayHasKey('basket', $response['response']);
$n ++;
}
$this->assertEquals(1, $n);
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$session = $appbox->get_session(); $session = $appbox->get_session();
$usr_id = $session->get_usr_id(); $usr_id = $session->get_usr_id();
@@ -370,7 +366,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
$repo = $em->getRepository('\Entities\Basket'); $repo = $em->getRepository('\Entities\Basket');
/* @var $repo \Repositories\BasketRepository */ /* @var $repo \Repositories\BasketRepository */
$basket = $repo->findUserBasket($ssel_id, self::$core->getAuthenticatedUser(), true); $basket = $repo->findUserBasket($response['response']['basket']['basket_id'], self::$core->getAuthenticatedUser(), true);
$this->assertTrue($basket instanceof \Entities\Basket); $this->assertTrue($basket instanceof \Entities\Basket);
$em->remove($basket); $em->remove($basket);