From 191f151ae6233f78a4103e6f589baa60aa239a7a Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@git-test.afi-sa.fr>
Date: Sat, 22 Sep 2012 13:57:10 +0000
Subject: [PATCH] =?UTF-8?q?Article:=20s=C3=A9lection=20et=20sauvegarde=20d?=
 =?UTF-8?q?u=20lieu=20dans=20le=20formulaire?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../admin/views/scripts/cms/newsform.phtml    |  2 +-
 library/Class/Article.php                     | 48 ++++++++++---------
 .../admin/controllers/CmsControllerTest.php   | 20 ++++++--
 3 files changed, 43 insertions(+), 27 deletions(-)

diff --git a/application/modules/admin/views/scripts/cms/newsform.phtml b/application/modules/admin/views/scripts/cms/newsform.phtml
index 889934f5dbf..ba42fff5f6b 100644
--- a/application/modules/admin/views/scripts/cms/newsform.phtml
+++ b/application/modules/admin/views/scripts/cms/newsform.phtml
@@ -133,7 +133,7 @@ Class_ScriptLoader::getInstance()
 			<tr>
 				<td><?php echo $this->traduire('Lieu'); ?></td>
         <td><?php echo $this->formSelect('id_lieu', 
-																				 null, 
+																				 $this->article->getIdLieu(), 
 																				 null, 
 																				 $this->combo_lieu_options); ?></td>
 			</tr>
diff --git a/library/Class/Article.php b/library/Class/Article.php
index 5b37a8d1677..52decd951cb 100644
--- a/library/Class/Article.php
+++ b/library/Class/Article.php
@@ -387,33 +387,36 @@ class Class_Article extends Storm_Model_Abstract {
 	protected $_table_name = 'cms_article';
 	protected $_table_primary = 'ID_ARTICLE';
 
-	protected $_has_many = array('traductions' => array('model' => 'Class_Article',
-																											'role' => 'article_original',
-																											'dependents' => 'delete'),
+	protected $_has_many = ['traductions' => ['model' => 'Class_Article',
+																						'role' => 'article_original',
+																						'dependents' => 'delete'],
 
-															 'avis_users' => array('model' => 'Class_Avis',
-																										 'role' => 'article',
-																										 'dependents' => 'delete',
-																										 'order' => 'date_avis desc'));
+													'avis_users' => ['model' => 'Class_Avis',
+																					 'role' => 'article',
+																					 'dependents' => 'delete',
+																					 'order' => 'date_avis desc']];
 
-	protected $_belongs_to = array('categorie' => array('model' => 'Class_ArticleCategorie',
-																											 'referenced_in' => 'id_cat'),
+	protected $_belongs_to = ['categorie' => ['model' => 'Class_ArticleCategorie',
+																						'referenced_in' => 'id_cat'],
 
-																 'article_original' => array('model' => 'Class_Article',
-																														 'referenced_in' => 'parent_id'),
-																 'bib' => array('through' => 'categorie')
-													);
+														'article_original' => ['model' => 'Class_Article',
+																									 'referenced_in' => 'parent_id'],
 
+														'bib' => ['through' => 'categorie'],
 
-	protected $_overrided_attributes = array('id',
-																					  'parent_id',
-																					  'article_original',
-																					  'langue',
-																					  'titre',
-																					  'description',
-																					  'contenu');
+														'lieu' => ['model' => 'Class_Lieu',
+																			 'referenced_in' => 'id_lieu'] ];
 
-	protected $_default_attribute_values = array(
+
+	protected $_overrided_attributes = ['id',
+																			'parent_id',
+																			'article_original',
+																			'langue',
+																			'titre',
+																			'description',
+																			'contenu'];
+
+	protected $_default_attribute_values = [
 																					'titre' => '',
 																					'description' => '',
 																					'contenu' => '',
@@ -428,7 +431,8 @@ class Class_Article extends Storm_Model_Abstract {
 																					'date_maj' => '',
 																					'date_creation' => '',
 																					'status' => self::STATUS_DRAFT,
-																				);
+																					'id_lieu' => 0
+																				];
 
 	/**
 	 * @return ArticleLoader
diff --git a/tests/application/modules/admin/controllers/CmsControllerTest.php b/tests/application/modules/admin/controllers/CmsControllerTest.php
index a8fdbb44c69..ea4f09d585e 100644
--- a/tests/application/modules/admin/controllers/CmsControllerTest.php
+++ b/tests/application/modules/admin/controllers/CmsControllerTest.php
@@ -226,14 +226,14 @@ class CmsControllerArticleConcertAsAdminPortailEditActionTest extends CmsControl
 
 
 	/** @test */
-	public function selectIdLieuShouldContainsAucun() {
-		$this->assertXPath('//select[@name="id_lieu"]//option[@label="Aucun"][@value="0"]');		
+	public function selectIdLieuShouldContainsAucunAndBeSelected() {
+		$this->assertXPath('//select[@name="id_lieu"]//option[@selected="selected"][@label="Aucun"][@value="0"]');		
 	}
 
 
 	/** @test */
 	public function selectIdLieuShouldContainsBonlieu() {
-		$this->assertXPath('//select[@name="id_lieu"]//option[@label="Bonlieu"][@value="3"]');		
+		$this->assertXPath('//select[@name="id_lieu"]//option[not(@selected)][@label="Bonlieu"][@value="3"]');		
 	}
 
 
@@ -453,7 +453,8 @@ class CmsControllerArticleConcertEditActionPostTest extends CmsControllerTestCas
 									'events_debut' => '02/03/2011',
 									'events_fin' => '05/03/2011',
 									'contenu' => 'Ici: <img src="../../images/bonlieu.jpg" />',
-									'description' => 'Affiche: <img src="http://localhost' . BASE_URL . '/images/concert.jpg" />');
+									'description' => 'Affiche: <img src="http://localhost' . BASE_URL . '/images/concert.jpg" />',
+									'id_lieu' => 3);
 
 		$this
 			->getRequest()
@@ -543,6 +544,17 @@ class CmsControllerArticleConcertEditActionPostTest extends CmsControllerTestCas
 	function categorieShouldBeEvenements() {
 		$this->assertEquals($this->cat_evenements, $this->concert->getCategorie());
 	}
+
+	
+	/** @test */
+	public function lieuShouldBeBonlieu() {
+		$this->assertEquals($this->lieu_bonlieu, $this->concert->getLieu());
+	}
+
+	/** @test */
+	public function comboLieuShouldHaveOptionBonlieuSelected() {
+		$this->assertXPath('//select[@name="id_lieu"]//option[@selected="selected"][@label="Bonlieu"][@value="3"]');		
+	}
 }
 
 
-- 
GitLab