From ae7f2e39c2b16c574389832f7aa9ffff4b38267b Mon Sep 17 00:00:00 2001 From: efalcy <efalcy@git-test.afi-sa.fr> Date: Wed, 20 Nov 2013 17:50:48 +0000 Subject: [PATCH] Creation d'un trait VolatileFixtures pour creer des fixtures volatile et les sauvegarder --- .gitattributes | 1 + library/Trait/VolatileFixtures.php | 37 ++++++++++++ .../modules/AbstractControllerTestCase.php | 2 +- .../admin/controllers/CmsControllerTest.php | 56 ++++++++++--------- 4 files changed, 68 insertions(+), 28 deletions(-) create mode 100644 library/Trait/VolatileFixtures.php diff --git a/.gitattributes b/.gitattributes index 564a9400fbc..dc406cd3524 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2198,6 +2198,7 @@ library/Trait/Translator.php -text library/Trait/TreeNode.php -text library/Trait/TreeViewableCategorie.php -text library/Trait/TreeViewableItem.php -text +library/Trait/VolatileFixtures.php -text library/ZFDebug/README.md -text library/ZFDebug/demos/Zend_Application_Bootstrap.php -text library/ZFDebug/demos/bootstrap.php -text diff --git a/library/Trait/VolatileFixtures.php b/library/Trait/VolatileFixtures.php new file mode 100644 index 00000000000..ef6c9919756 --- /dev/null +++ b/library/Trait/VolatileFixtures.php @@ -0,0 +1,37 @@ +<?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 + */ + +trait Trait_VolatileFixtures { + /** + * @return String + */ + public function fixture($class_name, $attributes) { + $instance = $class_name::newInstanceWithId($attributes['id'], $attributes); + if (!$instance->getLoader()->isVolatile()) + $class_name::beVolatile(); + $instance->assertSave(); + return $instance; + } + + +} + +?> \ No newline at end of file diff --git a/tests/application/modules/AbstractControllerTestCase.php b/tests/application/modules/AbstractControllerTestCase.php index b18161a8983..9fc2125250b 100644 --- a/tests/application/modules/AbstractControllerTestCase.php +++ b/tests/application/modules/AbstractControllerTestCase.php @@ -20,7 +20,7 @@ */ abstract class AbstractControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase { use Storm_Test_THelpers; - + use Trait_VolatileFixtures; protected $_registry_sql; //permet d'authentifier sur la partie admin avant test diff --git a/tests/application/modules/admin/controllers/CmsControllerTest.php b/tests/application/modules/admin/controllers/CmsControllerTest.php index db6a55b7131..2c407df1e65 100644 --- a/tests/application/modules/admin/controllers/CmsControllerTest.php +++ b/tests/application/modules/admin/controllers/CmsControllerTest.php @@ -21,6 +21,7 @@ require_once 'AdminAbstractControllerTestCase.php'; abstract class CmsControllerSimpleUserTestCase extends AbstractControllerTestCase { + protected $_admin_bib; protected $_concert; public function setUp() { @@ -85,28 +86,27 @@ abstract class CmsControllerTestCase extends Admin_AbstractControllerTestCase { protected $_admin_bib, $_laurent,$_bernard; public function setUp() { parent::setUp(); - Class_Users::beVolatile(); - Class_UserGroupMembership::beVolatile(); - Class_UserGroup::beVolatile(); - Class_Lieu::beVolatile(); $this->setupBib(); - $this->_laurent = Class_Users::newInstanceWithIdAssertSave(20, ['login' => 'laurent', - 'mail' => 'laurent@afi-sa.fr', - 'bib' => $this->annecy, - 'password' => 'toto', - 'role_level' => ZendAfi_Acl_AdminControllerRoles::ADMIN_PORTAIL]); - $this->_admin_bib = Class_Users::newInstanceWithIdAssertSave(10, ['login' => 'AdminBibConnected', - 'bib' => $this->annecy, - 'role' => 'admin_bib', - 'mail' => 'admin@afi-sa.fr', - 'password' => 'toto', - 'role_level' => ZendAfi_Acl_AdminControllerRoles::ADMIN_BIB]); - - $this->_bernard = Class_Users::newInstanceWithIdAssertSave(30, ['login' => 'bernie', - 'bib' => $this->annecy, - 'mail' => 'bernard@afi-sa.fr', - 'password' => 'bernie', - 'role_level' => ZendAfi_Acl_AdminControllerRoles::ADMIN_PORTAIL]); + $this->_laurent = $this->fixture('Class_Users', ['id'=>20, + 'login' => 'laurent', + 'mail' => 'laurent@afi-sa.fr', + 'bib' => $this->annecy, + 'password' => 'toto', + 'role_level' => ZendAfi_Acl_AdminControllerRoles::ADMIN_PORTAIL]); + $this->_admin_bib = $this->fixture('Class_Users',['id' => 10, + 'login' => 'AdminBibConnected', + 'bib' => $this->annecy, + 'role' => 'admin_bib', + 'mail' => 'admin@afi-sa.fr', + 'password' => 'toto', + 'role_level' => ZendAfi_Acl_AdminControllerRoles::ADMIN_BIB]); + + $this->_bernard = $this->fixture('Class_Users',['id' =>30, + 'login' => 'bernie', + 'bib' => $this->annecy, + 'mail' => 'bernard@afi-sa.fr', + 'password' => 'bernie', + 'role_level' => ZendAfi_Acl_AdminControllerRoles::ADMIN_PORTAIL]); ZendAfi_Auth::getInstance()->logUser($this->_admin_bib); @@ -123,12 +123,14 @@ abstract class CmsControllerTestCase extends Admin_AbstractControllerTestCase { public function setupLieux() { - $this->lieu_bonlieu = Class_Lieu::newInstanceWithIdAssertSave(3, - ['libelle' => 'Bonlieu', - 'adresse' => '1, rue Jean Jaures', - 'code_postal' => '74000', - 'ville' => 'Annecy', - 'pays' => 'France']); + + $this->lieu_bonlieu = $this->fixture('Class_Lieu', ['id' => 3, + 'libelle' => 'Bonlieu', + 'adresse' => '1, rue Jean Jaures', + 'code_postal' => '74000', + 'ville' => 'Annecy', + 'pays' => 'France' + ]); $this->lieu_arcadium = Class_Lieu::newInstanceWithIdAssertSave(10, ['libelle' => 'Arcadium', -- GitLab