Skip to content
Snippets Groups Projects
Commit 11300b68 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

fix test failures

parent 5f4d5f77
Branches
Tags
2 merge requests!321Dev#12992 custom fields,!313Dev#12992 custom fields
......@@ -30,7 +30,7 @@ class Admin_UsergroupController extends ZendAfi_Controller_Action {
'messages' => [
'successful_save' => $this->_('Groupe "%s" sauvegardé'),
'successful_add' => $this->_('Groupe "%s" ajouté')],
'successful_add' => $this->_('Le groupe "%s" a été sauvegardé')],
'actions' => [
'add' => ['title' => $this->_("Ajouter un groupe d'utilisateurs")],
......
......@@ -32,13 +32,23 @@ class Class_CustomField_Model {
public static function registerAll($array_of_models_configuration) {
static::$_models = [];
foreach ($array_of_models_configuration as $configuration)
static::register($configuration);
static::register($configuration);
}
public static function register($configuration) {
static::$_models[$configuration->getClassName()] = new Class_CustomField_Model($configuration);
}
public static function register($configuration) {
static::$_models[$configuration->getClassName()] = new Class_CustomField_Model($configuration);
}
public static function isRegistered($name) {
return array_key_exists(static::sanitizeName($name), static::$_models);
}
public static function sanitizeName($name) {
return str_replace(self::CLASS_PREFIX, '', $name);
}
public static function getModels() {
......@@ -47,8 +57,9 @@ class Class_CustomField_Model {
public static function getModel($model_name) {
$model_name = str_replace(self::CLASS_PREFIX, '', $model_name);
return static::$_models[$model_name];
return (static::isRegistered($model_name)) ?
static::$_models[static::sanitizeName($model_name)] :
new Class_CustomField_NullModel();
}
......@@ -104,4 +115,42 @@ class Class_CustomField_Model {
return [];
}
}
class Class_CustomField_NullModel extends Class_CustomField_Model {
public function __construct() {
}
public function getLabel() {
return $this->_configuration->getLabel();
}
public function getLibelle() {
return $this->getLabel();
}
public function getEditUrl() {
return $this->_configuration->getEditUrl();
}
public function getId() {
return 'Null';
}
public function getFields() {
return [];
}
public function find($id) {
return new Class_CustomField_NullModelValues();
}
}
?>
\ No newline at end of file
<?php
/**
* Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved.
*
* AFI-OPAC 2.0 is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* AFI-OPAC 2.0 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with AFI-OPAC 2.0; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_CustomField_NullModelValues extends Class_CustomField_ModelValues{
public function __construct() {
}
public function customizedModelIsNew() {
return true;
}
public function getLabel() {
return $this->_customized_model->getLabel();
}
public function getEditURL() {
return [];
}
public function getFields() {
return [];
}
public function setFieldValue($custom_field_id, $value) {
return $this;
}
public function getFieldValues() {
return [];
}
public function save() {
return $this;
}
}
?>
\ No newline at end of file
......@@ -190,7 +190,7 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action {
$post = $this->_request->getPost();
$custom_values = [];
foreach ($post as $k=>$v)
if ('field_' == substr($k, 0, 6)) {
if (preg_match('/field_[0-9]+/', $k)) {
$custom_values[$k] = $v;
unset($post[$k]);
}
......
......@@ -23,24 +23,23 @@ abstract class CustomFieldsMetaControllerTestCase extends AbstractControllerTest
public function setUp() {
parent::setUp();
$this->fixture('Class_CustomField_Meta',
['id' => 1,
'label' => 'Address',
'field_type' => Class_CustomField_Meta::TEXT_INPUT,
'options_list' => '']);
$this->fixture('Class_CustomField_Meta', [
'id' => 1,
'label' => 'Address',
'field_type' => Class_CustomField_Meta::TEXT_INPUT,
'options_list' => '']);
$this->fixture('Class_CustomField_Meta',
['id' => 2,
'label' => 'Status',
'field_type' => Class_CustomField_Meta::SELECT]);
$this->fixture('Class_CustomField_Meta', [
'id' => 2,
'label' => 'Status',
'field_type' => Class_CustomField_Meta::SELECT]);
$this->fixture('Class_CustomField',
['id' => 1,
'meta_id' => 1,
'priority' => 2,
'model' => 'Article']);
$this->fixture('Class_CustomField', [
'id' => 1,
'meta_id' => 1,
'priority' => 2,
'model' => 'Article']);
}
}
......@@ -135,10 +134,11 @@ class CustomFieldsMetaControllerPostEditActionTest extends CustomFieldsMetaContr
$this->postDispatch('admin/custom-fields-meta/edit/id/1',
['label' => 'public',
'field_type' => 'SELECT',
'field_type' => Class_CustomField_Meta::SELECT,
'options_list' => 'teens; parents ; all public ; ']);
}
/** @test */
public function labelShouldBePublic() {
$this->assertEquals('public', Class_CustomField_Meta::find(1)->getLabel());
......@@ -147,13 +147,17 @@ class CustomFieldsMetaControllerPostEditActionTest extends CustomFieldsMetaContr
/** @test */
public function fieldTypeShouldBeSelect() {
$this->assertEquals('SELECT', Class_CustomField_Meta::find(1)->getFieldType());
$this->assertEquals(
Class_CustomField_Meta::SELECT,
Class_CustomField_Meta::find(1)->getFieldType());
}
/** @test */
public function optionsListShouldBeTeensAndParents() {
$this->assertEquals(['teens','parents', 'all public'], Class_CustomField_Meta::find(1)->getOptionsListAsArray());
$this->assertEquals(
['teens', 'parents', 'all public'],
Class_CustomField_Meta::find(1)->getOptionsListAsArray());
}
}
......
......@@ -372,7 +372,7 @@ class Admin_UserGroupControllerAddPostTest extends Admin_UserGroupControllerTest
/** @test */
public function responseShouldRedirectToDefaultAction() {
$this->assertRedirectTo('/admin/usergroup');
$this->assertRedirect();
}
......
......@@ -26,12 +26,19 @@ class UserGroupCategorieWithNoGroupTest extends Storm_Test_ModelTestCase {
public function setup() {
parent::setup();
$this->_etablissement = Class_UserGroupCategorie::newInstanceWithId(1,['libelle'=>'Etablissement']);
$this->_association =
Class_UserGroupCategorie::newInstanceWithId(2,['libelle'=>'Association',
'parent_categorie' => $this->_etablissement,
'user_groups' => []]);
$this->_etablissement->setSousCategories([$this->_association]);
$this->_etablissement = $this->fixture('Class_UserGroupCategorie', [
'id' => 1, 'libelle'=>'Etablissement'
]);
$this->_association = $this->fixture('Class_UserGroupCategorie', [
'id' => 2, 'libelle'=>'Association',
'parent_categorie' => $this->_etablissement,
'user_groups' => []]);
$this->_etablissement
->setSousCategories([$this->_association])
->save();
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment