complete admin controller tests

This commit is contained in:
Nicolas Le Goff
2012-01-27 17:16:50 +01:00
parent 7099059f0b
commit 694f943d23
9 changed files with 669 additions and 380 deletions

View File

@@ -124,29 +124,29 @@ class databox_field implements cache_cacheableInterface
protected $Vocabulary;
protected $VocabularyRestriction = false;
const TYPE_TEXT = "text";
const TYPE_DATE = "date";
const TYPE_TEXT = "text";
const TYPE_DATE = "date";
const TYPE_STRING = "string";
const TYPE_NUMBER = "number";
/**
* http://dublincore.org/documents/dces/
*/
const DCES_TITLE = 'Title';
const DCES_CREATOR = 'Creator';
const DCES_SUBJECT = 'Subject';
const DCES_TITLE = 'Title';
const DCES_CREATOR = 'Creator';
const DCES_SUBJECT = 'Subject';
const DCES_DESCRIPTION = 'Description';
const DCES_PUBLISHER = 'Publisher';
const DCES_PUBLISHER = 'Publisher';
const DCES_CONTRIBUTOR = 'Contributor';
const DCES_DATE = 'Date';
const DCES_TYPE = 'Type';
const DCES_FORMAT = 'Format';
const DCES_IDENTIFIER = 'Identifier';
const DCES_SOURCE = 'Source';
const DCES_LANGUAGE = 'Language';
const DCES_RELATION = 'Relation';
const DCES_COVERAGE = 'Coverage';
const DCES_RIGHTS = 'Rights';
const DCES_DATE = 'Date';
const DCES_TYPE = 'Type';
const DCES_FORMAT = 'Format';
const DCES_IDENTIFIER = 'Identifier';
const DCES_SOURCE = 'Source';
const DCES_LANGUAGE = 'Language';
const DCES_RELATION = 'Relation';
const DCES_COVERAGE = 'Coverage';
const DCES_RIGHTS = 'Rights';
/**
*
@@ -169,7 +169,7 @@ class databox_field implements cache_cacheableInterface
$stmt = $connbas->prepare($sql);
$stmt->execute(array(':id' => $id));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$this->id = (int) $id;
@@ -190,7 +190,7 @@ class databox_field implements cache_cacheableInterface
}
catch (Exception $e)
{
}
if ($row['dces_element'])
@@ -239,7 +239,7 @@ class databox_field implements cache_cacheableInterface
*/
public static function get_instance(databox &$databox, $id)
{
$cache_key = 'field_' . $id;
$cache_key = 'field_' . $id;
$instance_id = $databox->get_sbas_id() . '_' . $id;
if (!isset(self::$_instance[$instance_id]) || (self::$_instance[$instance_id] instanceof self) === false)
{
@@ -289,16 +289,16 @@ class databox_field implements cache_cacheableInterface
caption_field::delete_all_metadatas($this);
$connbas = $this->get_connection();
$sql = 'DELETE FROM metadatas_structure WHERE id = :id';
$stmt = $connbas->prepare($sql);
$sql = 'DELETE FROM metadatas_structure WHERE id = :id';
$stmt = $connbas->prepare($sql);
$stmt->execute(array(':id' => $this->get_id()));
$stmt->closeCursor();
$dom_struct = $this->databox->get_dom_structure();
$xp_struct = $this->databox->get_xpath_structure();
$xp_struct = $this->databox->get_xpath_structure();
$nodes = $xp_struct->query(
'/record/description/*[@meta_id=' . $this->id . ']'
'/record/description/*[@meta_id=' . $this->id . ']'
);
foreach ($nodes as $node)
@@ -338,35 +338,35 @@ class databox_field implements cache_cacheableInterface
WHERE id = :id';
$params = array(
':name' => $this->name,
':source' => $this->source->get_source(),
':indexable' => $this->indexable ? '1' : '0',
':readonly' => $this->readonly ? '1' : '0',
':required' => $this->required ? '1' : '0',
':separator' => $this->separator,
':multi' => $this->multi ? '1' : '0',
':report' => $this->report ? '1' : '0',
':type' => $this->type,
':tbranch' => $this->tbranch,
':thumbtitle' => $this->thumbtitle,
':VocabularyControlType' => $this->Vocabulary ? $this->Vocabulary->getType() : null,
':RestrictVocab' => $this->Vocabulary ? ($this->VocabularyRestriction ? '1' : '0') : '0',
':id' => $this->id
':name' => $this->name,
':source' => $this->source->get_source(),
':indexable' => $this->indexable ? '1' : '0',
':readonly' => $this->readonly ? '1' : '0',
':required' => $this->required ? '1' : '0',
':separator' => $this->separator,
':multi' => $this->multi ? '1' : '0',
':report' => $this->report ? '1' : '0',
':type' => $this->type,
':tbranch' => $this->tbranch,
':thumbtitle' => $this->thumbtitle,
':VocabularyControlType' => $this->Vocabulary ? $this->Vocabulary->getType() : null,
':RestrictVocab' => $this->Vocabulary ? ($this->VocabularyRestriction ? '1' : '0') : '0',
':id' => $this->id
);
$stmt = $connbas->prepare($sql);
$stmt->execute($params);
$dom_struct = $this->databox->get_dom_structure();
$xp_struct = $this->databox->get_xpath_structure();
$xp_struct = $this->databox->get_xpath_structure();
$nodes = $xp_struct->query(
'/record/description/*[@meta_id=' . $this->id . ']'
'/record/description/*[@meta_id=' . $this->id . ']'
);
if ($nodes->length == 0)
{
$meta = $dom_struct->createElement($this->name);
$meta = $dom_struct->createElement($this->name);
$nodes_parent = $xp_struct->query('/record/description');
$nodes_parent->item(0)->appendChild($meta);
}
@@ -377,8 +377,8 @@ class databox_field implements cache_cacheableInterface
$current_name = $meta->nodeName;
if ($this->name != $meta->nodeName)
{
$old_meta = $meta;
$meta = $dom_struct->createElement($this->name);
$old_meta = $meta;
$meta = $dom_struct->createElement($this->name);
$nodes_parent = $xp_struct->query('/record/description');
$nodes_parent->item(0)->replaceChild($meta, $old_meta);
}
@@ -427,7 +427,7 @@ class databox_field implements cache_cacheableInterface
$classname = 'metadata_description_nosource';
else
$classname = 'metadata_description_' . str_replace(
array('/rdf:RDF/rdf:Description/', ':', '-'), array('', '_', ''), $xpath
array('/rdf:RDF/rdf:Description/', ':', '-'), array('', '_', ''), $xpath
);
if (!class_exists($classname))
@@ -475,8 +475,8 @@ class databox_field implements cache_cacheableInterface
$stmt = $connbas->prepare($sql);
$stmt->execute(array(
':dces_element' => $DCES_element ? $DCES_element->get_label() : null
, ':id' => $this->id
':dces_element' => $DCES_element ? $DCES_element->get_label() : null
, ':id' => $this->id
));
$stmt->closeCursor();
$this->dces_element = $DCES_element;
@@ -667,7 +667,7 @@ class databox_field implements cache_cacheableInterface
}
catch (Exception $e)
{
}
return $this;
@@ -849,10 +849,10 @@ class databox_field implements cache_cacheableInterface
{
$sorter = 0;
$sql = 'SELECT (MAX(sorter) + 1) as sorter FROM metadatas_structure';
$sql = 'SELECT (MAX(sorter) + 1) as sorter FROM metadatas_structure';
$stmt = $databox->get_connection()->prepare($sql);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if ($row)
@@ -867,8 +867,8 @@ class databox_field implements cache_cacheableInterface
1, :sorter)";
$stmt = $databox->get_connection()->prepare($sql);
$stmt->execute(array(':name' => self::generateName($name), ':sorter' => $sorter));
$id = $databox->get_connection()->lastInsertId();
$stmt->execute(array(':name' => self::generateName($name), ':sorter' => $sorter));
$id = $databox->get_connection()->lastInsertId();
$stmt->closeCursor();
$databox->delete_data_from_cache(databox::CACHE_META_STRUCT);
@@ -876,7 +876,6 @@ class databox_field implements cache_cacheableInterface
return self::get_instance($databox, $id);
}
public static function generateName($name)
{
$unicode_processor = new unicode();

View File

@@ -65,7 +65,6 @@ class databox_subdefsStructure implements IteratorAggregate
);
if (!$sx_struct)
return $this;
$subdefgroup = $sx_struct->subdefs[0];
@@ -129,8 +128,9 @@ class databox_subdefsStructure implements IteratorAggregate
public function get_subdef($subdef_type, $subdef_name)
{
if (isset($this->AvSubdefs[$subdef_type]) && isset($this->AvSubdefs[$subdef_type][$subdef_name]))
{
return $this->AvSubdefs[$subdef_type][$subdef_name];
}
throw new Exception_Databox_SubdefNotFound();
}
@@ -146,9 +146,9 @@ class databox_subdefsStructure implements IteratorAggregate
$dom_struct = $this->databox->get_dom_structure();
$dom_xp = $this->databox->get_xpath_structure();
$nodes = $dom_xp->query(
'//record/subdefs/'
. 'subdefgroup[@name="' . $group . '"]/'
. 'subdef[@name="' . $name . '"]'
'//record/subdefs/'
. 'subdefgroup[@name="' . $group . '"]/'
. 'subdef[@name="' . $name . '"]'
);
if ($nodes->length > 0)
@@ -173,7 +173,7 @@ class databox_subdefsStructure implements IteratorAggregate
* @param string $class
* @return databox_subdefsStructure
*/
public function add_subdef($group, $name, $class)
public function add_subdef($groupname, $name, $class)
{
$dom_struct = $this->databox->get_dom_structure();
@@ -182,13 +182,13 @@ class databox_subdefsStructure implements IteratorAggregate
$subdef->setAttribute('name', $name);
$dom_xp = $this->databox->get_xpath_structure();
$query = '//record/subdefs/subdefgroup[@name="' . $group . '"]';
$query = '//record/subdefs/subdefgroup[@name="' . $groupname . '"]';
$groups = $dom_xp->query($query);
if ($groups->length == 0)
{
$group = $dom_struct->createElement('subdefgroup');
$group->setAttribute('name', $group);
$group->setAttribute('name', $groupname);
$dom_xp->query('/record/subdefs')->item(0)->appendChild($group);
}
else
@@ -233,7 +233,7 @@ class databox_subdefsStructure implements IteratorAggregate
$dom_xp = $this->databox->get_xpath_structure();
$nodes = $dom_xp->query('//record/subdefs/'
. 'subdefgroup[@name="' . $group . '"]');
. 'subdefgroup[@name="' . $group . '"]');
if ($nodes->length > 0)
{
$dom_group = $nodes->item(0);
@@ -255,9 +255,9 @@ class databox_subdefsStructure implements IteratorAggregate
}
$nodes = $dom_xp->query(
'//record/subdefs/'
. 'subdefgroup[@name="' . $group . '"]/'
. 'subdef[@name="' . $name . '"]'
'//record/subdefs/'
. 'subdefgroup[@name="' . $group . '"]/'
. 'subdef[@name="' . $name . '"]'
);
if ($nodes->length > 0)