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

@@ -36,153 +36,152 @@ class Description implements ControllerProviderInterface
$controllers->post('/{sbas_id}/', function(Application $app, $sbas_id)
{
$Core = $app['Core'];
$user = $Core->getAuthenticatedUser();
$request = $app['request'];
if (!$user->ACL()->has_right_on_sbas($sbas_id, 'bas_modify_struct'))
{
throw new \Exception_Forbidden('You are not allowed to access this zone');
}
$databox = \databox::get_instance((int) $sbas_id);
$fields = $databox->get_meta_structure();
$available_fields = \databox::get_available_metadatas();
$available_dc_fields = $databox->get_available_dcfields();
$databox->get_connection()->beginTransaction();
$error = false;
try
{
if (is_array($request->get('field_ids')))
{
foreach ($request->get('field_ids') as $id)
{
$Core = $app['Core'];
$user = $Core->getAuthenticatedUser();
$request = $app['request'];
if (!$user->ACL()->has_right_on_sbas($sbas_id, 'bas_modify_struct'))
{
throw new \Exception_Forbidden('You are not allowed to access this zone');
}
$databox = \databox::get_instance((int) $sbas_id);
$fields = $databox->get_meta_structure();
$available_fields = \databox::get_available_metadatas();
$available_dc_fields = $databox->get_available_dcfields();
$databox->get_connection()->beginTransaction();
$error = false;
try
{
$field = \databox_field::get_instance($databox, $id);
$field->set_name($request->get('name_' . $id));
$field->set_thumbtitle($request->get('thumbtitle_' . $id));
$field->set_source($request->get('src_' . $id));
$field->set_multi($request->get('multi_' . $id));
$field->set_indexable($request->get('indexable_' . $id));
$field->set_required($request->get('required_' . $id));
$field->set_separator($request->get('separator_' . $id));
$field->set_readonly($request->get('readonly_' . $id));
$field->set_type($request->get('type_' . $id));
$field->set_tbranch($request->get('tbranch_' . $id));
$field->set_report($request->get('report_' . $id));
$field->setVocabularyControl(null);
$field->setVocabularyRestricted(false);
try
{
$vocabulary = \Alchemy\Phrasea\Vocabulary\Controller::get($request->get('vocabulary_' . $id));
$field->setVocabularyControl($vocabulary);
$field->setVocabularyRestricted($request->get('vocabularyrestricted_' . $id));
}
catch (\Exception $e)
if (is_array($request->get('field_ids')))
{
foreach ($request->get('field_ids') as $id)
{
try
{
$field = \databox_field::get_instance($databox, $id);
$field->set_name($request->get('name_' . $id));
$field->set_thumbtitle($request->get('thumbtitle_' . $id));
$field->set_source($request->get('src_' . $id));
$field->set_multi($request->get('multi_' . $id));
$field->set_indexable($request->get('indexable_' . $id));
$field->set_required($request->get('required_' . $id));
$field->set_separator($request->get('separator_' . $id));
$field->set_readonly($request->get('readonly_' . $id));
$field->set_type($request->get('type_' . $id));
$field->set_tbranch($request->get('tbranch_' . $id));
$field->set_report($request->get('report_' . $id));
$field->setVocabularyControl(null);
$field->setVocabularyRestricted(false);
try
{
$vocabulary = \Alchemy\Phrasea\Vocabulary\Controller::get($request->get('vocabulary_' . $id));
$field->setVocabularyControl($vocabulary);
$field->setVocabularyRestricted($request->get('vocabularyrestricted_' . $id));
}
catch (\Exception $e)
{
}
$dces_element = null;
$class = 'databox_Field_DCES_' . $request->get('dces_' . $id);
if (class_exists($class))
$dces_element = new $class();
$field->set_dces_element($dces_element);
$field->save();
if ($request->get('regname') == $field->get_id())
{
$field->set_regname();
}
if ($request->get('regdate') == $field->get_id())
{
$field->set_regdate();
}
if ($request->get('regdesc') == $field->get_id())
{
$field->set_regdesc();
}
}
catch (\Exception $e)
{
continue;
}
}
}
$dces_element = null;
$class = 'databox_Field_DCES_' . $request->get('dces_' . $id);
if (class_exists($class))
$dces_element = new $class();
$field->set_dces_element($dces_element);
$field->save();
if ($request->get('regname') == $field->get_id())
if ($request->get('newfield'))
{
$field->set_regname();
$field = \databox_field::create($databox, $request->get('newfield'));
}
if ($request->get('regdate') == $field->get_id())
{
$field->set_regdate();
}
if ($request->get('regdesc') == $field->get_id())
{
$field->set_regdesc();
}
}
catch (Exception $e)
{
continue;
}
}
}
if ($request->get('newfield'))
{
\databox_field::create($databox, $request->get('newfield'));
}
if (is_array($request->get('todelete_ids')))
{
foreach ($request->get('todelete_ids') as $id)
{
try
{
$field = \databox_field::get_instance($databox, $id);
$field->delete();
if (is_array($request->get('todelete_ids')))
{
foreach ($request->get('todelete_ids') as $id)
{
try
{
$field = \databox_field::get_instance($databox, $id);
$field->delete();
}
catch (\Exception $e)
{
}
}
}
}
catch (\Exception $e)
{
$error = true;
}
}
}
}
catch (\Exception $e)
{
$error = true;
}
if ($error)
$databox->get_connection()->rollBack();
else
$databox->get_connection()->commit();
if ($error)
$databox->get_connection()->rollBack();
else
$databox->get_connection()->commit();
return new RedirectResponse('/admin/databox/' . $sbas_id . '/description/');
});
return new RedirectResponse('/admin/databox/' . $sbas_id . '/description/');
})->assert('sbas_id', '\d+');
$controllers->get('/{sbas_id}/', function(Application $app, $sbas_id)
{
{
$Core = $app['Core'];
$user = $Core->getAuthenticatedUser();
$Core = $app['Core'];
$user = $Core->getAuthenticatedUser();
$request = $app['request'];
$request = $app['request'];
if (!$user->ACL()->has_right_on_sbas($sbas_id, 'bas_modify_struct'))
{
throw new \Exception_Forbidden('You are not allowed to access this zone');
}
if (!$user->ACL()->has_right_on_sbas($sbas_id, 'bas_modify_struct'))
{
throw new \Exception_Forbidden('You are not allowed to access this zone');
}
$databox = \databox::get_instance((int) $sbas_id);
$fields = $databox->get_meta_structure();
$available_fields = \databox::get_available_metadatas();
$available_dc_fields = $databox->get_available_dcfields();
$databox = \databox::get_instance((int) $sbas_id);
$fields = $databox->get_meta_structure();
$available_fields = \databox::get_available_metadatas();
$available_dc_fields = $databox->get_available_dcfields();
$params = array(
'databox' => $databox,
'fields' => $fields,
'available_fields' => $available_fields,
'available_dc_fields' => $available_dc_fields,
'vocabularies' => \Alchemy\Phrasea\Vocabulary\Controller::getAvailable(),
);
$params = array(
'databox' => $databox,
'fields' => $fields,
'available_fields' => $available_fields,
'available_dc_fields' => $available_dc_fields,
'vocabularies' => \Alchemy\Phrasea\Vocabulary\Controller::getAvailable(),
);
return new Response($Core->getTwig()->render('admin/databox/doc_structure.twig', $params));
});
return new Response($Core->getTwig()->render('admin/databox/doc_structure.twig', $params));
})->assert('sbas_id', '\d+');
return $controllers;
}

