From ada4d21120d7427e570e410392b73b7300a91dd7 Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@git-test.afi-sa.fr> Date: Thu, 28 Nov 2013 09:59:41 +0000 Subject: [PATCH] =?UTF-8?q?Refacto=20tests=20CMS=20Le=20formulaire=20de=20?= =?UTF-8?q?duplication=20d'un=20article=20pointe=20sur=20l'action=20newsad?= =?UTF-8?q?d=20pour=20rentrer=20dans=20le=20flux=20d'ajout=20=C3=A0=20la?= =?UTF-8?q?=20premi=C3=A8re=20soumission?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controllers/CmsController.php | 11 +- .../admin/views/scripts/cms/newsform.phtml | 2 +- .../admin/controllers/CmsControllerTest.php | 116 +++++++++--------- 3 files changed, 67 insertions(+), 62 deletions(-) diff --git a/application/modules/admin/controllers/CmsController.php b/application/modules/admin/controllers/CmsController.php index 571950ebae7..ab181289fd9 100644 --- a/application/modules/admin/controllers/CmsController.php +++ b/application/modules/admin/controllers/CmsController.php @@ -156,15 +156,20 @@ class Admin_CmsController extends ZendAfi_Controller_Action { public function newsduplicateAction() { - xdebug_break(); $category = $this->getCategoryAndSetComboCat(); - $duplicated_article = Class_Article::getLoader()->find($this->_getParam('id_article')); + $duplicated_article = Class_Article::find($this->_getParam('id_article')); $new_article = $duplicated_article->copy(); $this->view->article = $new_article; - $this->view->titre = 'Ajouter un article'; + $this->view->titre = $this->_('Dupliquer l\'article: ').$new_article->getTitre(); $this->view->combo_lieu_options = $this->comboLieuOptions(); + $this->view->form_action = $this->view->url(['module' => 'admin', + 'controller' => 'cms', + 'action' => 'newsadd', + 'id_cat' => $new_article->getIdCat()], + null, + true); } diff --git a/application/modules/admin/views/scripts/cms/newsform.phtml b/application/modules/admin/views/scripts/cms/newsform.phtml index a4a3737d6fc..2471b8f4c95 100644 --- a/application/modules/admin/views/scripts/cms/newsform.phtml +++ b/application/modules/admin/views/scripts/cms/newsform.phtml @@ -9,7 +9,7 @@ $currentYear--; <form id="news_form" class="form" name="form" - action="<?php echo $this->url(); ?>" + action="<?php echo $this->form_action ? $this->form_action : $this->url(); ?>" method="post"> <span class="error"><?php echo implode('<br/>', $this->article->getErrors()); ?></span> diff --git a/tests/application/modules/admin/controllers/CmsControllerTest.php b/tests/application/modules/admin/controllers/CmsControllerTest.php index 04b7ae6099e..ebf9fd0b411 100644 --- a/tests/application/modules/admin/controllers/CmsControllerTest.php +++ b/tests/application/modules/admin/controllers/CmsControllerTest.php @@ -20,60 +20,7 @@ */ require_once 'AdminAbstractControllerTestCase.php'; -abstract class CmsControllerSimpleUserTestCase extends AbstractControllerTestCase { - protected $_admin_bib; - protected $_concert; - public function setUp() { - parent::setUp(); - $this->setupBib(); - $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]); - ZendAfi_Auth::getInstance()->logUser($this->_admin_bib); - $this->setupArticle(); - } - - - public function setupBib() { - $this->annecy = $this->fixture('Class_Bib', ['id' => 2, - 'id_zone' => 4, - 'libelle' => 'Annecy' - ]); - $this->cran_gevrier = $this->fixture('Class_Bib', ['id' => 4,'id_zone' => 4, - 'libelle' => 'Cran-Gevrier', - 'article_categories' => []]); - } - - function assertInputValueEquals($input_name, $value) { - $this->assertXPath(sprintf('//form[@id="news_form"]//input[@name="%s"][@value="%s"]', - $input_name, $value)); - } - - public function setupArticle() { - - $cat_a_la_une = $this->fixture('Class_ArticleCategorie',['id' => 23, - 'libelle' => 'A la Une']); - $this->_concert = $this->fixture('Class_Article',['id' => 8080, - 'titre' => 'Concert', - 'categorie' => $cat_a_la_une, - 'auteur' => $this->_admin_bib, - 'description' => 'Venez nombreux ici: <img src="'.BASE_URL.'/images/bonlieu.jpg" />', - 'contenu' => 'Ã Bonlieu. <img src="'.BASE_URL.'/images/truffaz.jpg" />', - 'debut' => '2011-03-20', - 'fin' => '2011-03-28', - 'events_debut' => '2011-03-27', - 'events_fin' => '2011-03-28', - 'cacher_titre' => 1, - 'langue' => 'fr', - 'tags' => 'concert;jazz', - 'avis' => true]); - } -} abstract class CmsControllerTestCase extends Admin_AbstractControllerTestCase { /** @var Class_Article */ protected $concert; @@ -137,7 +84,6 @@ abstract class CmsControllerTestCase extends Admin_AbstractControllerTestCase { public function setupDomaines() { - $this->domaine_histoire = Class_Catalogue::newInstanceWithId(10, ['libelle' => 'Histoire', 'sous_domaines' => [$this->domaine_art = Class_Catalogue::newInstanceWithId(11, @@ -169,6 +115,7 @@ abstract class CmsControllerTestCase extends Admin_AbstractControllerTestCase { return $this; } + public function setupBib() { Class_Bib::beVolatile(); $this->annecy = Class_Bib::newInstanceWithId(1, ['id_zone' => 4, @@ -184,9 +131,8 @@ abstract class CmsControllerTestCase extends Admin_AbstractControllerTestCase { $this->cran_gevrier->save(); } + public function setupArticles() { - // Class_ArticleCategorie::beVolatile(); -// Class_Article::beVolatile(); $cat_a_la_une = Class_ArticleCategorie::newInstanceWithId(23, ['libelle' => 'A la Une']); $this->annecy->setArticleCategories([$cat_a_la_une]); $this->cat_evenements = Class_ArticleCategorie::newInstanceWithId(34, @@ -379,6 +325,8 @@ class CmsControllerArticleConcertAsReferentEditActionTest extends CmsControllerA } + + class CmsControllerArticleWithoutCategoryAddActionTest extends CmsControllerTestCase { public function setUp() { parent::setUp(); @@ -393,24 +341,72 @@ class CmsControllerArticleWithoutCategoryAddActionTest extends CmsControllerTest -class CmsControllerArticleWithoutCategoryDuplicateActionTest extends CmsControllerSimpleUserTestCase { + + +class CmsControllerArticleDuplicateActionTest extends AbstractControllerTestCase { + protected + $_admin_bib, + $_concert; + public function setUp() { parent::setUp(); + + $this->_admin_bib = $this->fixture('Class_Users',['id' => 10, + 'login' => 'AdminBibConnected', + 'bib' => $this->fixture('Class_Bib', ['id' => 2, + 'id_zone' => 4, + 'libelle' => 'Annecy']), + 'role' => 'admin_bib', + 'mail' => 'admin@afi-sa.fr', + 'password' => 'toto', + 'role_level' => ZendAfi_Acl_AdminControllerRoles::ADMIN_BIB]); + ZendAfi_Auth::getInstance()->logUser($this->_admin_bib); + $this->setupArticle(); $this->dispatch('/admin/cms/newsduplicate/id_article/8080/id_cat/23'); } + + public function setupArticle() { + $this->fixture('Class_Article',['id' => 8080, + 'titre' => 'Concert', + 'categorie' => $this->fixture('Class_ArticleCategorie',['id' => 23, + 'libelle' => 'A la Une']), + 'auteur' => $this->_admin_bib, + 'description' => 'Venez nombreux ici: <img src="'.BASE_URL.'/images/bonlieu.jpg" />', + 'contenu' => 'Ã Bonlieu. <img src="'.BASE_URL.'/images/truffaz.jpg" />', + 'debut' => '2011-03-20', + 'fin' => '2011-03-28', + 'events_debut' => '2011-03-27', + 'events_fin' => '2011-03-28', + 'cacher_titre' => 1, + 'langue' => 'fr', + 'tags' => 'concert;jazz', + 'avis' => true]); + } + + /** @test */ function contenuDuplicateShouldContainsVenezNombreux() { $this->assertXPathContentContains('//textarea','Venez nombreux ici',$this->_response->getBody()); } + /** @test */ function eventsFinDuplicateShouldContains20110328() { - $this->assertInputValueEquals('events_fin', '28/03/2011'); + $this->assertXPath('//input[@name="events_fin"][@value="28/03/2011"]'); + } + + /** @test */ + public function formActionShouldBeNewsAddIdCat23() { + $this->assertXPath('//form[contains(@action, "/admin/cms/newsadd/id_cat/23")]'); } + /** @test */ + public function titreShouldBeDupliquerLArticleConcert() { + $this->assertXPathContentContains('//h1', 'Dupliquer l\'article: Concert'); + } } @@ -1207,6 +1203,8 @@ class CmsControllerNewsAddActionWithoutWorkflowTest extends CmsControllerTestCas } + + class CmsControllerArticleVisibilityTest extends CmsControllerTestCase { /** @test */ function makeVisibleShouldRedirectToCategorieEvenements() { @@ -1225,6 +1223,8 @@ class CmsControllerArticleVisibilityTest extends CmsControllerTestCase { } + + class CmsControllerNewsAddActionPostWithoutWorkflowTest extends CmsControllerTestCase { /** @var Class_Article */ protected $_article; -- GitLab