From 939a86b474923430858ba96fe7f7d28bdc142936 Mon Sep 17 00:00:00 2001
From: gloas <gloas@git-test.afi-sa.fr>
Date: Wed, 18 Dec 2013 14:28:31 +0000
Subject: [PATCH] Class_Article: hasEventForMonth cas no article

---
 library/Class/Article.php           | 31 ++++++++++++++++++++++++++++-
 tests/library/Class/ArticleTest.php | 17 ++++++++++++++++
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/library/Class/Article.php b/library/Class/Article.php
index 0fd9cd451bf..8d4bd17770e 100644
--- a/library/Class/Article.php
+++ b/library/Class/Article.php
@@ -1132,7 +1132,7 @@ class Class_Article extends Storm_Model_Abstract {
 	
 
 	public function getIcoInfo() {
-			return 'ico/liste.gif';
+		return 'ico/liste.gif';
 	}
 
 
@@ -1169,6 +1169,35 @@ class Class_Article extends Storm_Model_Abstract {
 	public function getLieuLibelle() {
 		return $this->getLieu() ? $this->getLieu()->getLibelle() : '' ;
 	}
+
+	
+	public static function hasEventForMonth($month) {
+		return 0 < count(array_merge(Class_Article::getArticlesByPreferences(['event_date' => 
+																																					date("d-m-Y", 
+																																							 mktime(0,
+																																											0,
+																																											0, 
+																																											$month, 
+																																											1, 
+																																											(date('m')>$month) ? date('Y') + 1 : date('Y') )),
+																																					'published' => true,
+																																					'events_only'=>'true',
+																																					'status' => 3]), 
+																 Class_Article::getArticlesByPreferences(['event_date' => 
+																																					date("d-m-Y", 
+																																							 mktime(0,
+																																											0, 
+																																											0, 
+																																											$month + 1, 
+																																											0, 
+																																											(date('m')>$month) 
+																																											? date('Y') +1 
+																																											: date('Y') )),
+																																					'published' => true,
+																																					'events_only'=>'true',
+																																					'status' => 3])));
+	}
+	
 }
 
 ?>
\ No newline at end of file
diff --git a/tests/library/Class/ArticleTest.php b/tests/library/Class/ArticleTest.php
index c9f4af9a7c9..5cd8a6483a6 100644
--- a/tests/library/Class/ArticleTest.php
+++ b/tests/library/Class/ArticleTest.php
@@ -951,4 +951,21 @@ class ArticleTestFixtures {
 																		));
 	}
 
+}
+
+
+Class EventsByMonthTest extends  Storm_Test_ModelTestCase {
+	public function setup() {
+		parent::setup();
+		
+		Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Article')
+			->whenCalled('findAll')
+			->answers([]);
+
+	}
+
+	/** @test **/
+	public function fevrierShouldNotContainsEvents() {
+		$this->assertFalse(Class_Article::hasEventForMonth(2));
+	}
 }
\ No newline at end of file
-- 
GitLab