View File

@@ -40,42 +40,42 @@ class Fields implements ControllerProviderInterface
$multi = ($request->get('multi') === 'true');
$metadata = \databox_field::load_class_from_xpath($request->get('source'));
$metadata = \databox_field::load_class_from_xpath($request->get('source'));
$datas = array(
'result' => ($multi === $metadata->is_multi())
, 'is_multi' => $metadata->is_multi()
);
$datas = array(
'result' => ($multi === $metadata->is_multi())
, 'is_multi' => $metadata->is_multi()
);
$Serializer = $app['Core']['Serializer'];
$Serializer = $app['Core']['Serializer'];
return new Response(
$Serializer->serialize($datas, 'json')
, 200
, array('Content-Type' => 'application/json')
);
});
return new Response(
$Serializer->serialize($datas, 'json')
, 200
, array('Content-Type' => 'application/json')
);
});
$controllers->get('/checkreadonly/', function() use ($app, $appbox)
{
$request = $app['request'];
$readonly = ($request->get('readonly') === 'true');
{
$request = $app['request'];
$readonly = ($request->get('readonly') === 'true');
$metadata = \databox_field::load_class_from_xpath($request->get('source'));
$metadata = \databox_field::load_class_from_xpath($request->get('source'));
$datas = array(
'result' => ($readonly === $metadata->is_readonly())
, 'is_readonly' => $metadata->is_readonly()
);
$datas = array(
'result' => ($readonly === $metadata->is_readonly())
, 'is_readonly' => $metadata->is_readonly()
);
$Serializer = $app['Core']['Serializer'];
$Serializer = $app['Core']['Serializer'];
return new Response(
$Serializer->serialize($datas, 'json')
, 200
, array('Content-Type' => 'application/json')
);
});
return new Response(
$Serializer->serialize($datas, 'json')
, 200
, array('Content-Type' => 'application/json')
);
});
return $controllers;
}

