mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-15 05:53:13 +00:00
Fix unit tests metadatas
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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
|
||||
@@ -626,6 +407,7 @@ 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);
|
||||
$params = array(
|
||||
':meta_struct_id' => $databox_field->get_id()
|
||||
@@ -641,7 +423,8 @@ class caption_field //implements cache_cacheableInterface
|
||||
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()
|
||||
@@ -659,7 +442,7 @@ 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']);
|
||||
$caption_field = new caption_field($databox_field, $record);
|
||||
$caption_field->delete();
|
||||
unset($caption_field);
|
||||
unset($record);
|
||||
|
@@ -240,34 +240,43 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
||||
$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["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);
|
||||
}
|
||||
|
||||
@@ -452,7 +461,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
||||
$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());
|
||||
|
||||
@@ -472,7 +481,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
||||
$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());
|
||||
|
||||
|
Reference in New Issue
Block a user