diff --git a/lib/classes/caption/field.class.php b/lib/classes/caption/field.class.php
index 87e9b7887e..a28aeacf05 100644
--- a/lib/classes/caption/field.class.php
+++ b/lib/classes/caption/field.class.php
@@ -15,7 +15,7 @@
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
-class caption_field //implements cache_cacheableInterface
+class caption_field
{
/**
@@ -30,12 +30,6 @@ class caption_field //implements cache_cacheableInterface
*/
protected $values;
-// /**
-// *
-// * @var int
-// */
-// protected $id;
-
/**
*
* @var record
@@ -52,7 +46,6 @@ class caption_field //implements cache_cacheableInterface
public function __construct(databox_field &$databox_field, record_Interface $record)
{
$this->record = $record;
-// $this->id = (int) $id;
$this->databox_field = $databox_field;
$this->values = array();
@@ -63,13 +56,13 @@ class caption_field //implements cache_cacheableInterface
AND meta_struct_id = :meta_struct_id';
$params = array(
- ':record_id' => $record->get_record_id()
- , ':meta_struct_id' => $databox_field->get_id()
+ ':record_id' => $record->get_record_id()
+ , ':meta_struct_id' => $databox_field->get_id()
);
$stmt = $connbas->prepare($sql);
$stmt->execute($params);
- $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
+ $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if (!$databox_field->is_multi() && count($rs) > 1)
@@ -96,122 +89,54 @@ class caption_field //implements cache_cacheableInterface
return $this->record;
}
+ /**
+ *
+ * @return boolean
+ */
public function is_required()
{
return $this->databox_field->is_required();
}
+ /**
+ *
+ * @return boolean
+ */
public function is_multi()
{
return $this->databox_field->is_multi();
}
+ /**
+ *
+ * @return boolean
+ */
public function is_readonly()
{
return $this->databox_field->is_readonly();
}
-// /**
-// *
-// * @return caption_field
-// */
-// public function delete()
-// {
-// $connbas = $this->databox_field->get_connection();
-//
-// $sql = 'DELETE FROM metadatas WHERE id = :id';
-// $stmt = $connbas->prepare($sql);
-// $stmt->execute(array(':id' => $this->id));
-// $stmt->closeCursor();
-// $this->delete_data_from_cache();
-//
-// $sbas_id = $this->record->get_sbas_id();
-// $this->record->get_caption()->delete_data_from_cache();
-//
-// try
-// {
-// $registry = registry::get_instance();
-// $sphinx_rt = sphinxrt::get_instance($registry);
-//
-// $sbas_params = phrasea::sbas_params();
-//
-// if (isset($sbas_params[$sbas_id]))
-// {
-// $params = $sbas_params[$sbas_id];
-// $sbas_crc = crc32(str_replace(array('.', '%'), '_', sprintf('%s_%s_%s_%s', $params['host'], $params['port'], $params['user'], $params['dbname'])));
-// $sphinx_rt->delete(array("metadatas" . $sbas_crc, "metadatas" . $sbas_crc . "_stemmed_fr", "metadatas" . $sbas_crc . "_stemmed_en"), "metas_realtime" . $sbas_crc, $this->id);
-// $sphinx_rt->delete(array("documents" . $sbas_crc, "documents" . $sbas_crc . "_stemmed_fr", "documents" . $sbas_crc . "_stemmed_en"), "docs_realtime" . $sbas_crc, $this->record->get_record_id());
-// }
-// }
-// catch (Exception $e)
-// {
-// unset($e);
-// }
-//
-// return $this;
-// }
-//
-// /**
-// * Part of the cache_cacheableInterface
-// *
-// * @param string $option
-// * @return string
-// */
-// public function get_cache_key($option = null)
-// {
-// return 'captionfield_' . $this->record->get_serialize_key()
-// . $this->id . ($option ? '_' . $option : '');
-// }
-//
-// /**
-// * Part of the cache_cacheableInterface
-// *
-// * @param string $option
-// * @return mixed
-// */
-// public function get_data_from_cache($option = null)
-// {
-// $databox = databox::get_instance($this->record->get_sbas_id());
-//
-// return $databox->get_data_from_cache($this->get_cache_key($option));
-// }
-//
-// /**
-// * Part of the cache_cacheableInterface
-// *
-// * @param mixed $value
-// * @param string $option
-// * @param int $duration
-// * @return caption_field
-// */
-// public function set_data_to_cache($value, $option = null, $duration = 0)
-// {
-// $databox = databox::get_instance($this->record->get_sbas_id());
-// $databox->set_data_to_cache($value, $this->get_cache_key($option), $duration);
-//
-// return $this;
-// }
-//
-// /**
-// * Part of the cache_cacheableInterface
-// *
-// * @param string $option
-// * @return caption_field
-// */
-// public function delete_data_from_cache($option = null)
-// {
-// $databox = databox::get_instance($this->record->get_sbas_id());
-// $databox->delete_data_from_cache($this->get_cache_key($option));
-//
-// return $this;
-// }
-//
-// /**
-// *
-// * @param array $value
-// * @param databox_field $databox_field
-// * @return string
-// */
+ /**
+ *
+ * @return caption_field
+ */
+ public function delete()
+ {
+
+ foreach ($this->get_values() as $value)
+ {
+ $value->delete();
+ }
+
+ return $this;
+ }
+
+ /**
+ *
+ * @param array $values
+ * @param string $separator
+ * @return string
+ */
protected static function serialize_value(Array $values, $separator)
{
if (strlen($separator) > 1)
@@ -224,178 +149,43 @@ class caption_field //implements cache_cacheableInterface
$array_values = array();
- foreach($values as $value)
+ foreach ($values as $value)
{
$array_values[] = $value->getValue();
}
return implode($separator, $array_values);
}
-//
-// /**
-// *
-// * @param array $value
-// * @return caption_field
-// */
-// public function set_value(Array $value)
-// {
-// $sbas_id = $this->databox_field->get_databox()->get_sbas_id();
-// $connbas = $this->databox_field->get_connection();
-//
-// $sql_up = 'UPDATE metadatas SET value = :value WHERE id = :meta_id';
-// $stmt_up = $connbas->prepare($sql_up);
-// $stmt_up->execute(array(':meta_id' => $this->get_meta_id(), ':value' => self::serialize_value($value, $this->databox_field->get_separator())));
-// $stmt_up->closeCursor();
-//
-// try
-// {
-// $registry = registry::get_instance();
-// $sphinx_rt = sphinxrt::get_instance($registry);
-//
-// $sbas_params = phrasea::sbas_params();
-//
-// if (isset($sbas_params[$sbas_id]))
-// {
-// $params = $sbas_params[$sbas_id];
-// $sbas_crc = crc32(str_replace(array('.', '%'), '_', sprintf('%s_%s_%s_%s', $params['host'], $params['port'], $params['user'], $params['dbname'])));
-// $sphinx_rt->delete(array("metadatas" . $sbas_crc, "metadatas" . $sbas_crc . "_stemmed_fr", "metadatas" . $sbas_crc . "_stemmed_en"), "", $this->get_meta_id());
-// $sphinx_rt->delete(array("documents" . $sbas_crc, "documents" . $sbas_crc . "_stemmed_fr", "documents" . $sbas_crc . "_stemmed_en"), "", $this->record->get_record_id());
-// }
-// }
-// catch (Exception $e)
-// {
-//
-// }
-//
-// $this->update_cache_value($value);
-//
-// return $this;
-// }
-//
-// /**
-// *
-// * @param array $value
-// * @return caption_field
-// */
-// public function update_cache_value(Array $value)
-// {
-// $this->delete_data_from_cache();
-// $this->record->get_caption()->delete_data_from_cache();
-// $sbas_id = $this->databox_field->get_databox()->get_sbas_id();
-// try
-// {
-// $registry = registry::get_instance();
-//
-// $sbas_params = phrasea::sbas_params();
-//
-// if (isset($sbas_params[$sbas_id]))
-// {
-// $params = $sbas_params[$sbas_id];
-// $sbas_crc = crc32(str_replace(array('.', '%'), '_', sprintf('%s_%s_%s_%s', $params['host'], $params['port'], $params['user'], $params['dbname'])));
-//
-// $sphinx_rt = sphinxrt::get_instance($registry);
-// $sphinx_rt->replace_in_metas(
-// "metas_realtime" . $sbas_crc, $this->id, $this->databox_field->get_id(), $this->record->get_record_id(), $sbas_id, phrasea::collFromBas($this->record->get_base_id()), ($this->record->is_grouping() ? '1' : '0'), $this->record->get_type(), $value, $this->record->get_creation_date()
-// );
-//
-// $all_datas = array();
-// foreach ($this->record->get_caption()->get_fields() as $field)
-// {
-// if (!$field->is_indexable())
-// continue;
-// $all_datas[] = $field->get_value(true);
-// }
-// $all_datas = implode(' ', $all_datas);
-//
-// $sphinx_rt->replace_in_documents(
-// "docs_realtime" . $sbas_crc, //$this->id,
-// $this->record->get_record_id(), $all_datas, $sbas_id, phrasea::collFromBas($this->record->get_base_id()), ($this->record->is_grouping() ? '1' : '0'), $this->record->get_type(), $this->record->get_creation_date()
-// );
-// }
-// }
-// catch (Exception $e)
-// {
-// unset($e);
-// }
-//
-// return $this;
-// }
/**
*
- * @param databox_field $databox_field
- * @param record_Interface $record
- * @param array $value
- * @return caption_field
-// */
-// public static function create(databox_field &$databox_field, record_Interface $record, Array $value)
-// {
-//
-// $sbas_id = $databox_field->get_databox()->get_sbas_id();
-// $connbas = $databox_field->get_connection();
-// $sql_ins = 'INSERT INTO metadatas (id, record_id, meta_struct_id, value)
-// VALUES
-// (null, :record_id, :field, :value)';
-// $stmt_ins = $connbas->prepare($sql_ins);
-// $stmt_ins->execute(
-// array(
-// ':record_id' => $record->get_record_id(),
-// ':field' => $databox_field->get_id(),
-// ':value' => self::serialize_value($value, $databox_field->get_separator())
-// )
-// );
-// $stmt_ins->closeCursor();
-// $meta_id = $connbas->lastInsertId();
-//
-// $caption_field = new self($databox_field, $record, $meta_id);
-// $caption_field->update_cache_value($value);
-//
-// $record->get_caption()->delete_data_from_cache();
-//
-// return $caption_field;
-// }
-
-// /**
-// *
-// * @return string
-// */
-// public function get_value($as_string = false, $custom_separator = false)
-// {
-// if ($this->databox_field->is_multi() === true)
-// {
-// if ($as_string === true && $custom_separator === false)
-// {
-// return $this->value;
-// }
-// $separator = $this->databox_field->get_separator();
-// $array_values = self::get_multi_values($this->value, $separator);
-//
-// if ($as_string === true && $custom_separator !== false)
-// return self::serialize_value($array_values, $custom_separator);
-// else
-// return $array_values;
-// }
-// else
-// {
-// return $this->value;
-// }
-// }
-
+ * @return array
+ */
public function get_values()
{
return $this->values;
}
+ /**
+ *
+ * @param int $meta_id
+ * @return array
+ */
public function get_value($meta_id)
{
return $this->values[$meta_id];
}
+ /**
+ *
+ * @param string $custom_separator
+ * @return mixed
+ */
public function get_serialized_values($custom_separator = false)
{
if ($this->databox_field->is_multi() === true)
{
- if($custom_separator !== false)
+ if ($custom_separator !== false)
$separator = $custom_separator;
else
$separator = $this->databox_field->get_separator();
@@ -404,7 +194,7 @@ class caption_field //implements cache_cacheableInterface
}
else
{
- foreach($this->values as $value)
+ foreach ($this->values as $value)
{
/* @var $value Caption_Field_Value */
@@ -442,15 +232,6 @@ class caption_field //implements cache_cacheableInterface
return $this->databox_field->is_indexable();
}
-// /**
-// *
-// * @return int
-// */
-// public function get_meta_id()
-// {
-// return $this->id;
-// }
-
/**
*
* @return databox_field
@@ -466,16 +247,16 @@ class caption_field //implements cache_cacheableInterface
*/
public function highlight_thesaurus()
{
- $appbox = appbox::get_instance();
- $session = $appbox->get_session();
+ $appbox = appbox::get_instance();
+ $session = $appbox->get_session();
$registry = $appbox->get_registry();
- $unicode = new unicode();
+ $unicode = new unicode();
$sbas_id = $this->databox_field->get_databox()->get_sbas_id();
$value = $this->get_serialized_values();
- $databox = databox::get_instance($sbas_id);
+ $databox = databox::get_instance($sbas_id);
$XPATH_thesaurus = $databox->get_xpath_thesaurus();
$tbranch = $this->databox_field->get_tbranch();
@@ -488,7 +269,7 @@ class caption_field //implements cache_cacheableInterface
$cleanvalue = str_replace(array("", "", "'"), array("", "", "'"), $fvalue);
list($term_noacc, $context_noacc) = $this->splitTermAndContext($cleanvalue);
- $term_noacc = $unicode->remove_indexer_chars($term_noacc);
+ $term_noacc = $unicode->remove_indexer_chars($term_noacc);
$context_noacc = $unicode->remove_indexer_chars($context_noacc);
if ($context_noacc)
{
@@ -496,9 +277,9 @@ class caption_field //implements cache_cacheableInterface
}
else
{
- $q = "//sy[@w='" . $term_noacc . "' and not(@k)]";
+ $q = "//sy[@w='" . $term_noacc . "' and not(@k)]";
}
- $qjs = $link = "";
+ $qjs = $link = "";
foreach ($DOM_branchs as $DOM_branch)
{
$nodes = $XPATH_thesaurus->cache_query($q, $DOM_branch);
@@ -530,7 +311,7 @@ class caption_field //implements cache_cacheableInterface
$k = $synonym->getAttribute("k");
if ($synonym->getAttribute("w") != $term_noacc || $k != $context_noacc)
{
- $link = $qjs = $synonym->getAttribute("v");
+ $link = $qjs = $synonym->getAttribute("v");
if ($k)
{
$link .= " (" . $k . ")";
@@ -559,12 +340,12 @@ class caption_field //implements cache_cacheableInterface
if ($qjs)
{
$value = "get_name())
- . "');return(false);\">"
- . $link
- . "";
+ . str_replace("'", "\'", $qjs)
+ . "', '"
+ . str_replace("'", "\'", $this->get_name())
+ . "');return(false);\">"
+ . $link
+ . "";
}
}
@@ -578,14 +359,14 @@ class caption_field //implements cache_cacheableInterface
*/
protected function splitTermAndContext($word)
{
- $term = trim($word);
+ $term = trim($word);
$context = "";
- if (($po = strpos($term, "(")) !== false)
+ if (($po = strpos($term, "(")) !== false)
{
if (($pc = strpos($term, ")", $po)) !== false)
{
$context = trim(substr($term, $po + 1, $pc - $po - 1));
- $term = trim(substr($term, 0, $po));
+ $term = trim(substr($term, 0, $po));
}
}
@@ -611,7 +392,7 @@ class caption_field //implements cache_cacheableInterface
// en regexp pour utiliser split
$separator = preg_split('//', $separator, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
$separator = '/\\' . implode('|\\', $separator) . '/';
- $values = preg_split($separator, $serialized_value);
+ $values = preg_split($separator, $serialized_value);
}
foreach ($values as $key => $value)
@@ -626,31 +407,33 @@ class caption_field //implements cache_cacheableInterface
{
$sql = 'SELECT count(id) as count_id FROM metadatas
WHERE meta_struct_id = :meta_struct_id';
- $stmt = $databox_field->get_databox()->get_connection()->prepare($sql);
+
+ $stmt = $databox_field->get_databox()->get_connection()->prepare($sql);
$params = array(
- ':meta_struct_id' => $databox_field->get_id()
+ ':meta_struct_id' => $databox_field->get_id()
);
$stmt->execute($params);
$rowcount = $stmt->rowCount();
$stmt->closeCursor();
- $n = 0;
+ $n = 0;
$increment = 500;
while ($n < $rowcount)
{
$sql = 'SELECT record_id, id FROM metadatas
- WHERE meta_struct_id = :meta_struct_id LIMIT ' . $n . ', ' . $increment;
+ WHERE meta_struct_id = :meta_struct_id
+ LIMIT ' . $n . ', ' . $increment;
$params = array(
- ':meta_struct_id' => $databox_field->get_id()
+ ':meta_struct_id' => $databox_field->get_id()
);
- $stmt = $databox_field->get_databox()->get_connection()->prepare($sql);
+ $stmt = $databox_field->get_databox()->get_connection()->prepare($sql);
$stmt->execute($params);
$rowcount = $stmt->rowCount();
- $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
+ $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
unset($stmt);
@@ -658,8 +441,8 @@ class caption_field //implements cache_cacheableInterface
{
try
{
- $record = $databox_field->get_databox()->get_record($row['record_id']);
- $caption_field = new caption_field($databox_field, $record, $row['id']);
+ $record = $databox_field->get_databox()->get_record($row['record_id']);
+ $caption_field = new caption_field($databox_field, $record);
$caption_field->delete();
unset($caption_field);
unset($record);
diff --git a/lib/unitTest/api/v1/api_v1_adapterTest.php b/lib/unitTest/api/v1/api_v1_adapterTest.php
index cf08fb43e6..6af633727d 100644
--- a/lib/unitTest/api/v1/api_v1_adapterTest.php
+++ b/lib/unitTest/api/v1/api_v1_adapterTest.php
@@ -28,7 +28,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testGet_error_code()
{
$request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
- $result = $this->object->get_error_code($request, 400);
+ $result = $this->object->get_error_code($request, 400);
$this->assertTrue(is_object(json_decode($result->format())));
$this->assertEquals(400, $result->get_http_code());
$this->assertEquals('application/json', $result->get_content_type());
@@ -62,7 +62,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testGet_error_message()
{
$request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
- $result = $this->object->get_error_message($request, API_V1_result::ERROR_BAD_REQUEST);
+ $result = $this->object->get_error_message($request, API_V1_result::ERROR_BAD_REQUEST);
$this->assertTrue(is_object(json_decode($result->format())));
$this->assertEquals(400, $result->get_http_code());
$this->assertEquals('application/json', $result->get_content_type());
@@ -101,7 +101,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testGet_databoxes()
{
$request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
- $result = $this->object->get_databoxes($request);
+ $result = $this->object->get_databoxes($request);
$this->assertEquals(200, $result->get_http_code());
$this->assertEquals('application/json', $result->get_content_type());
$this->assertTrue(is_object(json_decode($result->format())));
@@ -109,7 +109,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testGet_databox_collections()
{
- $appbox = appbox::get_instance();
+ $appbox = appbox::get_instance();
$request = new Request();
foreach ($appbox->get_databoxes() as $databox)
{
@@ -125,11 +125,11 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
$appbox = appbox::get_instance();
$request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
- $result = $this->object->get_record($request, self::$record_1->get_sbas_id(), "-40");
+ $result = $this->object->get_record($request, self::$record_1->get_sbas_id(), "-40");
$this->assertEquals(400, $result->get_http_code());
$request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
- $result = $this->object->get_record($request, self::$record_1->get_sbas_id(), self::$record_1->get_record_id());
+ $result = $this->object->get_record($request, self::$record_1->get_sbas_id(), self::$record_1->get_record_id());
$this->assertEquals(200, $result->get_http_code());
$this->assertEquals('application/json', $result->get_content_type());
$this->assertTrue(is_object(json_decode($result->format())));
@@ -137,7 +137,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testGet_databox_status()
{
- $appbox = appbox::get_instance();
+ $appbox = appbox::get_instance();
$request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
foreach ($appbox->get_databoxes() as $databox)
{
@@ -150,7 +150,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testGet_databox_metadatas()
{
- $appbox = appbox::get_instance();
+ $appbox = appbox::get_instance();
$request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
foreach ($appbox->get_databoxes() as $databox)
{
@@ -163,7 +163,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testGet_databox_terms()
{
- $appbox = appbox::get_instance();
+ $appbox = appbox::get_instance();
$request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
foreach ($appbox->get_databoxes() as $databox)
{
@@ -177,7 +177,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testSearch_records()
{
$request = new Request(array('record_type' => "image"), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
- $result = $this->object->search_records($request);
+ $result = $this->object->search_records($request);
$this->assertEquals(200, $result->get_http_code());
$this->assertEquals('application/json', $result->get_content_type());
$this->assertTrue(is_object(json_decode($result->format())));
@@ -188,7 +188,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
$appbox = appbox::get_instance();
$request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
- $result = $this->object->get_record_related($request, self::$record_1->get_sbas_id(), self::$record_1->get_record_id());
+ $result = $this->object->get_record_related($request, self::$record_1->get_sbas_id(), self::$record_1->get_record_id());
$this->assertEquals(200, $result->get_http_code());
$this->assertEquals('application/json', $result->get_content_type());
$this->assertTrue(is_object(json_decode($result->format())));
@@ -199,7 +199,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
$appbox = appbox::get_instance();
$request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
- $result = $this->object->get_record_metadatas($request, self::$record_1->get_sbas_id(), self::$record_1->get_record_id());
+ $result = $this->object->get_record_metadatas($request, self::$record_1->get_sbas_id(), self::$record_1->get_record_id());
$this->assertEquals(200, $result->get_http_code());
$this->assertEquals('application/json', $result->get_content_type());
$this->assertTrue(is_object(json_decode($result->format())));
@@ -211,7 +211,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
$request = new Request();
$request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
- $result = $this->object->get_record_status($request, self::$record_1->get_sbas_id(), self::$record_1->get_record_id());
+ $result = $this->object->get_record_status($request, self::$record_1->get_sbas_id(), self::$record_1->get_record_id());
$this->assertEquals(200, $result->get_http_code());
$this->assertEquals('application/json', $result->get_content_type());
$this->assertTrue(is_object(json_decode($result->format())));
@@ -222,7 +222,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
$appbox = appbox::get_instance();
$request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
- $result = $this->object->get_record_embed($request, self::$record_1->get_sbas_id(), self::$record_1->get_record_id());
+ $result = $this->object->get_record_embed($request, self::$record_1->get_sbas_id(), self::$record_1->get_record_id());
$this->assertEquals(200, $result->get_http_code());
$this->assertEquals('application/json', $result->get_content_type());
$this->assertTrue(is_object(json_decode($result->format())));
@@ -230,44 +230,53 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testSet_record_metadatas()
{
- $appbox = appbox::get_instance();
+ $appbox = appbox::get_instance();
$databox = self::$record_1->get_databox();
$request = new Request(array("salut" => "salut c'est la fete"), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
- $result = $this->object->set_record_metadatas($request, self::$record_1->get_sbas_id(), self::$record_1->get_record_id());
+ $result = $this->object->set_record_metadatas($request, self::$record_1->get_sbas_id(), self::$record_1->get_record_id());
$this->assertEquals(400, $result->get_http_code());
$request = new Request(array("metadatas" => "salut c'est la fete"), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
$this->object->set_record_metadatas($request, self::$record_1->get_sbas_id(), self::$record_1->get_record_id());
$this->assertEquals(400, $result->get_http_code());
- if(sizeof(self::$record_1->get_caption()->get_fields()) == 0)
+ if (sizeof(self::$record_1->get_caption()->get_fields()) == 0)
{
$caption_field_value = caption_Field_Value::create(databox_field::get_instance($databox, 1), self::$record_1, 'my value');
}
//valide metas
$metadatas = array();
- foreach (self::$record_1->get_caption()->get_fields() as $field)
+
+ foreach (self::$record_1->get_databox()->get_meta_structure()->get_elements() as $field)
{
- $values = $field->get_values();
- foreach($values as $value)
+ try
{
- $metadatas[] = array(
- 'meta_id' => $value->getId()
- , 'meta_struct_id' => $field->get_meta_struct_id()
- , 'value' => $value->getValue()
- );
+ $values = self::$record_1->get_caption()->get_field($field->get_name())->get_values();
+ $value = array_pop($values);
+ $meta_id = $value->getId();
}
+ catch (\Exception $e)
+ {
+ $meta_id = null;
+ }
+
+ $metadatas[] = array(
+ 'meta_id' => $meta_id
+ , 'meta_struct_id' => $field->get_id()
+ , 'value' => 'podom pom pom ' . $field->get_id()
+ );
}
- $metadatas = array_shift($metadatas);
+ $metadatas = array_shift($metadatas);
$metadatas["value"] = "new_value";
-
$request = new Request(array("metadatas" => array($metadatas)), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
$result = $this->object->set_record_metadatas($request, self::$record_1->get_sbas_id(), self::$record_1->get_record_id());
+ $response = json_decode($result->format());
+
$this->checkResponseField($result, "metadatas", PHPUnit_Framework_Constraint_IsType::TYPE_OBJECT);
}
@@ -277,8 +286,8 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testSet_record_status()
{
$appbox = appbox::get_instance();
- $stub = $this->getMock("API_V1_adapter", array("list_record_status"), array(false, &$appbox, bootstrap::getCore()));
- $appbox = appbox::get_instance();
+ $stub = $this->getMock("API_V1_adapter", array("list_record_status"), array(false, &$appbox, bootstrap::getCore()));
+ $appbox = appbox::get_instance();
$databox = self::$record_1->get_databox();
$statusbit = null;
@@ -289,7 +298,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
}
$request = new Request(array("salut" => "salut c'est la fete"), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
- $result = $stub->set_record_status($request, self::$record_1->get_sbas_id(), self::$record_1->get_record_id());
+ $result = $stub->set_record_status($request, self::$record_1->get_sbas_id(), self::$record_1->get_record_id());
$this->assertEquals(400, $result->get_http_code());
$request = new Request(array("status" => "salut c'est la fete"), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
@@ -301,10 +310,10 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
$request = new Request(array("status" => $status), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
//check method use record->get_caption
$stub->expects($this->once())
- ->method("list_record_status")
- ->will($this->returnValue(new stdClass()));
+ ->method("list_record_status")
+ ->will($this->returnValue(new stdClass()));
//check for metadas fiels in response
- $result = $stub->set_record_status($request, self::$record_1->get_sbas_id(), self::$record_1->get_record_id());
+ $result = $stub->set_record_status($request, self::$record_1->get_sbas_id(), self::$record_1->get_record_id());
$this->checkResponseField($result, "status", PHPUnit_Framework_Constraint_IsType::TYPE_OBJECT);
}
@@ -314,11 +323,11 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testSet_record_collection()
{
$appbox = appbox::get_instance();
- $stub = $this->getMock("API_V1_adapter", array("list_record"), array(false, &$appbox, bootstrap::getCore()));
+ $stub = $this->getMock("API_V1_adapter", array("list_record"), array(false, &$appbox, bootstrap::getCore()));
$databox = self::$record_1->get_databox();
$request = new Request(array("salut" => "salut c'est la fete"), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
- $result = $stub->set_record_collection($request, self::$record_1->get_sbas_id(), self::$record_1->get_record_id());
+ $result = $stub->set_record_collection($request, self::$record_1->get_sbas_id(), self::$record_1->get_record_id());
$this->assertEquals(400, $result->get_http_code());
foreach ($appbox->get_databoxes() as $databox)
@@ -332,10 +341,10 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
$request = new Request(array("base_id" => $collection->get_base_id()), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
//check method use record->get_caption
$stub->expects($this->once())
- ->method("list_record")
- ->will($this->returnValue(new stdClass()));
+ ->method("list_record")
+ ->will($this->returnValue(new stdClass()));
//check for metadas fiels in response
- $result = $stub->set_record_collection($request, self::$record_1->get_sbas_id(), self::$record_1->get_record_id());
+ $result = $stub->set_record_collection($request, self::$record_1->get_sbas_id(), self::$record_1->get_record_id());
$this->checkResponseField($result, "record", PHPUnit_Framework_Constraint_IsType::TYPE_OBJECT);
}
@@ -346,14 +355,14 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
- 'This test has not been implemented yet.'
+ 'This test has not been implemented yet.'
);
}
public function testSearch_baskets()
{
$request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
- $result = $this->object->search_baskets($request);
+ $result = $this->object->search_baskets($request);
$this->assertEquals(200, $result->get_http_code());
$this->assertEquals('application/json', $result->get_content_type());
$this->assertTrue(is_object(json_decode($result->format())));
@@ -362,7 +371,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testCreate_basket()
{
$request = new Request(array(), array(), array('name' => 'BIG BASKET'), array(), array(), array('HTTP_Accept' => 'application/json'));
- $result = $this->object->create_basket($request);
+ $result = $this->object->create_basket($request);
$this->assertEquals(200, $result->get_http_code());
$this->assertEquals('application/json', $result->get_content_type());
$this->assertTrue(is_object(json_decode($result->format())));
@@ -374,11 +383,11 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
}
$this->assertEquals(1, $n);
- $appbox = appbox::get_instance();
+ $appbox = appbox::get_instance();
$session = $appbox->get_session();
- $usr_id = $session->get_usr_id();
+ $usr_id = $session->get_usr_id();
- $em = self::$core->getEntityManager();
+ $em = self::$core->getEntityManager();
$repo = $em->getRepository('\Entities\Basket');
/* @var $repo \Repositories\BasketRepository */
@@ -393,7 +402,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
{
$appbox = appbox::get_instance();
$usr_id = $appbox->get_session()->get_usr_id();
- $user = User_Adapter::getInstance($usr_id, $appbox);
+ $user = User_Adapter::getInstance($usr_id, $appbox);
$em = self::$core->getEntityManager();
@@ -407,7 +416,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
$ssel_id = $Basket->getId();
$request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
- $result = $this->object->delete_basket($request, $ssel_id);
+ $result = $this->object->delete_basket($request, $ssel_id);
$this->assertEquals(200, $result->get_http_code());
$this->assertEquals('application/json', $result->get_content_type());
$this->assertTrue(is_object(json_decode($result->format())));
@@ -433,7 +442,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
$basket = $this->insertOneBasket();
$request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
- $result = $this->object->get_basket($request, $basket->getId());
+ $result = $this->object->get_basket($request, $basket->getId());
$this->assertEquals(200, $result->get_http_code());
$this->assertEquals('application/json', $result->get_content_type());
$this->assertTrue(is_object(json_decode($result->format())));
@@ -447,12 +456,12 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
$basket = $this->insertOneBasket();
$request = new Request(array(), array(), array('name' => 'PROUTO'), array(), array(), array('HTTP_Accept' => 'application/json'));
- $result = $this->object->set_basket_title($request, $basket->getId());
+ $result = $this->object->set_basket_title($request, $basket->getId());
$this->assertEquals(200, $result->get_http_code());
$this->assertEquals('application/json', $result->get_content_type());
$this->assertTrue(is_object(json_decode($result->format())));
- $repository =self::$core->getEntityManager()->getRepository('\Entities\Basket');
+ $repository = self::$core->getEntityManager()->getRepository('\Entities\Basket');
$ret_bask = $repository->find($basket->getId());
@@ -467,12 +476,12 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
$basket = $this->insertOneBasket();
$request = new Request(array(), array(), array('description' => 'une belle description'), array(), array(), array('HTTP_Accept' => 'application/json'));
- $result = $this->object->set_basket_description($request, $basket->getId());
+ $result = $this->object->set_basket_description($request, $basket->getId());
$this->assertEquals(200, $result->get_http_code());
$this->assertEquals('application/json', $result->get_content_type());
$this->assertTrue(is_object(json_decode($result->format())));
- $repository =self::$core->getEntityManager()->getRepository('\Entities\Basket');
+ $repository = self::$core->getEntityManager()->getRepository('\Entities\Basket');
$ret_bask = $repository->find($basket->getId());
@@ -482,10 +491,10 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testSearch_publications()
{
$appbox = appbox::get_instance();
- $stub = $this->getMock("API_V1_adapter", array("list_publication"), array(false, &$appbox, bootstrap::getCore()));
+ $stub = $this->getMock("API_V1_adapter", array("list_publication"), array(false, &$appbox, bootstrap::getCore()));
$request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
- $feed = Feed_Adapter::create($appbox, self::$user, "hello", "salut");
- $result = $this->object->search_publications($request, self::$user);
+ $feed = Feed_Adapter::create($appbox, self::$user, "hello", "salut");
+ $result = $this->object->search_publications($request, self::$user);
$this->checkResponseField($result, "feeds", PHPUnit_Framework_Constraint_IsType::TYPE_OBJECT);
$feed->delete();
}
@@ -494,7 +503,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
- 'This test has not been implemented yet.'
+ 'This test has not been implemented yet.'
);
}
@@ -502,13 +511,13 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
{
$appbox = appbox::get_instance();
- $date = new DateTime();
- $request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
- $feed = Feed_Adapter::create($appbox, self::$user, "hello", "salut");
- $feed_publisher = Feed_Publisher_Adapter::getPublisher($appbox, $feed, self::$user);
- $feed_entry = Feed_Entry_Adapter::create($appbox, $feed, $feed_publisher, "coucou", "hello", "me", "my@email.com");
+ $date = new DateTime();
+ $request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
+ $feed = Feed_Adapter::create($appbox, self::$user, "hello", "salut");
+ $feed_publisher = Feed_Publisher_Adapter::getPublisher($appbox, $feed, self::$user);
+ $feed_entry = Feed_Entry_Adapter::create($appbox, $feed, $feed_publisher, "coucou", "hello", "me", "my@email.com");
$feed_entry_item = Feed_Entry_Item::create($appbox, $feed_entry, self::$record_1);
- $coll = Feed_Collection::load_all($appbox, self::$user);
+ $coll = Feed_Collection::load_all($appbox, self::$user);
foreach ($coll->get_feeds() as $feed)
{
$result = $this->object->get_publication($request, $feed->get_id(), self::$user);
@@ -524,7 +533,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
- 'This test has not been implemented yet.'
+ 'This test has not been implemented yet.'
);
}
@@ -532,7 +541,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
- 'This test has not been implemented yet.'
+ 'This test has not been implemented yet.'
);
}
@@ -540,7 +549,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
- 'This test has not been implemented yet.'
+ 'This test has not been implemented yet.'
);
}