View File

@@ -78,7 +78,7 @@ class Publications implements ControllerProviderInterface
, 'error' => $app['request']->get('error')
)
);
});
})->assert('id', '\d+');
$controllers->post('/feed/{id}/update/', function($id) use ($app, $appbox)
@@ -108,7 +108,7 @@ class Publications implements ControllerProviderInterface
$feed->set_public($request->get('public'));
return $app->redirect('/admin/publications/list/');
});
})->assert('id', '\d+');
$controllers->post('/feed/{id}/iconupload/', function($id) use ($app, $appbox)
@@ -150,7 +150,7 @@ class Publications implements ControllerProviderInterface
unlink($file->getPathname());
return new Response('FILEHREF:' . $feed->get_icon_url() . '?' . mt_rand(100000, 999999));
});
})->assert('id', '\d+');
$controllers->post('/feed/{id}/addpublisher/', function($id) use ($app, $appbox)
{
@@ -168,7 +168,7 @@ class Publications implements ControllerProviderInterface
}
return $app->redirect('/admin/publications/feed/' . $id . '/?err=' . $error);
});
})->assert('id', '\d+');
$controllers->post('/feed/{id}/removepublisher/', function($id) use ($app, $appbox)
@@ -189,7 +189,7 @@ class Publications implements ControllerProviderInterface
}
return $app->redirect('/admin/publications/feed/' . $id . '/?err=' . $error);
});
})->assert('id', '\d+');
$controllers->post('/feed/{id}/delete/', function($id) use ($app, $appbox)
{

View File

@@ -39,73 +39,73 @@ class Root implements ControllerProviderInterface
$controllers = new ControllerCollection();
$controllers->get('/', function(Application $app)
{
{
$Core = $app['Core'];
$appbox = \appbox::get_instance();
$user = $Core->getAuthenticatedUser();
$Core = $app['Core'];
$appbox = \appbox::get_instance();
$user = $Core->getAuthenticatedUser();
\User_Adapter::updateClientInfos(3);
\User_Adapter::updateClientInfos(3);
$section = $app['request']->get('section', false);
$section = $app['request']->get('section', false);
$available = array(
'connected'
, 'registrations'
, 'taskmanager'
, 'base'
, 'bases'
, 'collection'
, 'user'
, 'users'
);
$available = array(
'connected'
, 'registrations'
, 'taskmanager'
, 'base'
, 'bases'
, 'collection'
, 'user'
, 'users'
);
$feature = 'connected';
$featured = false;
$position = explode(':', $section);
if (count($position) > 0)
{
if (in_array($position[0], $available))
{
$feature = $position[0];
if (isset($position[1]))
$featured = $position[1];
}
}
$feature = 'connected';
$featured = false;
$position = explode(':', $section);
if (count($position) > 0)
{
if (in_array($position[0], $available))
{
$feature = $position[0];
if (isset($position[1]))
$featured = $position[1];
}
}
$databoxes = $off_databoxes = array();
foreach ($appbox->get_databoxes() as $databox)
{
try
{
if (!$user->ACL()->has_access_to_sbas($databox->get_sbas_id()))
continue;
$databoxes = $off_databoxes = array();
foreach ($appbox->get_databoxes() as $databox)
{
try
{
if (!$user->ACL()->has_access_to_sbas($databox->get_sbas_id()))
continue;
$connbas = $databox->get_connection();
}
catch (\Exception $e)
{
$off_databoxes[] = $databox;
continue;
}
$databoxes[] = $databox;
}
$connbas = $databox->get_connection();
}
catch (\Exception $e)
{
$off_databoxes[] = $databox;
continue;
}
$databoxes[] = $databox;
}
$twig = $Core->getTwig();
$twig = $Core->getTwig();
return new Response($twig->render('admin/index.html.twig', array(
'module' => 'admin'
, 'events' => \eventsmanager_broker::getInstance($appbox, $Core)
, 'module_name' => 'Admin'
, 'feature' => $feature
, 'featured' => $featured
, 'databoxes' => $databoxes
, 'off_databoxes' => $off_databoxes
, 'tree' => \module_admin::getTree($section)
))
);
});
return new Response($twig->render('admin/index.html.twig', array(
'module' => 'admin'
, 'events' => \eventsmanager_broker::getInstance($appbox, $Core)
, 'module_name' => 'Admin'
, 'feature' => $feature
, 'featured' => $featured
, 'databoxes' => $databoxes
, 'off_databoxes' => $off_databoxes
, 'tree' => \module_admin::getTree($section)
))
);
});
return $controllers;
}

