diff --git a/VERSIONS_HOTLINE/51508 b/VERSIONS_HOTLINE/51508 new file mode 100644 index 0000000000000000000000000000000000000000..3b58ebb94e98decc5f45dfe0971a39f4d17152f7 --- /dev/null +++ b/VERSIONS_HOTLINE/51508 @@ -0,0 +1 @@ + - ticket #51508 : Cosmogramme : correction de l'erreur SQL en création de section \ No newline at end of file diff --git a/cosmogramme/cosmozend/application/modules/cosmo/controllers/SectionController.php b/cosmogramme/cosmozend/application/modules/cosmo/controllers/SectionController.php new file mode 100644 index 0000000000000000000000000000000000000000..12e8d870e21e0d39c14eaada2d032c2044bbf422 --- /dev/null +++ b/cosmogramme/cosmozend/application/modules/cosmo/controllers/SectionController.php @@ -0,0 +1,29 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH 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). + * + * BOKEH 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 BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Cosmo_SectionController extends ZendAfi_Controller_Action { + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_Section', + 'ZendAfi_Controller_Plugin_Manager_Section']; + } +} +?> \ No newline at end of file diff --git a/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/section/add.phtml b/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/section/add.phtml new file mode 100644 index 0000000000000000000000000000000000000000..4cbf41858aff0ec2e6a75bb2528a42c4a2fe5b07 --- /dev/null +++ b/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/section/add.phtml @@ -0,0 +1,3 @@ +<?php +echo $this->renderForm($this->form); +?> \ No newline at end of file diff --git a/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/section/edit.phtml b/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/section/edit.phtml new file mode 100644 index 0000000000000000000000000000000000000000..4cbf41858aff0ec2e6a75bb2528a42c4a2fe5b07 --- /dev/null +++ b/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/section/edit.phtml @@ -0,0 +1,3 @@ +<?php +echo $this->renderForm($this->form); +?> \ No newline at end of file diff --git a/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/section/index.phtml b/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/section/index.phtml new file mode 100644 index 0000000000000000000000000000000000000000..171db88906e56271ab3a15e405c848fb9b3ea9db --- /dev/null +++ b/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/section/index.phtml @@ -0,0 +1,17 @@ +<?php +echo $this->tagAnchor(['action' => 'add', + 'id' => null], + $this->_('Ajouter une section')); +echo $this->tagModelTable($this->sections, + [$this->_('libellé'), + $this->_('Règles de reconnaissance'), + $this->_('Rejeter les exemplaires')], + ['libelle', + 'regles', + 'invisible'], + [function($model) + { + return $this->renderPluginsActions($model); + }], + 'sections'); +?> \ No newline at end of file diff --git a/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/SectionControllerTest.php b/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/SectionControllerTest.php new file mode 100644 index 0000000000000000000000000000000000000000..fef7aaf33b9fca6fe452cc7593beeb13690724a3 --- /dev/null +++ b/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/SectionControllerTest.php @@ -0,0 +1,112 @@ +<?php +/** + * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH 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). + * + * BOKEH 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 BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +abstract class Cosmo_SectionControllerTestCase extends CosmoControllerTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + $this->fixture('Class_CodifSection', + ['id' => 5, + 'libelle' => '01 Energie Enjeux', + 'regles' => '995$q=98']); + + $this->fixture('Class_CodifSection', + ['id' => 7, + 'libelle' => '01 Energie Politique', + 'regles' => '995$q=99']); + } +} + + + + +class Cosmo_SectionControllerIndexTest extends Cosmo_SectionControllerTestCase { + + public function setUp() { + parent::setUp(); + $this->dispatch('/cosmo/section', true); + } + + + /** @test */ + public function addNewSectionShouldBePresent() { + $this->assertXPath('//a', 'Ajouter une section'); + } + + + /** @test */ + public function energieEnjeuxShouldBeInTable() { + $this->assertXPathContentContains('//table//tr//td', '01 Energie Enjeux'); + } + + + /** @test */ + public function energiePolitiqueShouldBeInTable() { + $this->assertXPathContentContains('//table//tr//td', '01 Energie Politique'); + } + + + /** @test */ + public function editEnergiePolitiqueShouldBePresent() { + $this->assertXPath('//table//tr//td//a[contains(@href, "/cosmo/section/edit/id/7")]'); + } +} + + + + +class Cosmo_SectionControllerActionsTest extends Cosmo_SectionControllerTestCase { + + public function setUp() { + parent::setUp(); + } + + + /** @test */ + public function inputLibelleShouldBePresent() { + $this->dispatch('/cosmo/section/edit/id/7', true); + $this->assertXPath('//form//input[@value="01 Energie Politique"]'); + } + + + /** @test */ + public function postLibelle02ShouldSaveSection() { + $this->postDispatch('/cosmo/section/edit/id/7', + ['libelle' => '02 Energie Politique']); + $this->assertEquals('02 Energie Politique', Class_CodifSection::find(7)->getLibelle()); + } + + + /** @test */ + public function deleteEnergiePolitiqueShouldRemoveItFromDB() { + $this->dispatch('/cosmo/section/delete/id/7', true); + $this->assertNull(Class_CodifSection::find(7)); + } + + + /** @test */ + public function deleteEnergiePolitiqueShouldRedirectToSectionIndex() { + $this->dispatch('/cosmo/section/delete/id/7', true); + $this->assertRedirectTo('/cosmo/section/index'); + } +} \ No newline at end of file diff --git a/cosmogramme/php/_menu.php b/cosmogramme/php/_menu.php index 4e8ed257ab39f852f25dff736242f2fedc2229b5..13aea8c795bef4577400207bbdc93fd7882d4007 100644 --- a/cosmogramme/php/_menu.php +++ b/cosmogramme/php/_menu.php @@ -100,7 +100,7 @@ else ?> <div class="menu_section">Autorités et codifications</div> <?php - ligneMenu("Sections","codif_section.php"); + ligneMenu("Sections","../cosmozend/cosmo/section"); ligneMenu("Genres","codif_genre.php"); ligneMenu("Emplacements", '../cosmozend/cosmo/emplacement'); ligneMenu("Auteurs","codif_auteur.php"); diff --git a/cosmogramme/php/codif_section.php b/cosmogramme/php/codif_section.php deleted file mode 100644 index 932cb70f691cf87aaddc19df7c2ec70e079ce52b..0000000000000000000000000000000000000000 --- a/cosmogramme/php/codif_section.php +++ /dev/null @@ -1,148 +0,0 @@ -<?PHP -/** - * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. - * - * BOKEH 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). - * - * BOKEH 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 BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -/////////////////////////////////////////////////////////////////// -// -// CODIFS : SECTIONS -// -//////////////////////////////////////////////////////////////////// -include("_init_frame.php"); - -require_once( "fonctions/objets_saisie.php"); - -?> - -<h1>Codification des sections</h1> - -<?PHP - -//--------------------------------------------------------------------------------- -// CREER -//--------------------------------------------------------------------------------- -if($_REQUEST["action"]=="CREER") -{ - $action=array("libelle" => "** nouvelle section **","regles" => "995\$j=a"); - print(BR.BR.BR); - afficherSection($action,"block"); - print('</form></body></html>'); - exit; -} -//--------------------------------------------------------------------------------- -// VALIDER -//--------------------------------------------------------------------------------- -if($_REQUEST["action"]=="VALIDER") -{ - // Vérif de la syntaxe des règles - $regles=trim($_POST["regles"]); - if(! $regles) erreurFormat("Vous devez définir au moins une règle"); - $regles=str_replace(" ","",$regles); - $test = explode("\n",$regles); - foreach($test as $regle) - { - $nb++; - $zone=substr($regle,0,3); if(intval($zone) != $zone) erreurFormat("La zone est mal définie pour la règle n° ".$nb); - if(substr($regle,3,1) != "\$") erreurFormat("Le \$ est absent ou mal positionné pour la règle n° ".$nb); - $champ=substr($regle,4,1); if(($champ < "0" or $champ >"9") and ($champ < "a" or $champ > "z")) erreurFormat("Le champ est mal défini pour la règle n° ".$nb); - $valeurs=substr($regle,6); if(!trim($valeurs)) erreurFormat("Indiquez des valeurs pour la règle n° ".$nb); - $signe=substr($regle,5,1); if( strpos("=/*",$signe) === false) erreurFormat("Signe de comparaison incorrect pour la règle n° ".$nb); - $elem=explode(" ",$regle); - } - - // ecriture - if(!isset($_POST["invisible"])) $_POST["invisible"]="0"; - $id_section=$_POST["id_section"]; - $_POST["regles"]=$regles; - if(!$id_section) $sql->insert("codif_section",$_POST); - else - { - unset($_POST["id_section"]); - $sql->update("update codif_section set @SET@ where id_section=$id_section",$_POST); - } - -} -//--------------------------------------------------------------------------------- -// SUPPRIMER -//--------------------------------------------------------------------------------- - -if($_REQUEST["action"]=="SUPPRIMER") -{ - $id_section=$_REQUEST["id_section"]; - if($id_section) $sql->execute("delete from codif_section where id_section =$id_section"); -} - -//--------------------------------------------------------------------------------- -// LISTE -//--------------------------------------------------------------------------------- -print('<div class="liste">'); - -$liste=$sql->fetchAll("Select * from codif_section order by libelle"); -for($p=0; $p< count($liste); $p++) -{ - $section=$liste[$p]; - $img="plus.gif"; - $display="none"; - if($section["id_section"] == $_REQUEST["id_section"]) - { - $img="moins.gif"; - $display="block"; - } - print('<div class="liste_img"><img id="Isection'.$section["id_section"].'" src="'.URL_IMG.$img.'" onclick="contracter_bloc(\'section'.$section["id_section"].'\')" style="cursor:pointer"></div>'); - print('<div class="liste_titre">'. $section["libelle"].'</div>'); - affichersection($section,$display); -} -print('</div>'); -// Bouton ajouter -$bouton_ajout=rendBouton("Ajouter une section","codif_section","action=CREER"); -print(BR.BR.$bouton_ajout); - -print('</body></html>'); -exit; - -function affichersection($section,$display) -{ - print('<div class="form" id="section'.$section["id_section"].'" style="width:600px;margin-left:20px;display:'.$display.'">'); - print('<form method="post" action="'.URL_BASE.'php/codif_section.php?action=VALIDER">'); - print('<input type="hidden" name="id_section" value="'.$section["id_section"].'">'); - print('<table class="form" cellspacing="0" cellpadding="5">'); - print('<tr><th class="form" colspan="2" align="left">Création de section</th></tr>'); - print('<tr><td class="form_first" align="right" width="35%">Libellé</td><td class="form_first">'.getChamp("libelle",$section["libelle"],43).'</td></tr>'); - print('<tr><td class="form_first" align="center" colspan="2"><div class="commentaire">Syntaxe : [zone$champ][signe][valeur1;valeur2;etc...] - Ex : 995$a = a<br>Signes : "=" égal - "/" commence par - "*" contient</div></td></tr>'); - print('<tr><td class="form" align="right" valign="top">Règles de reconnaissance</td><td class="form">'.getTextarea("regles",$section["regles"],40,5).'</td></tr>'); - if($section["invisible"]==1) $checked="checked"; else $checked=""; - print('<tr><td class="form_first" align="right" width="35%">Rejeter les exemplaires</td><td class="form_first"><input type="checkbox" value="1" '.$checked.' name="invisible"></td></tr>'); - - // Boutons maj - print('<tr><th class="form" colspan="2" align="center">'); - $bouton_valider='<input type="submit" class="bouton" value="Valider">'; - $bouton_supprimer=rendBouton("Supprimer","codif_section","action=SUPPRIMER&id_section=".$section["id_section"]); - print($bouton_valider.str_repeat(" ",5).$bouton_supprimer); - print('</th></tr></table></form></div>'); -} - -function erreurFormat($erreur) -{ - print('<span class = "rouge">'.$erreur.'</span>'); - $action=$_POST; - print(BR.BR.BR); - afficherSection($action,"block"); - print('</form></body></html>'); - exit; -} -?> \ No newline at end of file diff --git a/cosmogramme/sql/patch/patch_316.php b/cosmogramme/sql/patch/patch_316.php new file mode 100644 index 0000000000000000000000000000000000000000..e1578072ceab6f73d7934e8d1db6ec51a1721f40 --- /dev/null +++ b/cosmogramme/sql/patch/patch_316.php @@ -0,0 +1,6 @@ +<?php +try { + Zend_Db_Table_Abstract::getDefaultAdapter() + ->query('ALTER TABLE codif_section MODIFY id_section int(11) NOT NULL AUTO_INCREMENT'); +} catch(Exception $e) {} +?> diff --git a/library/ZendAfi/Controller/Plugin/Manager/Section.php b/library/ZendAfi/Controller/Plugin/Manager/Section.php new file mode 100644 index 0000000000000000000000000000000000000000..2c9a966e14385bfe776e08ffdd3bfb08877b83dd --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/Manager/Section.php @@ -0,0 +1,46 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH 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). + * + * BOKEH 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 BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class ZendAfi_Controller_Plugin_Manager_Section extends ZendAfi_Controller_Plugin_Manager_Manager { + public function getActions($model) { + return [['url' => ['action' => 'edit', + 'id' => $model->getId()], + 'icon' => 'edit', + 'label' => $this->_('Modifier')], + + ['url' => ['action' => 'delete', + 'id' => $model->getId()], + 'icon' => 'delete', + 'label' => $this->_('Supprimer')]]; + } + + + protected function _redirectToIndex() { + $this->_redirect('/cosmo/' . $this->_request->getControllerName().'/index'); + } + + + protected function _redirectToEdit($model) { + $this->_redirect('/cosmo/' . $this->_request->getControllerName().'/edit/id/' . $model->getId()); + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Section.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Section.php new file mode 100644 index 0000000000000000000000000000000000000000..a9000b9070dd46d67a4c1a7b4b0fa277eed0c72c --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Section.php @@ -0,0 +1,38 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH 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). + * + * BOKEH 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 BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class ZendAfi_Controller_Plugin_ResourceDefinition_Section extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + + public function getDefinitions() { + return ['model' => ['class' => 'Class_CodifSection', + 'name' => 'section', + 'order' => 'libelle', + 'model_id' => 'id_section'], + + 'messages' => ['successful_save' => $this->_('La section "%s" a été modifée'), + 'successful_add' => $this->_('La section "%s" a été ajoutée'), + 'successful_delete' => $this->_('La section "%s" a été suppriméee')], + + 'form_class_name' => 'ZendAfi_Form_Admin_Section']; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Form/Admin/Section.php b/library/ZendAfi/Form/Admin/Section.php new file mode 100644 index 0000000000000000000000000000000000000000..3ba993e32b6f16acef79cf48b40f0f8f56dbb935 --- /dev/null +++ b/library/ZendAfi/Form/Admin/Section.php @@ -0,0 +1,47 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH 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). + * + * BOKEH 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 BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class ZendAfi_Form_Admin_Section extends ZendAfi_Form { + public function init() { + parent::init(); + + $this + ->addElement('text', + 'libelle', + ['label' => $this->_('Libellé'), + 'required' => true, + 'allowEmpty' => false]) + ->addElement('textarea', + 'regles', + ['label' => $this->_('Règles de reconnaissance : Syntaxe : [zone$champ][signe][valeur1;valeur2;etc...] - Ex : 995$a = a . Signes : "=" égal - "/" commence par - "*" contient'), + 'required' => true, + 'allowEmpty' => false]) + ->addElement('checkbox', + 'invisible', + ['label' => $this->_('Rejeter les exemplaires')]) + ->addUniqDisplayGroup('section', + ['legend' => $this->_('Formulaire de section')]); + } + + +} +?> \ No newline at end of file diff --git a/tests/db/UpgradeDBTest.php b/tests/db/UpgradeDBTest.php index 9c3f2a094c0caa9a2c82a0c5edbf96a4600702f8..1adf3a474075a45ea631151e03e2a7994a739a0e 100644 --- a/tests/db/UpgradeDBTest.php +++ b/tests/db/UpgradeDBTest.php @@ -1200,4 +1200,25 @@ class UpgradeDB_315_Test extends UpgradeDBTestCase { $this->assertFieldType('linked_cards', $field, $type); $this->assertFieldNotNullable('linked_cards', $field); } +} + + + +class UpgradeDB_316_Test extends UpgradeDBTestCase { + + public function prepare() { + try { + $this->query("ALTER TABLE codif_section MODIFY id_section tinyint(4)"); + } catch (Exception $e) { + var_dump($e); + } + } + + + /** @test */ + public function idSectionShouldBeIntElevenPrimaryKey() { + $this->assertFieldType('codif_section','id_section', 'int(11)'); + $this->assertField('codif_section','id_section', 'PRI', 'Key'); + $this->assertField('codif_section','id_section', 'NO', 'Null'); + } } \ No newline at end of file