diff --git a/.gitattributes b/.gitattributes index c4bf1a64da4903bdce3d6507802472dbf2d5dbc1..e5938f2267eb602f930c1b09d39d615fa5935b14 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4619,6 +4619,7 @@ tests/library/Class/File/MimeTest.php -text tests/library/Class/FileWriterTest.php -text tests/library/Class/Folder/ManagerTest.php -text tests/library/Class/FormationTest.php -text +tests/library/Class/FormulaireTest.php -text tests/library/Class/GlobalSqlRefactoringTest.php -text tests/library/Class/I18nTest.php -text tests/library/Class/I18nTranslatorTest.php -text diff --git a/library/Class/Formulaire.php b/library/Class/Formulaire.php index 56e98872a27521f0c0beb1718c74685dfff299c4..f86b11f39a13518748d02f466e156a679fe502d6 100644 --- a/library/Class/Formulaire.php +++ b/library/Class/Formulaire.php @@ -22,10 +22,13 @@ class Class_Formulaire extends Storm_Model_Abstract { use Trait_TimeSource; - protected $_datas; protected $_table_name='formulaires'; - protected $_default_attribute_values = ['data' => '']; + protected $_belongs_to = ['user' => ['model' => 'Class_Users', + 'referenced_in' => 'id_user']]; + + protected $_default_attribute_values = ['data' => 'a:0:{}']; + protected $_datas; public static function mergeDataNames($formulaires) { $names = []; foreach($formulaires as $formulaire) { diff --git a/library/Class/Users.php b/library/Class/Users.php index 4dc730fb5677e08cf2a2230753a0a3fe8eb91260..9da58f64ed2d1ebd3e4bcd75625ef37d4fad034b 100644 --- a/library/Class/Users.php +++ b/library/Class/Users.php @@ -141,40 +141,46 @@ class Class_Users extends Storm_Model_Abstract { protected $_table_name = 'bib_admin_users'; protected $_table_primary = 'ID_USER'; protected $_loader_class = 'UsersLoader'; - protected $_has_many = array('subscriptions' => array('model' => 'Class_NewsletterSubscription', - 'role' => 'user', - 'dependents' => 'delete'), + protected $_has_many = [ + 'subscriptions' => ['model' => 'Class_NewsletterSubscription', + 'role' => 'user', + 'dependents' => 'delete'], - 'newsletters' => array('through' => 'subscriptions'), + 'newsletters' => ['through' => 'subscriptions'], - 'avis' => array('model' => 'Class_AvisNotice', - 'role' => 'user', - 'order' => 'date_avis desc'), + 'avis' => ['model' => 'Class_AvisNotice', + 'role' => 'user', + 'order' => 'date_avis desc'], - 'avis_articles' => array('model' => 'Class_Avis', - 'role' => 'auteur', - 'order' => 'date_avis desc'), + 'avis_articles' => ['model' => 'Class_Avis', + 'role' => 'auteur', + 'order' => 'date_avis desc'], - 'paniers' => array('model' => 'Class_PanierNotice', - 'role' => 'user'), + 'paniers' => ['model' => 'Class_PanierNotice', + 'role' => 'user'], - 'session_formation_inscriptions' => array('model' => 'Class_SessionFormationInscription', - 'role' => 'stagiaire'), + 'session_formation_inscriptions' => ['model' => 'Class_SessionFormationInscription', + 'role' => 'stagiaire'], - 'session_formations' => array('through' => 'session_formation_inscriptions'), + 'session_formations' => ['through' => 'session_formation_inscriptions'], - 'formations' => array('through' => 'session_formation_inscriptions'), + 'formations' => ['through' => 'session_formation_inscriptions'], - 'session_formation_interventions' => array('model' => 'Class_SessionFormationIntervention', - 'role' => 'intervenant'), + 'session_formation_interventions' => ['model' => 'Class_SessionFormationIntervention', + 'role' => 'intervenant'], - 'session_interventions' => array('through' => 'session_formation_interventions'), + 'session_interventions' => ['through' => 'session_formation_interventions'], - 'user_group_memberships' => array('model' => 'Class_UserGroupMembership', - 'role' => 'user'), + 'user_group_memberships' => ['model' => 'Class_UserGroupMembership', + 'role' => 'user'], - 'user_groups' => array('through' => 'user_group_memberships') - ); + 'user_groups' => ['through' => 'user_group_memberships'], + + 'formulaires' => ['model' => 'Class_Formulaire', + 'role' => 'user', + 'order' => 'date_creation desc'], + + ]; protected $_belongs_to = array('bib' => array('model' => 'Class_Bib', diff --git a/tests/library/Class/FormulaireTest.php b/tests/library/Class/FormulaireTest.php new file mode 100644 index 0000000000000000000000000000000000000000..e5d330a8baee61fd9d8e0f58077a21cdef575f4a --- /dev/null +++ b/tests/library/Class/FormulaireTest.php @@ -0,0 +1,46 @@ +<?php +/** + * Copyright (c) 2012, 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 FormulaireTest extends Storm_Test_ModelTestCase { + public function setUp() { + parent::setUp(); + $this->_fantomas = Class_Users::newInstanceWithId(23, ['login' => 'fantomas']); + $this->_formulaire = Class_Formulaire::newInstanceWithId(2, ['id_user' => 23]); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Formulaire') + ->whenCalled('findAllBy') + ->answers([$this->_formulaire]); + + } + + + /** @test */ + public function formulaireUserShouldBeFantomas() { + $this->assertEquals('fantomas', $this->_formulaire->getUser()->getLogin()); + } + + + /** @test */ + public function userFantomasShouldHaveOneFormulaire() { + $this->assertEquals([$this->_formulaire], + $this->_fantomas->getFormulaires()); + } +}