View File

@@ -15,6 +15,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
@@ -34,104 +35,103 @@ class Subdefs implements ControllerProviderInterface
$controllers = new ControllerCollection();
$controllers->get('/{sbas_id}/', function(Application $app, $sbas_id)
{
$databox = \databox::get_instance((int) $sbas_id);
return new response($app['Core']->getTwig()->render(
'admin/subdefs.twig', array(
'databox' => $databox,
'subdefs' => $databox->get_subdef_structure()
)
)
);
});
$controllers->post('/{sbas_id}/', function(Application $app, $sbas_id)
{
$delete_subdef = $request->get('delete_subdef');
$toadd_subdef = $request->get('add_subdef');
$Parmsubdefs = $request->get('subdefs');
$databox = \databox::get_instance((int) $sbas_id);
$add_subdef = array('class' => null, 'name' => null, 'group' => null);
foreach ($add_subdef as $k => $v)
{
if (!isset($toadd_subdef[$k]) || trim($toadd_subdef[$k]) === '')
unset($add_subdef[$k]);
else
$add_subdef[$k] = $toadd_subdef[$k];
}
if ($delete_subdef)
{
$delete_subef = explode('_', $delete_subdef);
$group = $delete_subef[0];
$name = $delete_subef[1];
$subdefs = $databox->get_subdef_structure();
$subdefs->delete_subdef($group, $name);
}
elseif (count($add_subdef) === 3)
{
$subdefs = $databox->get_subdef_structure();
$group = $add_subdef['group'];
$name = $add_subdef['name'];
$class = $add_subdef['class'];
$subdefs->add_subdef($group, $name, $class);
}
else
{
$subdefs = $databox->get_subdef_structure();
$options = array();
foreach ($Parmsubdefs as $post_sub)
{
$post_sub_ex = explode('_', $post_sub);
$group = $post_sub_ex[0];
$name = $post_sub_ex[1];
$parm_loc = $request->get_parms($post_sub . '_class', $post_sub . '_downloadable');
$class = $parm_loc[$post_sub . '_class'];
$downloadable = $parm_loc[$post_sub . '_downloadable'];
$defaults = array('path', 'baseurl', 'meta', 'mediatype');
foreach ($defaults as $def)
{
$parm_loc = $request->get_parms($post_sub . '_' . $def);
$databox = \databox::get_instance((int) $sbas_id);
if ($def == 'meta' && !$parm_loc[$post_sub . '_' . $def])
return new response($app['Core']->getTwig()->render(
'admin/subdefs.twig', array(
'databox' => $databox,
'subdefs' => $databox->get_subdef_structure()
)
)
);
})->assert('sbas_id', '\d+');
$controllers->post('/{sbas_id}/', function(Application $app, Request $request, $sbas_id)
{
$delete_subdef = $request->get('delete_subdef');
$toadd_subdef = $request->get('add_subdef');
$Parmsubdefs = $request->get('subdefs', array());
$databox = \databox::get_instance((int) $sbas_id);
$add_subdef = array('class' => null, 'name' => null, 'group' => null);
foreach ($add_subdef as $k => $v)
{
$parm_loc[$post_sub . '_' . $def] = "no";
if (!isset($toadd_subdef[$k]) || trim($toadd_subdef[$k]) === '')
unset($add_subdef[$k]);
else
$add_subdef[$k] = $toadd_subdef[$k];
}
$options[$def] = $parm_loc[$post_sub . '_' . $def];
}
$parm_loc = $request->get_parms($post_sub . '_mediatype');
$mediatype = $parm_loc[$post_sub . '_mediatype'];
$parm_loc = $request->get_parms($post_sub . '_' . $mediatype);
if (isset($parm_loc[$post_sub . '_' . $mediatype]))
{
foreach ($parm_loc[$post_sub . '_' . $mediatype] as $option => $value)
if ($delete_subdef)
{
if ($option == 'resolution' && $mediatype == 'image')
$option = 'dpi';
$options[$option] = $value;
}
}
$subdefs->set_subdef($group, $name, $class, $downloadable, $options);
}
}
$delete_subef = explode('_', $delete_subdef);
$group = $delete_subef[0];
$name = $delete_subef[1];
return \phrasea::redirect('/admin/subdefs/' . $databox->get_sbas_id() . '/');
});
$subdefs = $databox->get_subdef_structure();
$subdefs->delete_subdef($group, $name);
}
elseif (count($add_subdef) === 3)
{
$subdefs = $databox->get_subdef_structure();
$group = $add_subdef['group'];
$name = $add_subdef['name'];
$class = $add_subdef['class'];
$subdefs->add_subdef($group, $name, $class);
}
else
{
$subdefs = $databox->get_subdef_structure();
$options = array();
foreach ($Parmsubdefs as $post_sub)
{
$post_sub_ex = explode('_', $post_sub);
$group = $post_sub_ex[0];
$name = $post_sub_ex[1];
$class = $request->get($post_sub . '_class');
$downloadable = $request->get($post_sub . '_downloadable');
$defaults = array('path', 'baseurl', 'meta', 'mediatype');
foreach ($defaults as $def)
{
$parm_loc = $request->get($post_sub . '_' . $def);
if ($def == 'meta' && !$parm_loc)
{
$parm_loc = "no";
}
$options[$def] = $parm_loc;
}
$mediatype = $request->get($post_sub . '_mediatype');
$media = $request->get($post_sub . '_' . $mediatype, array());
foreach ($media as $option => $value)
{
if ($option == 'resolution' && $mediatype == 'image')
{
$option = 'dpi';
}
$options[$option] = $value;
}
$subdefs->set_subdef($group, $name, $class, $downloadable, $options);
}
}
return new RedirectResponse('/admin/subdefs/' . $databox->get_sbas_id() . '/');
})->assert('sbas_id', '\d+');
return $controllers;
}
}

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)

