From d0bc332e0b002d0e6ee24297cbc719cf79a9d3b1 Mon Sep 17 00:00:00 2001 From: efalcy <efalcy@git-test.afi-sa.fr> Date: Thu, 31 Jan 2013 10:53:59 +0000 Subject: [PATCH] Ajout de domaines dans les articles --- .gitattributes | 2 ++ .../admin/views/scripts/cms/newsform.phtml | 2 +- cosmogramme/php/_init.php | 4 +-- cosmogramme/sql/patch/patch_144.sql | 2 ++ cosmogramme/sql/patch/patch_145.sql | 2 ++ library/Class/Article.php | 16 ++++++--- library/Class/Catalogue.php | 20 ++++++++--- .../admin/controllers/CmsControllerTest.php | 36 +++++++++++++++---- tests/library/Class/CatalogueTest.php | 36 +++++++++++++++++++ 9 files changed, 102 insertions(+), 18 deletions(-) create mode 100644 cosmogramme/sql/patch/patch_144.sql create mode 100644 cosmogramme/sql/patch/patch_145.sql diff --git a/.gitattributes b/.gitattributes index cd43dc1f970..bc053202ede 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2120,6 +2120,8 @@ cosmogramme/sql/patch/patch_140.sql -text cosmogramme/sql/patch/patch_141.sql -text cosmogramme/sql/patch/patch_142.sql -text cosmogramme/sql/patch/patch_143.sql -text +cosmogramme/sql/patch/patch_144.sql -text +cosmogramme/sql/patch/patch_145.sql -text cosmogramme/tests/bootstrap.php -text cosmogramme/tests/php/classes/IndexationTest.php -text cosmogramme/tests/php/classes/Iso2709RecordTest.php -text diff --git a/application/modules/admin/views/scripts/cms/newsform.phtml b/application/modules/admin/views/scripts/cms/newsform.phtml index 9f152c89741..4626c553c59 100644 --- a/application/modules/admin/views/scripts/cms/newsform.phtml +++ b/application/modules/admin/views/scripts/cms/newsform.phtml @@ -214,7 +214,7 @@ Class_ScriptLoader::getInstance() <td><?php echo $this->traduire('Domaines'); ?></td> <td> <?php -echo $this->formMultiCheckbox('domaine_ids',$this->article->getDomaineIds(),[],Class_Catalogue::allByIdLabel()); +echo $this->formMultiCheckbox('domaine_ids',$this->article->getDomaineIdsAsArray(),[],Class_Catalogue::allByIdLabel()); ?> </td> </tr> diff --git a/cosmogramme/php/_init.php b/cosmogramme/php/_init.php index e304e15b547..758b56376bf 100644 --- a/cosmogramme/php/_init.php +++ b/cosmogramme/php/_init.php @@ -1,14 +1,14 @@ <?PHP // Constantes define("VERSION_COSMOGRAMME","6.25"); -define("PATCH_LEVEL","143"); +define("PATCH_LEVEL","145"); define("APPLI","cosmogramme"); define("CRLF", chr(13) . chr(10)); define("BR","<br />"); define("COSMOPATH", "/var/www/html/vhosts/opac2/www/htdocs"); date_default_timezone_set('Europe/Paris'); - +xdebug_break(); // Add cg: site= nom du site Opac (Ex: mabellebib.net) $argc = isset($argc) ? $argc : 0; if ($argc < 3) { diff --git a/cosmogramme/sql/patch/patch_144.sql b/cosmogramme/sql/patch/patch_144.sql new file mode 100644 index 00000000000..f2e9f0a82a9 --- /dev/null +++ b/cosmogramme/sql/patch/patch_144.sql @@ -0,0 +1,2 @@ +ALTER TABLE `cms_article` ADD COLUMN `DOMAINE_IDS` varchar(100) NOT NULL default ''; + diff --git a/cosmogramme/sql/patch/patch_145.sql b/cosmogramme/sql/patch/patch_145.sql new file mode 100644 index 00000000000..354b15ea6ee --- /dev/null +++ b/cosmogramme/sql/patch/patch_145.sql @@ -0,0 +1,2 @@ +ALTER TABLE `catalogue` ADD COLUMN `PARENT_ID` int(11) ; +ALTER TABLE `catalogue` ADD INDEX (PARENT_ID); diff --git a/library/Class/Article.php b/library/Class/Article.php index 889b8e6a9ff..78afd10bc14 100644 --- a/library/Class/Article.php +++ b/library/Class/Article.php @@ -445,7 +445,8 @@ class Class_Article extends Storm_Model_Abstract { 'date_maj' => '', 'date_creation' => '', 'status' => self::STATUS_DRAFT, - 'id_lieu' => 0 + 'id_lieu' => 0, + 'domaine_ids' => '' ]; /** @@ -944,12 +945,19 @@ class Class_Article extends Storm_Model_Abstract { return Class_CmsRank::getLoader()->findFirstBy(array('id_cms' => $this->getId())); } + public function setDomaineIds($domaines) { + if (is_array($domaines)) + $domaines=implode(';',$domaines); + return $this->_set('domaine_ids',$domaines); + } + + public function getDomaineIdsAsArray() { + $domaines = $this->_get('domaine_ids') ; + return array_filter(explode(';',$domaines)); + } -public function getDomaineIds() { - return ['11']; -} } diff --git a/library/Class/Catalogue.php b/library/Class/Catalogue.php index 2b443430a73..c6b67405a36 100644 --- a/library/Class/Catalogue.php +++ b/library/Class/Catalogue.php @@ -186,6 +186,15 @@ class CatalogueLoader extends Storm_Model_Loader { return implode(' and ', $clauses); } + + public function allByIdLabel() { + $catalogues = Class_Catalogue::findAllBy(['order' => 'libelle']); + $allids=[]; + foreach($catalogues as $catalogue) { + $allids[$catalogue->getId()]=$catalogue->getLibelle(); + } + return $allids; + } } @@ -215,13 +224,16 @@ class Class_Catalogue extends Storm_Model_Abstract { 'cote_fin' => '', 'nouveaute' => ''); + protected $_belongs_to = [ 'domaine_parent' => ['model' => 'Class_Catalogue', + 'referenced_in' => 'parent_id']]; + + protected $_has_many = ['sous_domaines' => ['model' => 'Class_Catalogue', + 'role' => 'domaine_parent', + 'dependents' => 'delete', + 'order' => 'libelle']]; protected $_from; protected $_until; - public static function getLoader() { - return self::getLoaderFor(__CLASS__); - } - public static function newCatalogueForAll() { return new AllNoticesCatalogue(); diff --git a/tests/application/modules/admin/controllers/CmsControllerTest.php b/tests/application/modules/admin/controllers/CmsControllerTest.php index 2a09e4b0d9e..7d02be4bc79 100644 --- a/tests/application/modules/admin/controllers/CmsControllerTest.php +++ b/tests/application/modules/admin/controllers/CmsControllerTest.php @@ -62,10 +62,8 @@ abstract class CmsControllerTestCase extends Admin_AbstractControllerTestCase { Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue') ->whenCalled('findAllBy') ->with(array('order' => 'libelle')) - ->answers([$this->domaine_art,$this->domaine_histoire]) - ->whenCalled('allByIdLabel') - ->answers(['10' => 'Histoire', '11'=> 'Art']) - ->beStrict(); + ->answers([$this->domaine_art,$this->domaine_histoire]); + } @@ -102,6 +100,7 @@ abstract class CmsControllerTestCase extends Admin_AbstractControllerTestCase { ->setAvis(true) ->setIndexation(false) ->setDateCreation('2010-12-25') + ->setDomaineIds([11,12]) ->setAvisUsers([]); @@ -441,6 +440,14 @@ class CmsControllerArticleConcertEditActionTest extends CmsControllerTestCase { } + + /** @test */ + public function checkBoxShouldContainsDomaineArt() { + $this->assertXPath("//label[contains(text(), 'Art')]//input[@type='checkbox'][@name='domaine_ids[]'][@value='11'][@checked='checked']",$this->_response->getBody()); + + } + + } @@ -479,7 +486,8 @@ class CmsControllerArticleConcertEditActionPostTest extends CmsControllerTestCas 'events_fin' => '05/03/2011', 'contenu' => 'Ici: <img src="../../images/bonlieu.jpg" />', 'description' => 'Affiche: <img src="http://localhost' . BASE_URL . '/images/concert.jpg" />', - 'id_lieu' => 3); + 'id_lieu' => 3, + 'domaine_ids' => ['10']); $this ->getRequest() @@ -580,6 +588,12 @@ class CmsControllerArticleConcertEditActionPostTest extends CmsControllerTestCas public function comboLieuShouldHaveOptionBonlieuSelected() { $this->assertXPath('//select[@name="id_lieu"]//option[@selected="selected"][@label="Bonlieu"][@value="3"]'); } + + /** @test */ + public function domainesShouldBeOnlyHistoire() { + $this->assertEquals(['10'],$this->concert->getDomaineIdsAsArray()); + } + } @@ -647,7 +661,8 @@ class CmsControllerArticleAddActionPostTest extends CmsControllerTestCase { 'events_fin' => '', 'description' => '', 'id_cat' => 23, - 'contenu' => 'Youpi!!'); + 'contenu' => 'Youpi!!', + 'domaine_ids' => ['11','12']); $this ->getRequest() @@ -691,6 +706,13 @@ class CmsControllerArticleAddActionPostTest extends CmsControllerTestCase { function categorieShouldBeALaUne() { $this->assertEquals('A la Une', $this->new_article->getCategorie()->getLibelle()); } + + + /** @test */ + public function domainesShouldBeArtAndMusique() { + $this->assertEquals(['11','12'],$this->new_article->getDomaineIdsAsArray()); + } + } @@ -698,7 +720,7 @@ class CmsControllerArticleAddActionPostTest extends CmsControllerTestCase { class CmsControllerNewsAddActionTest extends CmsControllerTestCase { public function setUp() { parent::setUp(); - $this->dispatch('admin/cms/newsadd/id_cat/23'); + $this->dispatch('admin/cms/newsadd/id_cat/23',true); } /** @test */ diff --git a/tests/library/Class/CatalogueTest.php b/tests/library/Class/CatalogueTest.php index b8bd2d7ee27..42109500a0c 100644 --- a/tests/library/Class/CatalogueTest.php +++ b/tests/library/Class/CatalogueTest.php @@ -503,4 +503,40 @@ class CatalogueTestGetNoticesByPreferences extends ModelTestCase { } } + + + +class CatalogueParentTest extends Storm_Test_ModelTestCase { + + public function setUp() { + parent::setUp(); + $this->_histoire = Class_Catalogue::newInstanceWithId(100, [ 'libelle' => 'Histoire']); + $this->_politique = Class_Catalogue::newInstanceWithId(200, [ 'libelle' => 'Politique', + 'parent_id' => 100]); + $this->_moyenage = Class_Catalogue::newInstanceWithId(300, [ 'libelle'=>'Moyen-age', + 'parent_id' => 100]); + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue') + ->whenCalled('findAllBy') + ->with(['role' => 'domaine_parent', + 'model' => $this->_histoire, + 'order' => 'libelle' + ]) + ->answers([ $this->_politique, $this->_moyenage]); + + + } + + /** @test */ + public function politiqueShouldHaveHistoireAsDomaineParent() { + $this->assertEquals('Histoire', $this->_politique->getDomaineParent()->getLibelle()); + } + +/** @test */ + public function HistoireShouldHaveSousDomainesPolitiqueEtMoyenAge() { + $this->assertEquals([ $this->_politique, $this->_moyenage],$this->_histoire->getSousDomaines()); + + } +} + + ?> \ No newline at end of file -- GitLab