diff --git a/library/Class/Article.php b/library/Class/Article.php index 27624850f485fd6edd03ddbcc94c9377cd209754..dfbd7694e34e8d1a1a48f1a2fc4ffc7905cee53a 100644 --- a/library/Class/Article.php +++ b/library/Class/Article.php @@ -1171,13 +1171,9 @@ class Class_Article extends Storm_Model_Abstract { public static function hasEventForMonth($month) { - return 0 < count(Class_Article::getLoader()->getArticlesByPreferences(['event_date'=> - date("Y-m", - mktime(0,0,0,$month ,1, - (date('m')>$month) ? date('Y') + 1 : date('Y') )), + return 0 < count(Class_Article::getLoader()->getArticlesByPreferences(['event_date'=>self::getTimeSource()->getMonth($month), 'events_only' => true, - 'status'=>3]) - ); + 'status'=>3])); } } diff --git a/library/Class/TimeSource.php b/library/Class/TimeSource.php index e46ceeebeace5763c007f36aaabe2805a6ce9544..aac46a77b412644c13b847cdb8ed173be2eeebd0 100644 --- a/library/Class/TimeSource.php +++ b/library/Class/TimeSource.php @@ -46,5 +46,11 @@ class Class_TimeSource { $time = $this->time(); return mktime(0, 0, 0, date('n', $time) + $number_of_months, date('j', $time), date('Y', $time)); } + + + public function getMonth($month) { + $time = $this->time(); + return date('Y-m' ,mktime(0,0,0,$month ,1,(date('m')>$month) ? date('Y', $time) + 1 : date('Y', $time) )); + } } ?> \ No newline at end of file diff --git a/tests/library/Class/ArticleTest.php b/tests/library/Class/ArticleTest.php index f8f021105d1dd94b41bd3efab95c14c26b3ab864..1ae833f0dcb8851cf03df0f251f8ace4c894908d 100644 --- a/tests/library/Class/ArticleTest.php +++ b/tests/library/Class/ArticleTest.php @@ -958,9 +958,12 @@ class ArticleTestFixtures { Class EventsByMonthTest extends Storm_Test_ModelTestCase { public function setup() { parent::setup(); - + + $time_source = new TimeSourceForTest('2013-08-19 09:00:00'); + Class_Article::setTimeSource($time_source); + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Article') - ->whenCalled('findAll') + ->whenCalled('getArticlesByPreferences') ->answers([]); } @@ -976,7 +979,10 @@ Class EventsByMonthTest extends Storm_Test_ModelTestCase { Class EventsByMonthWithArticleTest extends Storm_Test_ModelTestCase { public function setup() { parent::setup(); - + + $time_source = new TimeSourceForTest('2013-08-19 09:00:00'); + Class_Article::setTimeSource($time_source); + $this->concert = Class_Article::getLoader() ->newInstanceWithId(4) ->setTitre('Erik Truffaz en concert') @@ -988,8 +994,17 @@ Class EventsByMonthWithArticleTest extends Storm_Test_ModelTestCase { ->setStatus(3); Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Article') - ->whenCalled('findAll') - ->answers([$this->concert]); + ->whenCalled('getArticlesByPreferences') + ->with(['event_date' => '2014-02', + 'events_only' => true, + 'status' => 3]) + ->answers([]) + ->whenCalled('getArticlesByPreferences') + ->with(['event_date' => '2014-03', + 'events_only' => true, + 'status' => 3]) + ->answers([$this->concert]) + ->beStrict(); } @@ -997,32 +1012,12 @@ Class EventsByMonthWithArticleTest extends Storm_Test_ModelTestCase { public function fevrierShouldNotContainsEvents() { $this->assertFalse(Class_Article::hasEventForMonth(2)); } -} -Class EventsByMonthWithArticleInMonthTest extends Storm_Test_ModelTestCase { - public function setup() { - parent::setup(); - - $concert = Class_Article::newInstanceWithId(4) - ->setTitre('Erik Truffaz en concert') - ->setContenu('Ã Bonlieu') - ->setEventsDebut('2014-03-15') - ->setEventsFin('2014-03-15') - ->setStatus(3); - - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Article') - ->whenCalled('findAll') - ->answers([$concert]) - - ->whenCalled('getArticlesByPreferences') - ->answers([$concert]) - ; - - } - /** @test **/ public function marsShouldContainsEventErikTruffazEnConcert() { $this->assertTrue(Class_Article::hasEventForMonth(3)); } -} \ No newline at end of file +} + +?> \ No newline at end of file diff --git a/tests/library/ZendAfi/View/Helper/Accueil/CalendarTest.php b/tests/library/ZendAfi/View/Helper/Accueil/CalendarTest.php index 92d5804e5278c5d4f990d1b97b2a38ff0578cbc9..e18312b94756094be2fd144e4ccdc2e167773064 100644 --- a/tests/library/ZendAfi/View/Helper/Accueil/CalendarTest.php +++ b/tests/library/ZendAfi/View/Helper/Accueil/CalendarTest.php @@ -815,6 +815,4 @@ class CalendarOnJanuaryTest extends CalendarViewHelperTestCase { } - - ?> \ No newline at end of file