View File

@@ -42,22 +42,247 @@ class DescriptionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/**
* Default route test
*/
public function testRouteSlash()
public function testRouteDescription()
{
$this->markTestIncomplete();
$appbox = appbox::get_instance();
$databox = array_shift($appbox->get_databoxes());
$fields = $databox->get_meta_structure();
$fieldIds = array();
foreach($fields as $field)
{
$fieldIds[] = $field->get_id();
}
$this->client->request("POST", "/description/" . $databox->get_sbas_id());
$name = "testtest" . uniqid();
$field = \databox_field::create($databox, $name);
$id = $field->get_id();
$this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array(
'field_ids' => array($id)
, 'name_' . $id => $name
, 'multi_' . $id => 1
, 'indexable_' . $id => 1
, 'src_' . $id => '/rdf:RDF/rdf:Description/IPTC:SupplementalCategories'
, 'required_' . $id => 0
, 'readonly_' . $id => 0
, 'type_' . $id => 'string'
, 'vocabulary_' . $id => 'User'
, 'regname' => $id
, 'regdate' => $id
, 'regdesc' => $id
));
$this->assertTrue($this->client->getResponse()->isRedirect());
$field->delete();
}
public function testPostDelete()
{
$appbox = appbox::get_instance();
$databox = array_shift($appbox->get_databoxes());
$name = "test" . uniqid();
$field = \databox_field::create($databox, $name);
$id = $field->get_id();
$this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array(
'todelete_ids' => array($id)
));
$this->assertTrue($this->client->getResponse()->isRedirect());
try
{
$field = \databox_field::get_instance($databox, $id);
$field->delete();
$this->fail("should raise an exception");
}
catch (\Exception $e)
{
}
}
public function testPostCreate()
{
$appbox = appbox::get_instance();
$databox = array_shift($appbox->get_databoxes());
$name = 'test' . uniqid();
$this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array(
'newfield' => $name
));
$this->assertTrue($this->client->getResponse()->isRedirect());
$fields = $databox->get_meta_structure();
$find = false;
foreach ($fields as $field)
{
if ($field->get_name() === databox_field::generateName($name))
{
$field->delete();
$find = true;
}
}
if (!$find)
{
$this->fail("should have create a new field");
}
}
public function testPostDescriptionException()
{
$appbox = appbox::get_instance();
$databox = array_shift($appbox->get_databoxes());
$this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array(
'todelete_ids' => array('unknow_id')
));
$this->assertTrue($this->client->getResponse()->isRedirect());
$name = "test" . uniqid();
$field = \databox_field::create($databox, $name);
$id = $field->get_id();
$this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array(
'field_ids' => array($id)
, 'name_' . $id => $name
, 'multi_' . $id => 1
, 'indexable_' . $id => 1
, 'src_' . $id => '/rdf:RDF/rdf:Description/IPTC:SupplementalCategories'
, 'required_' . $id => 0
, 'readonly_' . $id => 0
, 'type_' . $id => 'string'
, 'vocabulary_' . $id => 'Unknow_Vocabulary'
, 'regname' => $id
, 'regdate' => $id
, 'regdesc' => $id
));
$this->assertTrue($this->client->getResponse()->isRedirect());
$field->delete();
$name = "test" . uniqid();
$field = \databox_field::create($databox, $name);
$id = $field->get_id();
$this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array(
'field_ids' => array($id)
, 'multi_' . $id => 1
, 'indexable_' . $id => 1
, 'src_' . $id => '/rdf:RDF/rdf:Description/IPTC:SupplementalCategories'
, 'required_' . $id => 0
, 'readonly_' . $id => 0
, 'type_' . $id => 'string'
, 'vocabulary_' . $id => 'Unknow_Vocabulary'
, 'regname' => $id
, 'regdate' => $id
, 'regdesc' => $id
));
$this->assertTrue($this->client->getResponse()->isRedirect());
$field->delete();
$name = "test" . uniqid();
$field = \databox_field::create($databox, $name);
$field->set_multi(false);
$field->set_indexable(false);
$field->set_required(true);
$field->set_readonly(true);
$id = $field->get_id();
$this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array(
'field_ids' => array($id)
, 'name_' . $id => $name
, 'multi_' . $id => 1
, 'indexable_' . $id => 1
, 'src_' . $id => 'unknow_Source'
, 'required_' . $id => 0
, 'readonly_' . $id => 0
, 'type_' . $id => 'string'
, 'vocabulary_' . $id => 'Unknow_Vocabulary'
, 'regname' => $id
, 'regdate' => $id
, 'regdesc' => $id
));
$this->assertTrue($this->client->getResponse()->isRedirect());
$this->assertTrue($field->is_readonly());
$this->assertTrue($field->is_required());
$this->assertFalse($field->is_multi());
$this->assertFalse($field->is_indexable());
$field->delete();
$name = "test" . uniqid();
$field = \databox_field::create($databox, $name);
$id = $field->get_id();
$this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array(
'field_ids' => array('unknow_id')
, 'name_' . $id => $name
, 'multi_' . $id => 1
, 'indexable_' . $id => 1
, 'src_' . $id => '/rdf:RDF/rdf:Description/IPTC:SupplementalCategories'
, 'required_' . $id => 0
, 'readonly_' . $id => 0
, 'type_' . $id => 'string'
, 'vocabulary_' . $id => 'Unknow_Vocabulary'
, 'regname' => $id
, 'regdate' => $id
, 'regdesc' => $id
));
$this->assertTrue($this->client->getResponse()->isRedirect());
$field->delete();
}
public function testPostDescriptionRights()
{
$appbox = appbox::get_instance();
$session = $appbox->get_session();
$auth = new Session_Authentication_None(self::$user_alt1);
$session->authenticate($auth);
$databox = array_shift($appbox->get_databoxes());
$name = "test" . uniqid();
$field = \databox_field::create($databox, $name);
$id = $field->get_id();
$this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array(
'field_ids' => array($id)
, 'name_' . $id => $name
, 'multi_' . $id => 1
, 'indexable_' . $id => 1
, 'src_' . $id => '/rdf:RDF/rdf:Description/IPTC:SupplementalCategories'
, 'required_' . $id => 0
, 'readonly_' . $id => 0
, 'type_' . $id => 'string'
, 'vocabulary_' . $id => 'User'
, 'regname' => $id
, 'regdate' => $id
, 'regdesc' => $id
));
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals("You are not allowed to access this zone", $this->client->getResponse()->getContent());
$field->delete();
}
public function testGetDescriptionException()
{
$appbox = appbox::get_instance();
$session = $appbox->get_session();
$auth = new Session_Authentication_None(self::$user_alt1);
$session->authenticate($auth);
$databox = array_shift($appbox->get_databoxes());
$this->client->request("GET", "/description/" . $databox->get_sbas_id() . "/");
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals("You are not allowed to access this zone", $this->client->getResponse()->getContent());
}
public function testGetDescription()
{
$appbox = appbox::get_instance();
$databox = array_shift($appbox->get_databoxes());
$this->client->request("GET", "/description/" . $databox->get_sbas_id() . "/");
$this->assertTrue($this->client->getResponse()->isOk());
}
}

