mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-16 22:43:19 +00:00
Refactor caption_field
This commit is contained in:
@@ -609,16 +609,19 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
|||||||
*/
|
*/
|
||||||
foreach ($caption->get_fields() as $field)
|
foreach ($caption->get_fields() as $field)
|
||||||
{
|
{
|
||||||
$old_datas[$field->get_meta_id()] = $field->get_value();
|
foreach($field->get_values() as $value)
|
||||||
|
{
|
||||||
|
$old_datas[$value->getId()] = $value->getValue();
|
||||||
if ($field->is_readonly() === false && $field->is_multi() === false)
|
if ($field->is_readonly() === false && $field->is_multi() === false)
|
||||||
{
|
{
|
||||||
$toupdate[$field->get_meta_id()] = array(
|
$toupdate[$value->getId()] = array(
|
||||||
'meta_struct_id' => $field->get_meta_struct_id(),
|
'meta_struct_id' => $field->get_meta_struct_id(),
|
||||||
'meta_id' => $field->get_meta_id(),
|
'meta_id' => $value->getId(),
|
||||||
'value' => array($field->get_value() . ' test')
|
'value' => array($value->getValue() . ' test')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
||||||
|
|
||||||
$crawler = $this->client->request('POST', $route, array('metadatas' => $toupdate));
|
$crawler = $this->client->request('POST', $route, array('metadatas' => $toupdate));
|
||||||
@@ -634,11 +637,13 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
|||||||
|
|
||||||
foreach ($caption->get_fields() as $field)
|
foreach ($caption->get_fields() as $field)
|
||||||
{
|
{
|
||||||
|
foreach($field->get_values() as $value)
|
||||||
|
{
|
||||||
if ($field->is_readonly() === false && $field->is_multi() === false)
|
if ($field->is_readonly() === false && $field->is_multi() === false)
|
||||||
{
|
{
|
||||||
$saved_value = $toupdate[$field->get_meta_id()]['value'][0];
|
$saved_value = $toupdate[$value->getId()]['value'][0];
|
||||||
$this->assertEquals($field->get_value(), $saved_value);
|
$this->assertEquals($value->getValue(), $saved_value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->evaluateRecordsMetadataResponse($content);
|
$this->evaluateRecordsMetadataResponse($content);
|
||||||
|
@@ -616,16 +616,19 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
|||||||
*/
|
*/
|
||||||
foreach ($caption->get_fields() as $field)
|
foreach ($caption->get_fields() as $field)
|
||||||
{
|
{
|
||||||
$old_datas[$field->get_meta_id()] = $field->get_value();
|
foreach($field->get_values() as $value)
|
||||||
|
{
|
||||||
|
$old_datas[$value->getId()] = $field->get_value();
|
||||||
if ($field->is_readonly() === false && $field->is_multi() === false)
|
if ($field->is_readonly() === false && $field->is_multi() === false)
|
||||||
{
|
{
|
||||||
$toupdate[$field->get_meta_id()] = array(
|
$toupdate[$value->getId()] = array(
|
||||||
'meta_struct_id' => $field->get_meta_struct_id(),
|
'meta_struct_id' => $field->get_meta_struct_id(),
|
||||||
'meta_id' => $field->get_meta_id(),
|
'meta_id' => $value->getId(),
|
||||||
'value' => array($field->get_value() . ' test')
|
'value' => array($value->getValue() . ' test')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
||||||
|
|
||||||
$crawler = $this->client->request('POST', $route, array('metadatas' => $toupdate), array(), array("HTTP_ACCEPT" => "application/yaml"));
|
$crawler = $this->client->request('POST', $route, array('metadatas' => $toupdate), array(), array("HTTP_ACCEPT" => "application/yaml"));
|
||||||
@@ -641,11 +644,13 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
|||||||
|
|
||||||
foreach ($caption->get_fields() as $field)
|
foreach ($caption->get_fields() as $field)
|
||||||
{
|
{
|
||||||
|
foreach($field->get_values() as $value)
|
||||||
|
{
|
||||||
if ($field->is_readonly() === false && $field->is_multi() === false)
|
if ($field->is_readonly() === false && $field->is_multi() === false)
|
||||||
{
|
{
|
||||||
$saved_value = $toupdate[$field->get_meta_id()]['value'][0];
|
$saved_value = $toupdate[$value->getId()]['value'][0];
|
||||||
$this->assertEquals($field->get_value(), $saved_value);
|
$this->assertEquals($value->getValue(), $saved_value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->evaluateRecordsMetadataResponse($content);
|
$this->evaluateRecordsMetadataResponse($content);
|
||||||
|
@@ -248,13 +248,17 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
|||||||
//valide metas
|
//valide metas
|
||||||
$metadatas = array();
|
$metadatas = array();
|
||||||
foreach (self::$record_1->get_caption()->get_fields() as $field)
|
foreach (self::$record_1->get_caption()->get_fields() as $field)
|
||||||
|
{
|
||||||
|
$values = $field->get_values();
|
||||||
|
foreach($values as $value)
|
||||||
{
|
{
|
||||||
$metadatas[] = array(
|
$metadatas[] = array(
|
||||||
'meta_id' => $field->get_meta_id()
|
'meta_id' => $value->getId()
|
||||||
, 'meta_struct_id' => $field->get_meta_struct_id()
|
, 'meta_struct_id' => $field->get_meta_struct_id()
|
||||||
, 'value' => $field->get_value()
|
, 'value' => $value->getValue()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$metadatas = array_shift($metadatas);
|
$metadatas = array_shift($metadatas);
|
||||||
$metadatas["value"] = array("new_value");
|
$metadatas["value"] = array("new_value");
|
||||||
|
@@ -38,7 +38,6 @@ class record_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
|||||||
parent::tearDownAfterClass();
|
parent::tearDownAfterClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testGet_creation_date()
|
public function testGet_creation_date()
|
||||||
{
|
{
|
||||||
$date_obj = new DateTime();
|
$date_obj = new DateTime();
|
||||||
@@ -169,7 +168,6 @@ class record_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testGet_sha256()
|
public function testGet_sha256()
|
||||||
{
|
{
|
||||||
$this->assertNotNull(static::$record_1->get_sha256());
|
$this->assertNotNull(static::$record_1->get_sha256());
|
||||||
@@ -311,15 +309,62 @@ class record_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
|||||||
foreach ($meta_structure_el as $meta_el)
|
foreach ($meta_structure_el as $meta_el)
|
||||||
{
|
{
|
||||||
$current_fields = $current_caption->get_fields(array($meta_el->get_name()));
|
$current_fields = $current_caption->get_fields(array($meta_el->get_name()));
|
||||||
$meta_id = null;
|
|
||||||
|
$field = null;
|
||||||
|
|
||||||
if (count($current_fields) > 0)
|
if (count($current_fields) > 0)
|
||||||
{
|
{
|
||||||
$meta_id = $current_fields[0]->get_meta_id();
|
$field = array_pop($current_fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
$value = $meta_el->is_multi() ? array('un', 'jeu', 'de', 'test') : array('un jeu de test');
|
if($meta_el->is_multi())
|
||||||
|
{
|
||||||
|
if($field)
|
||||||
|
{
|
||||||
|
foreach($field->get_values() as $value)
|
||||||
|
{
|
||||||
|
$metadatas[] = array(
|
||||||
|
'meta_struct_id' => $meta_el->get_id()
|
||||||
|
, 'meta_id' => $value->getId()
|
||||||
|
, 'value' => ''
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$metadatas[] = array('meta_struct_id' => $meta_el->get_id(), 'meta_id' => $meta_id, 'value' => $value);
|
$metadatas[] = array(
|
||||||
|
'meta_struct_id' => $meta_el->get_id()
|
||||||
|
, 'meta_id' => null
|
||||||
|
, 'value' => 'un'
|
||||||
|
);
|
||||||
|
$metadatas[] = array(
|
||||||
|
'meta_struct_id' => $meta_el->get_id()
|
||||||
|
, 'meta_id' => null
|
||||||
|
, 'value' => 'jeu'
|
||||||
|
);
|
||||||
|
$metadatas[] = array(
|
||||||
|
'meta_struct_id' => $meta_el->get_id()
|
||||||
|
, 'meta_id' => null
|
||||||
|
, 'value' => 'de'
|
||||||
|
);
|
||||||
|
$metadatas[] = array(
|
||||||
|
'meta_struct_id' => $meta_el->get_id()
|
||||||
|
, 'meta_id' => null
|
||||||
|
, 'value' => 'mots'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if($field)
|
||||||
|
{
|
||||||
|
$meta_id = array_pop($field->get_values())->getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
$metadatas[] = array(
|
||||||
|
'meta_struct_id' => $meta_el->get_id()
|
||||||
|
, 'meta_id' => $meta_id
|
||||||
|
, 'value' => 'un jeu de test'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self::$record_1->set_metadatas($metadatas);
|
self::$record_1->set_metadatas($metadatas);
|
||||||
@@ -512,7 +557,6 @@ class record_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
|||||||
|
|
||||||
if (!$found)
|
if (!$found)
|
||||||
$this->fail();
|
$this->fail();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user