diff --git a/application/modules/admin/controllers/TypeDocsController.php b/application/modules/admin/controllers/TypeDocsController.php index c6c47b6e6c250eb8c56460a7ae6c49f1c75d9279..f64ebd2234ec193474add531fc8e4c868050e4d1 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 d35369a49a7b9956d69813abd4aaa0049ad9b50a..ef0abd8456b7b69d47a0762937e81af07758f9c7 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 dc993df301343c5ba2ea08d45c2d724ca02484c8..0066954a361e3470224072217dc8f945973ede0f 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 1c8723d3f174a7257080e992d7e6a5e1be2b47a1..10bc9de27cc6229a40a09533a531651c0e701368 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 1dab68c69e4df4a90e06e4a98628320fbb93c49d..f9867007a1a532deb8b2c0b4f189dc3a26166f6e 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 c56774585e94c0e46f76f402a3216c63f5d25b8c..455a3a73f779a8d19a626bed1a124dbec4bc30bf 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 9b141fc56c389f3b859803cdef5bb8cba07d9acf..2c5eeb23912344eded68626484868f4f1f25b58a 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 e4fa875920b6c67f1e906e9a5ea324e59ca6de47..1188e521eb3205ffc68d727f0b2e0ba501918d4d 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')