From cf9c4902a014bed75cd62e00dc96ebfd16c2e18c Mon Sep 17 00:00:00 2001 From: efalcy <efalcy@git-test.afi-sa.fr> Date: Tue, 17 Dec 2013 16:20:01 +0000 Subject: [PATCH] Type de documents : association avec les familles , edition/sauvegarde ok --- .../admin/controllers/TypeDocsController.php | 2 +- cosmogramme/sql/patch/patch_184.sql | 6 +- library/Class/CodifTypeDoc.php | 7 ++- library/Class/TypeDoc.php | 21 +++++-- .../Action/RessourceDefinitions.php | 2 +- library/ZendAfi/View/Helper/TagModelTable.php | 1 - .../controllers/TypeDocsControllerTest.php | 59 +++++++++++++++---- tests/library/Class/TypeDocTest.php | 2 + 8 files changed, 73 insertions(+), 27 deletions(-) diff --git a/application/modules/admin/controllers/TypeDocsController.php b/application/modules/admin/controllers/TypeDocsController.php index c6c47b6e6c2..f64ebd2234e 100644 --- a/application/modules/admin/controllers/TypeDocsController.php +++ b/application/modules/admin/controllers/TypeDocsController.php @@ -30,7 +30,7 @@ class Admin_TypeDocsController extends ZendAfi_Controller_Action { 'order' => 'libelle'], 'messages' => ['successful_save' => $this->_('Type de document %s modifié')], - 'actions' => ['edit' => ['title' => 'Modification du type de document:'], + 'actions' => ['edit' => ['title' => 'Modification du type de document: %s'], 'index' => ['title' => 'Types de documents']], 'display_groups' => ['definition' => ['legend' => 'Définition', 'elements' => ['famille_id' => ['element' => 'select', diff --git a/cosmogramme/sql/patch/patch_184.sql b/cosmogramme/sql/patch/patch_184.sql index d35369a49a7..ef0abd8456b 100644 --- a/cosmogramme/sql/patch/patch_184.sql +++ b/cosmogramme/sql/patch/patch_184.sql @@ -1,6 +1,6 @@ CREATE TABLE `codif_type_doc` ( - `id` tinyint(4) NOT NULL, + `type_doc_id` tinyint(4) NOT NULL, `famille_id` tinyint(4) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=0; + PRIMARY KEY (`type_doc_id`) +) ENGINE=MyISAM ; diff --git a/library/Class/CodifTypeDoc.php b/library/Class/CodifTypeDoc.php index dc993df3013..0066954a361 100644 --- a/library/Class/CodifTypeDoc.php +++ b/library/Class/CodifTypeDoc.php @@ -22,7 +22,7 @@ class Class_CodifTypeDoc extends Storm_Model_Abstract { protected $_table_name = 'codif_type_doc'; - protected $_table_primary = 'id'; + protected $_table_primary = 'type_doc_id'; const INCONNU = 0; @@ -50,7 +50,7 @@ class Class_CodifTypeDoc extends Storm_Model_Abstract { public function setFamilleId($id) { if (!isset(static::$_libelles[$id])) $id=0; - parent::_set('famille_id',$id); + return parent::_set('famille_id',$id); } @@ -58,6 +58,9 @@ class Class_CodifTypeDoc extends Storm_Model_Abstract { return static::$_libelles; } + public function afterSave() { + $this->setId($this->getTypeDocId()); + } } diff --git a/library/Class/TypeDoc.php b/library/Class/TypeDoc.php index 1c8723d3f17..10bc9de27cc 100644 --- a/library/Class/TypeDoc.php +++ b/library/Class/TypeDoc.php @@ -88,8 +88,15 @@ class TypeDocLoader { } + public function saveCodifTypeDoc($model) { + $model->getCodifTypeDoc()->save(); + return $this; + } + + public function save($model) { $serialized = array(); + $this->saveCodifTypeDoc($model); foreach ($this->findAll() as $i => $type_doc) { if ($type_doc->getId() === $model->getId()) @@ -104,10 +111,10 @@ class TypeDocLoader { $serialized []= $this->serialize($model); } - return $this->_saveSerialized($serialized); + return $this->_saveSerialized($serialized); } - + public function delete($model) { $serialized = array(); @@ -250,10 +257,12 @@ class Class_TypeDoc extends Storm_Model_Abstract { public function getCodifTypeDoc() { if ($codif=parent::_get('codif_type_doc')) return $codif; - $codif=Class_CodifTypeDoc::newInstanceWithId($this->getId(), - ['famille_id' => $this->getId()]); + $codif=Class_CodifTypeDoc::newInstance( ['type_doc_id' => $this->getId(), + 'famille_id' => $this->getId()]); + $codif->save(); + $codif->setId($this->getId()); + $this->setCodifTypeDoc($codif); return $codif; - } @@ -263,7 +272,7 @@ class Class_TypeDoc extends Storm_Model_Abstract { public function getFamilleId() { - return $this->getCodifTypeDoc()->getId(); + return $this->getCodifTypeDoc()->getFamilleId(); } diff --git a/library/ZendAfi/Controller/Action/RessourceDefinitions.php b/library/ZendAfi/Controller/Action/RessourceDefinitions.php index 1dab68c69e4..f9867007a1a 100644 --- a/library/ZendAfi/Controller/Action/RessourceDefinitions.php +++ b/library/ZendAfi/Controller/Action/RessourceDefinitions.php @@ -98,7 +98,7 @@ class ZendAfi_Controller_Action_RessourceDefinitions { public function editActionTitle($model) { - return sprintf($this->titleForAction('edit'),$model); + return sprintf($this->titleForAction('edit'),$model->getLibelle()); } diff --git a/library/ZendAfi/View/Helper/TagModelTable.php b/library/ZendAfi/View/Helper/TagModelTable.php index c56774585e9..455a3a73f77 100644 --- a/library/ZendAfi/View/Helper/TagModelTable.php +++ b/library/ZendAfi/View/Helper/TagModelTable.php @@ -150,7 +150,6 @@ class ZendAfi_View_Helper_TagModelTable extends Zend_View_Helper_HtmlElement { public function renderModelAction($model, $action) { if (is_a($action, 'Closure')) return $action($model); - $content = $action['content']; return $this->view->tagAnchor(array('action' => $action['action'], diff --git a/tests/application/modules/admin/controllers/TypeDocsControllerTest.php b/tests/application/modules/admin/controllers/TypeDocsControllerTest.php index 9b141fc56c3..2c5eeb23912 100644 --- a/tests/application/modules/admin/controllers/TypeDocsControllerTest.php +++ b/tests/application/modules/admin/controllers/TypeDocsControllerTest.php @@ -21,8 +21,7 @@ -abstract class AbstractTypeDocsControllerTest extends AbstractControllerTestCase { - +abstract class AbstractTypeDocsControllerTestCase extends AbstractControllerTestCase { public function setUp() { parent::setUp(); Class_CosmoVar::newInstanceWithId('types_docs', ['liste' => "0:non identifié\r\n1:Livres\r\n2:périodiques"]); @@ -35,9 +34,7 @@ abstract class AbstractTypeDocsControllerTest extends AbstractControllerTestCase } -class TypeDocsControllerIndexTest extends AbstractTypeDocsControllerTest { - - +class TypeDocsControllerIndexTest extends AbstractTypeDocsControllerTestCase { public function setUp() { parent::setUp(); $this->dispatch('/admin/type-docs/',true); @@ -68,11 +65,16 @@ class TypeDocsControllerIndexTest extends AbstractTypeDocsControllerTest { $this->assertXPath('//a[contains(@href, "admin/type-docs/edit/id/1")]', $this->_response->getBody()); } + + /** @test */ + public function tableShouldContainsLinkToEditEbooKs() { + $this->assertXPath('//a[contains(@href, "admin/type-docs/edit/id/102")]', $this->_response->getBody()); + } + } -class TypeDocsControllerEditTest extends AbstractTypeDocsControllerTest { - +class TypeDocsControllerEditTest extends AbstractTypeDocsControllerTestCase { public function setUp() { parent::setUp(); $this->dispatch('/admin/type-docs/edit/id/1',true); @@ -80,7 +82,7 @@ class TypeDocsControllerEditTest extends AbstractTypeDocsControllerTest { /** @test */ public function titreShouldBeModificationDuTypeDocLivre() { - $this->assertXPathContentContains('//h1','Modification du type de document',$this->_response->getBody()); + $this->assertXPathContentContains('//h1','Modification du type de document: Livre',$this->_response->getBody()); } /** @test */ @@ -88,27 +90,58 @@ class TypeDocsControllerEditTest extends AbstractTypeDocsControllerTest { $this->assertXPath('//form//select[@name="famille_id"]/option[@value="1"][@selected="selected"]', $this->_response->getBody()); } +} + + +class TypeDocsControllerEditEPubTest extends AbstractTypeDocsControllerTestCase { + public function setUp() { + parent::setUp(); + $this->fixture('Class_CodifTypeDoc', ['id' => 102, + 'famille_id' => Class_CodifTypeDoc::LIVRE]); + + $this->dispatch('/admin/type-docs/edit/id/102',true); + } + + /** @test */ + public function titreShouldBeModificationDuTypeDocEPUB() { + $this->assertXPathContentContains('//h1','Modification du type de document: E-Books',$this->_response->getBody()); + } + + /** @test */ + public function livreShouldBeSelected() { + $this->assertXPath('//form//select[@name="famille_id"]/option[@value="1"][@selected="selected"]', $this->_response->getBody()); + } } -class TypeDocsControllerEditPostTest extends AbstractTypeDocsControllerTest { - +class TypeDocsControllerEditLivrePostTest extends AbstractTypeDocsControllerTestCase { public function setUp() { parent::setUp(); - $this->postDispatch('/admin/type-docs/edit/id/1', ['id' => '1', - 'famille_id' => '4']); + $this->postDispatch('/admin/type-docs/edit/id/1', [ 'famille_id' => '4']); + Class_CodifTypeDoc::clearCache(); } /** @test */ public function typeDocShouldBe4() { $this->assertEquals(4,Class_CodifTypeDoc::find(1)->getFamilleId()); } - +} +class TypeDocsControllerEditEbookPostTest extends AbstractTypeDocsControllerTestCase { + public function setUp() { + parent::setUp(); + $this->postDispatch('/admin/type-docs/edit/id/102', [ 'famille_id' => '4']); + Class_CodifTypeDoc::clearCache(); + } + /** @test */ + public function typeDocShouldBe4() { + $this->assertEquals(4,Class_CodifTypeDoc::find(102)->getFamilleId()); + } } + ?> \ No newline at end of file diff --git a/tests/library/Class/TypeDocTest.php b/tests/library/Class/TypeDocTest.php index e4fa875920b..1188e521eb3 100644 --- a/tests/library/Class/TypeDocTest.php +++ b/tests/library/Class/TypeDocTest.php @@ -21,6 +21,7 @@ class TypeDocTest extends Storm_Test_ModelTestCase { public function setUp() { + Class_CodifTypeDoc::beVolatile(); $this->cosmo_types = Class_CosmoVar::getLoader() ->newInstanceWithId('types_docs') ->setListe("0:non identifié\r\n1:livres\r\n2:périodiques"); @@ -86,6 +87,7 @@ class TypeDocTest extends Storm_Test_ModelTestCase { /** @test */ function saveNewInstancesVideoAndCDShouldUpdateTypesDocsVar() { + Class_TypeDoc::getLoader() ->newInstance() ->setLabel('videos') -- GitLab