View File

@@ -9,11 +9,11 @@ require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.
class ControllerSubdefsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
/**
* As controllers use WebTestCase, it requires a client
*/
protected $client;
/**
* If the controller tests require some records, specify it her
*
@@ -42,11 +42,77 @@ class ControllerSubdefsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/**
* Default route test
*/
public function testRouteSlash()
public function testRouteGetSubdef()
{
$this->markTestIncomplete(
'This test has not been implemented yet.'
$appbox = appbox::get_instance();
$databox = array_shift($appbox->get_databoxes());
$this->client->request("GET", "/subdefs/" . $databox->get_sbas_id() . "/");
$this->assertTrue($this->client->getResponse()->isOk());
}
public function testPostRouteAddSubdef()
{
$appbox = appbox::get_instance();
$databox = array_shift($appbox->get_databoxes());
$this->client->request("POST", "/subdefs/" . $databox->get_sbas_id() . "/", array('add_subdef' => array(
'class' => 'a_class',
'name' => 'a_name',
'group' => 'image'
)));
$this->assertTrue($this->client->getResponse()->isRedirect());
$subdefs = $databox->get_subdef_structure();
$subdefs->get_subdef("image", "a_name");
$subdefs->delete_subdef('image', 'a_name');
}
public function testPostRouteDeleteSubdef()
{
$appbox = appbox::get_instance();
$databox = array_shift($appbox->get_databoxes());
$subdefs = $databox->get_subdef_structure();
$subdefs->add_subdef("image", "name", "class");
$this->client->request("POST", "/subdefs/" . $databox->get_sbas_id() . "/", array('delete_subdef' => 'group_name'));
$this->assertTrue($this->client->getResponse()->isRedirect());
try
{
$subdefs->get_subdef("image", "name");
$this->fail("should raise an exception");
}
catch (\Exception $e)
{
}
}
public function testPostRouteAddSubdefWithNoParams()
{
$appbox = appbox::get_instance();
$databox = array_shift($appbox->get_databoxes());
$subdefs = $databox->get_subdef_structure();
$subdefs->add_subdef("image", "name", "class");
$this->client->request("POST", "/subdefs/" . $databox->get_sbas_id() . "/", array('subdefs' => array(
'image_name'
)
, 'image_name_class' => 'class'
, 'image_name_downloadable' => 0
, 'image_name_mediatype' => 'image'
, 'image_name_image' => array(
'size' => 400
, 'resolution' => 83
, 'strip' => 0
, 'quality' => 90
))
);
$this->assertTrue($this->client->getResponse()->isRedirect());
$subdef = $subdefs->get_subdef("image", "name");
/* @var $subdef \databox_subdefAbstract */
$this->assertFalse($subdef->is_downloadable());
$options = $subdef->get_options();
$this->assertEquals(400, $options["size"]);
$this->assertEquals(83, $options["resolution"]);
$this->assertEquals(90, $options["quality"]);
$this->assertFalse($options["strip"]);
$subdefs->delete_subdef("image", "name");
}
}