diff --git a/application/modules/admin/controllers/CustomFieldsController.php b/application/modules/admin/controllers/CustomFieldsController.php index 1b27e736cba5324c74f95444d370319a4c4beb2e..d57034d382d1ea6c6e3edb116009ab8af6c19a17 100644 --- a/application/modules/admin/controllers/CustomFieldsController.php +++ b/application/modules/admin/controllers/CustomFieldsController.php @@ -30,8 +30,8 @@ 'name' => 'custom_fields', 'order' => 'id'], - 'messages' => ['successful_save' => $this->_('Champ personnalisé %s sauvegardé'), - 'successful_add' => $this->_('Champ personnalisé %s ajouté'),], + 'messages' => ['successful_save' => $this->_('Champ personnalisé "%s" sauvegardé'), + 'successful_add' => $this->_('Champ personnalisé "%s" ajouté')], 'actions' => ['add' => ['title' => $this->_('Nouveau champ personnalisé')], 'edit' => ['title' => $this->_('Modifier un champ personnalisé')], diff --git a/library/Class/CustomField.php b/library/Class/CustomField.php index 9a9ab7d065f5fd0561b5a32120e0b22b3bba24bb..ba36e52bf7e18f4b43f00c8def5206deff14f761 100644 --- a/library/Class/CustomField.php +++ b/library/Class/CustomField.php @@ -11,12 +11,12 @@ * * 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 + * 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 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class CustomFieldsLoader extends Storm_Model_Loader { @@ -47,10 +47,14 @@ class CustomFieldsLoader extends Storm_Model_Loader { class Class_CustomField extends Storm_Model_Abstract { use Trait_TreeViewableItem; - protected $_table_name = 'custom_field', + protected + $_table_name = 'custom_field', $_loader_class = 'CustomFieldsLoader', $_belongs_to = ['meta' => ['model' => 'Class_CustomField_Meta', 'referenced_in' => 'meta_id']], + $_has_many = ['values' => ['model' => 'Class_CustomField_Value', + 'role' => 'field', + 'dependents' => 'delete']], $_default_attribute_values = ['priority' => 0]; diff --git a/library/Class/CustomField/Value.php b/library/Class/CustomField/Value.php index ea19ff0ee44b25baea4f09ce799fc586aa90903a..a7491e5d32c300373db38824c9ea715b1ca62ce9 100644 --- a/library/Class/CustomField/Value.php +++ b/library/Class/CustomField/Value.php @@ -11,16 +11,19 @@ * * 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 + * 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 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Class_CustomField_Value extends Storm_Model_Abstract { - protected $_table_name = 'custom_field_values'; + protected + $_table_name = 'custom_field_values', + $_belongs_to = ['field' => ['model' => 'Class_CustomField', + 'referenced_in' => 'custom_field_id']]; } ?> \ No newline at end of file diff --git a/tests/application/modules/admin/controllers/CustomFieldsControllerTest.php b/tests/application/modules/admin/controllers/CustomFieldsControllerTest.php index cd3333dff9419df341b64f8b5421f7db0a376b42..0668c13677d9c156a7cf6b469fa4a44913842023 100644 --- a/tests/application/modules/admin/controllers/CustomFieldsControllerTest.php +++ b/tests/application/modules/admin/controllers/CustomFieldsControllerTest.php @@ -74,6 +74,31 @@ abstract class CustomFieldControllerTestCase extends AbstractControllerTestCase 'label' => 'Zip code', 'field_type' => Class_CustomField_Meta::TEXT_INPUT, 'model' => 'UserGroup']); + + + $this->fixture('Class_UserGroup', + ['id' => 1, + 'libelle' => 'Teachers']); + + + $this->fixture('Class_CustomField_Value', //teachers address + ['id' => 23, + 'custom_field_id' => 3, + 'model_id' => 1, + 'value' => '11 rue Paradis']); + + $this->fixture('Class_CustomField_Value', //teachers age + ['id' => 24, + 'custom_field_id' => 4, + 'model_id' => 1, + 'value' => '25']); + + $this->fixture('Class_CustomField_Value', //teachers status + ['id' => 25, + 'custom_field_id' => 5, + 'model_id' => 1, + 'value' => 1]); + } } @@ -392,55 +417,39 @@ class CustomFieldsControllerUpDownActionTest extends CustomFieldControllerTestCa -class CustomFieldsControllerValuesForUserGroupWithoutDefinedCustomFieldsTest extends CustomFieldControllerTestCase { +class CustomFieldsControllerValuesForUserGroupWithMetaDeletedTest extends CustomFieldControllerTestCase { public function setUp() { parent::setUp(); - - $this->fixture('Class_UserGroup', - ['id' => 1, - 'libelle' => 'Teachers']); - Class_CustomField_Meta::deleteBy([]); - $this->dispatch('/admin/custom-fields/values/model/UserGroup/id/1', true); } /** @test */ - public function pageShouldDisplayNoCustomFieldsDefined() { + public function actionValuesShouldDisplayNoCustomFieldsDefined() { + $this->dispatch('/admin/custom-fields/values/model/UserGroup/id/1', true); $this->assertXPathContentContains('//p[@class="error"]', 'Aucun champ personnalisé n\'a été défini'); } -} + /** @test */ + public function customFieldsShouldHaveBeenDeleted() { + $this->assertEmpty(Class_CustomField::findAllBy(['meta_id' => 1])); + } -class CustomFieldsControllerValuesForUserGroupTeachersTest extends CustomFieldControllerTestCase { - public function setUp() { - parent::setUp(); + /** @test */ + public function customFieldsValuesShouldHaveBeenDeleted() { + $this->assertEmpty(Class_CustomField_Value::findAllBy(['id' => [23, 24, 25]])); + } +} - $this->fixture('Class_UserGroup', - ['id' => 1, - 'libelle' => 'Teachers']); - $this->fixture('Class_CustomField_Value', - ['id' => 23, - 'custom_field_id' => 3, - 'model_id' => 1, - 'value' => '11 rue Paradis']); - $this->fixture('Class_CustomField_Value', - ['id' => 24, - 'custom_field_id' => 4, - 'model_id' => 1, - 'value' => '25']); - $this->fixture('Class_CustomField_Value', - ['id' => 25, - 'custom_field_id' => 5, - 'model_id' => 1, - 'value' => 1]); - +class CustomFieldsControllerValuesForUserGroupTeachersTest extends CustomFieldControllerTestCase { + public function setUp() { + parent::setUp(); $this->dispatch('/admin/custom-fields/values/model/UserGroup/id/1', true); } @@ -489,28 +498,6 @@ class CustomFieldsControllerValuesForUserGroupTeachersTest extends CustomFieldCo class CustomFieldsControllerValuesForUserGroupPostTest extends CustomFieldControllerTestCase { public function setUp() { parent::setUp(); - - $this->fixture('Class_UserGroup', - ['id' => 1, - 'libelle' => 'Teachers']); - - $this->fixture('Class_CustomField_Value', - ['id' => 23, - 'custom_field_id' => 3, - 'model_id' => 1, - 'value' => '11 rue Paradis']); - - $this->fixture('Class_CustomField_Value', - ['id' => 24, - 'custom_field_id' => 4, - 'model_id' => 1, - 'value' => '25']); - - $this->fixture('Class_CustomField_Value', - ['id' => 25, - 'custom_field_id' => 5, - 'model_id' => 1, - 'value' => 1]); $this->postDispatch('/admin/custom-fields/values/model/UserGroup/id/1', [