diff --git a/library/Class/Article.php b/library/Class/Article.php index c37c723444c415e63867d0f2a3fbabbaa4866e32..17c173ce8b081036b2a5eed230acb936af28387a 100644 --- a/library/Class/Article.php +++ b/library/Class/Article.php @@ -463,12 +463,12 @@ class ArticleLoader extends Storm_Model_Loader { public function filterByDay($day, $articles) { $day_num = date("w", $day); return array_filter($articles, - function($event) use ($day_num) { - $pick_day_as_array = $event->getPickDayAsArray(); - if(empty($pick_day_as_array) || in_array($day_num, $pick_day_as_array)) - return $event; - }); - + function($event) use ($day_num) + { + $pick_day_as_array = $event->getPickDayAsArray(); + if(empty($pick_day_as_array) || in_array($day_num, $pick_day_as_array)) + return $event; + }); } diff --git a/tests/application/modules/opac/controllers/CmsControllerTest.php b/tests/application/modules/opac/controllers/CmsControllerTest.php index 740eff06949c880736608fc696d25d18c13e6c3f..f15021f7e5becf10a410dfc5141a67bc4a70751d 100644 --- a/tests/application/modules/opac/controllers/CmsControllerTest.php +++ b/tests/application/modules/opac/controllers/CmsControllerTest.php @@ -44,30 +44,30 @@ class CmsControllerRssNoProfileTest extends AbstractControllerTestCase { class CmsControllerdCalendarRssWithProfileAndArticleTest -extends AbstractControllerTestCase { + extends AbstractControllerTestCase { /** * @param Class_Profil $profil */ protected function _initProfilHook($profil) { $profil->setCfgAccueil( - array( - 'modules' => array( - '1' => array( - 'division' => '1', - 'type_module' => 'NEWS', - 'preferences' => array( - 'titre' => 'Les dernières nouvelles', - 'rss_avis' => true, - 'type_aff' => 2, - 'display_order' => 'Random', - 'nb_aff' => 2, - 'nb_analyse' => 5 - ) - ) - ), - 'options' => array() - ) - ); + array( + 'modules' => array( + '1' => array( + 'division' => '1', + 'type_module' => 'NEWS', + 'preferences' => array( + 'titre' => 'Les dernières nouvelles', + 'rss_avis' => true, + 'type_aff' => 2, + 'display_order' => 'Random', + 'nb_aff' => 2, + 'nb_analyse' => 5 + ) + ) + ), + 'options' => array() + ) + ); } public function setUp() { @@ -76,19 +76,19 @@ extends AbstractControllerTestCase { CmsController::setTimeSource(new TimeSourceForTest('2014-12-01 14:00:00')); Class_Calendar::setTimeSource(new TimeSourceForTest('2014-12-01 14:00:00')); $fete =$this->fixture('Class_Article', - ['id' => 1, - 'titre' => 'La fête de la banane', - 'contenu' => 'Une fête qui glisse !<img src="'.BASE_URL.'/image/banane.jpg"/>']) + ['id' => 1, + 'titre' => 'La fête de la banane', + 'contenu' => 'Une fête qui glisse !<img src="'.BASE_URL.'/image/banane.jpg"/>']) ->setDateMaj('2011-11-11 11:11:11') ->setEventsDebut('2009-09-09 09:09:09'); $fete_frite=$this->fixture('Class_Article', - ['id' => 2, - 'titre' => 'La fête de la frite', - 'contenu' => 'Une fête qui sent !', - 'debut' => '2012-12-12 12:12:12', - 'events_debut' => '2012-12-13', - 'all_day' => true]); + ['id' => 2, + 'titre' => 'La fête de la frite', + 'contenu' => 'Une fête qui sent !', + 'debut' => '2012-12-12 12:12:12', + 'events_debut' => '2012-12-13', + 'all_day' => true]); Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Article') ->whenCalled('getArticlesByPreferences') @@ -182,24 +182,24 @@ class CmsControllerRssWithProfileAndArticle extends AbstractControllerTestCase { */ protected function _initProfilHook($profil) { $profil->setCfgAccueil( - array( - 'modules' => array( - '1' => array( - 'division' => '1', - 'type_module' => 'NEWS', - 'preferences' => array( - 'titre' => 'Les dernières nouvelles', - 'rss_avis' => true, - 'type_aff' => 2, - 'display_order' => 'Random', - 'nb_aff' => 2, - 'nb_analyse' => 5 - ) - ) - ), - 'options' => array() - ) - ); + array( + 'modules' => array( + '1' => array( + 'division' => '1', + 'type_module' => 'NEWS', + 'preferences' => array( + 'titre' => 'Les dernières nouvelles', + 'rss_avis' => true, + 'type_aff' => 2, + 'display_order' => 'Random', + 'nb_aff' => 2, + 'nb_analyse' => 5 + ) + ) + ), + 'options' => array() + ) + ); } @@ -209,15 +209,15 @@ class CmsControllerRssWithProfileAndArticle extends AbstractControllerTestCase { Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Article') ->whenCalled('getArticlesByPreferences') ->answers(array( - Class_Article::getLoader() - ->newInstanceWithId(1) - ->setTitre('La fête de la banane') - ->setContenu('Une fête qui glisse !'), - Class_Article::getLoader() - ->newInstanceWithId(2) - ->setTitre('La fête de la frite') - ->setContenu('Une fête qui sent !'), - )); + Class_Article::getLoader() + ->newInstanceWithId(1) + ->setTitre('La fête de la banane') + ->setContenu('Une fête qui glisse !'), + Class_Article::getLoader() + ->newInstanceWithId(2) + ->setTitre('La fête de la frite') + ->setContenu('Une fête qui sent !'), + )); $this->dispatch('cms/rss?id_profil=2&id_module=1'); @@ -265,100 +265,103 @@ class CmsControllerRssWithProfileAndArticle extends AbstractControllerTestCase { abstract class AbstractCmsControllerArticleViewByDateTest extends AbstractControllerTestCase { + protected $_article_loader; protected $display_mode = "Title"; protected $display_order = "EventDebut"; + public function dispatchViewByDate() { $this->fixturesForDispatch(); $this->dispatch('/cms/articleviewbydate?d=2011-09-03&id_module=8&id_profil=2&select_id_categorie=all', true); } - protected function fixturesForDispatch() { - Class_Profil::getCurrentProfil() - ->setCfgAccueil( - ['modules' => - ['8' => ['division' => '0', - 'type_module' => 'CALENDAR', - 'preferences' => ['display_mode' => $this->display_mode, - 'display_order' => $this->display_order]], - 'options' =>[]]] - ); - - Class_AdminVar::newInstanceWithId('WORKFLOW', ['valeur' => '']); - $this->fixture('Class_ArticleCategorie', - ['id' => 1, - 'libelle' => 'Alimentaire', - 'bib'=> $this->fixture('Class_Bib', - ['id' => 1, - 'libelle' => 'Bonlieu' - ]) - ]); - $articles = [ - $this->fixture('Class_Article', - ['id' => 1, - 'titre' => 'La fête de la banane', - 'date_creation' => '2011-01-15', - 'contenu' => 'Pas qu\'à moitié {FIN} Une fête qui glisse !', - 'events_debut' => '2011-09-03', - 'events_fin' => '2011-10-03', - 'categorie' => Class_ArticleCategorie::find(1) - ]), - - - $this->fixture('Class_Article', - ['id' => 9, - 'titre' =>'La fête de la frite', - 'date_creation' => '2011-01-20', - 'contenu' => 'test', - 'events_debut' => '2011-09-03', - 'events_fin' => '2011-09-03', - 'categorie' => $this->fixture('Class_ArticleCategorie', - ['id' => 12, - 'libelle' => 'Alimentaire'])]) - - ]; - - $articles = Class_Article::getLoader()->sortArticles($articles, $this->display_order); - - $prefs_module_calendar = ['titre' => "Calendrier des animations", - 'event_date' => '2011-09-03', - 'id_bib' => null, - 'id_categorie' => '', - 'events_only' => true, - 'published' => false, - 'display_next_event' => 1, - 'nb_events' => 3, - 'display_mode' => $this->display_mode, - 'display_order' => $this->display_order, - 'display_cat_select' => false, - 'display_event_info'=>false, - 'rss_avis' => false, - 'boite' => null - ]; - - if ($this->display_mode == "Summary") - $prefs_module_calendar['summary_content']="Summary"; - - $this->_article_loader = Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Article') - ->whenCalled('getArticlesByPreferences') - ->with($prefs_module_calendar) - ->answers($articles) - - ->whenCalled('getArticlesByPreferences') - ->with([ - 'event_date' => '2011-09-03', - 'events_only' => true, - 'published' => false, - 'id_bib' => null, - 'display_mode' => $this->display_mode, - 'display_order' => $this->display_order - ]) - ->answers($articles) - - ->whenCalled('getArticlesByPreferences') - ->answers($articles); + + protected function fixturesForDispatch() { + Class_Profil::getCurrentProfil() + ->setCfgAccueil( + ['modules' => + ['8' => ['division' => '0', + 'type_module' => 'CALENDAR', + 'preferences' => ['display_mode' => $this->display_mode, + 'display_order' => $this->display_order]], + 'options' =>[]]] + ); + + Class_AdminVar::newInstanceWithId('WORKFLOW', ['valeur' => '']); + $this->fixture('Class_ArticleCategorie', + ['id' => 1, + 'libelle' => 'Alimentaire', + 'bib'=> $this->fixture('Class_Bib', + ['id' => 1, + 'libelle' => 'Bonlieu' + ]) + ]); + $articles = [ + $this->fixture('Class_Article', + ['id' => 1, + 'titre' => 'La fête de la banane', + 'date_creation' => '2011-01-15', + 'contenu' => 'Pas qu\'à moitié {FIN} Une fête qui glisse !', + 'events_debut' => '2011-09-03', + 'events_fin' => '2011-10-03', + 'categorie' => Class_ArticleCategorie::find(1) + ]), + + + $this->fixture('Class_Article', + ['id' => 9, + 'titre' =>'La fête de la frite', + 'date_creation' => '2011-01-20', + 'contenu' => 'test', + 'events_debut' => '2011-09-03', + 'events_fin' => '2011-09-03', + 'categorie' => $this->fixture('Class_ArticleCategorie', + ['id' => 12, + 'libelle' => 'Alimentaire'])]) + + ]; + + $articles = Class_Article::getLoader()->sortArticles($articles, $this->display_order); + + $prefs_module_calendar = ['titre' => "Calendrier des animations", + 'event_date' => '2011-09-03', + 'id_bib' => null, + 'id_categorie' => '', + 'events_only' => true, + 'published' => false, + 'display_next_event' => 1, + 'nb_events' => 3, + 'display_mode' => $this->display_mode, + 'display_order' => $this->display_order, + 'display_cat_select' => false, + 'display_event_info'=>false, + 'rss_avis' => false, + 'boite' => null + ]; + + if ($this->display_mode == "Summary") + $prefs_module_calendar['summary_content']="Summary"; + + $this->_article_loader = Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Article') + ->whenCalled('getArticlesByPreferences') + ->with($prefs_module_calendar) + ->answers($articles) + + ->whenCalled('getArticlesByPreferences') + ->with([ + 'event_date' => '2011-09-03', + 'events_only' => true, + 'published' => false, + 'id_bib' => null, + 'display_mode' => $this->display_mode, + 'display_order' => $this->display_order + ]) + ->answers($articles) + + ->whenCalled('getArticlesByPreferences') + ->answers($articles); } } @@ -397,11 +400,13 @@ class CmsControllerArticleViewByDateOnMonthTest extends AbstractControllerTestCa class CmsControllerArticleViewByDatePickDayTest extends AbstractCmsControllerArticleViewByDateTest { + public function setUp() { parent::setUp(); $this->display_mode='Title'; } + /** @test */ public function feteDeLaFriteShouldBePresentOnSaturday() { parent::fixturesForDispatch(); @@ -440,9 +445,11 @@ class CmsControllerArticleViewByDatePickDayTest extends AbstractCmsControllerArt $this->assertNotXpathContentContains('//ul//li//a', 'La fête de la frite'); } - } + + + class CmsControllerArticleViewByDateTest extends AbstractCmsControllerArticleViewByDateTest { public function setUp() { parent::setUp(); @@ -450,6 +457,7 @@ class CmsControllerArticleViewByDateTest extends AbstractCmsControllerArticleVie $this->dispatchViewByDate(); } + /** @test */ public function feteDeLaBananeTitleShouldBePresent() { $this->assertXpathContentContains('//ul//li//a', 'La fête de la banane'); @@ -506,14 +514,14 @@ class CmsControllerProfilDivisionTest extends AbstractCmsControllerArticleViewBy 'select_annexe' => 'on']], '10' => ['division' => '3', - 'type_module' => 'NEWS', - 'preferences' => ['titre' => 'Articles']], + 'type_module' => 'NEWS', + 'preferences' => ['titre' => 'Articles']], '11' => ['division' => '1', - 'type_module' => 'LOGIN', - 'preferences' => ['lien_connexion' => 'Par ici la connexion']], + 'type_module' => 'LOGIN', + 'preferences' => ['lien_connexion' => 'Par ici la connexion']], - ]]; + ]]; Class_Profil::getCurrentProfil()->setCfgAccueil($cfg_accueil_jeunesse); $this->dispatch('/cms/articleviewbydate?d=2011-09-03&id_module=8&id_profil=2&select_id_categorie=all', true); } @@ -601,13 +609,13 @@ class CmsControllerArticleViewByDateWithOnlyArticlePortailTest extends AbstractC $this->_article_loader = Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Article') ->whenCalled('getArticlesByPreferences') ->answers([Class_Article::newInstanceWithId(1, - ['titre' => 'La fête de la frite', - 'content' => '', - 'events_debut' => '2011-09-03', - 'events_fin' => '2011-09-03', - 'categorie' => Class_ArticleCategorie::newInstanceWithId(1, - ['libelle' => 'Alimentaire'])]) - ]); + ['titre' => 'La fête de la frite', + 'content' => '', + 'events_debut' => '2011-09-03', + 'events_fin' => '2011-09-03', + 'categorie' => Class_ArticleCategorie::newInstanceWithId(1, + ['libelle' => 'Alimentaire'])]) + ]); $this->dispatch('/cms/articleviewbydate?d=2011-09-03&id_module=8&id_profil=2&select_id_categorie=all', true); } @@ -808,7 +816,7 @@ abstract class CmsControllerWithFeteDeLaFriteTestCase extends AbstractController ->setValeur(0); $bonlieu = $this->fixture('Class_Bib', ['id' => 1, - 'libelle' => 'Bonlieu']); + 'libelle' => 'Bonlieu']); $annecy = $this->fixture('Class_Lieu', ['id' => '4156465', @@ -821,15 +829,15 @@ abstract class CmsControllerWithFeteDeLaFriteTestCase extends AbstractController 'bib' => $bonlieu ]); $avis_mimi = $this->fixture('Class_Avis' , ['id' => 34, - 'auteur' => $this->fixture('Class_Users' , ['id'=> 98, - 'pseudo' => 'Mimi', - 'password' => 'toto', - 'login' => 'mimi']), - 'date_avis' => '2012-02-05', - 'note'=>4, - 'entete' => "Hmmm", - 'avis'=> 'ça a l\'air bon' - ]); + 'auteur' => $this->fixture('Class_Users' , ['id'=> 98, + 'pseudo' => 'Mimi', + 'password' => 'toto', + 'login' => 'mimi']), + 'date_avis' => '2012-02-05', + 'note'=>4, + 'entete' => "Hmmm", + 'avis'=> 'ça a l\'air bon' + ]); $avis_mimi->beWrittenByAbonne(); @@ -1381,14 +1389,14 @@ abstract class CmsControllerListTestCase extends AbstractControllerTestCase { */ protected function _createFeteDeLaFriteAndMatsumotoArticles() { return array( - Class_Article::newInstanceWithId(224) - ->setTitre('La fête de la frite') - ->setDescription('Ce soir ça frite !') - ->setContenu('<div>Une fête appétissante</div>'), - Class_Article::newInstanceWithId(225) - ->setTitre('Dédicaces de Leiji Matsumoto sama') - ->setContenu('<div>Albaaaaaator, albaaaator</div>') - ); + Class_Article::newInstanceWithId(224) + ->setTitre('La fête de la frite') + ->setDescription('Ce soir ça frite !') + ->setContenu('<div>Une fête appétissante</div>'), + Class_Article::newInstanceWithId(225) + ->setTitre('Dédicaces de Leiji Matsumoto sama') + ->setContenu('<div>Albaaaaaator, albaaaator</div>') + ); } /** @@ -1423,8 +1431,8 @@ abstract class CmsControllerListTestCase extends AbstractControllerTestCase { /** @test */ public function workflowAndTranslationFilterShouldBeCalled() { $this->assertTrue( - Class_Article::getLoader()->methodHasBeenCalled('filterByLocaleAndWorkflow') - ); + Class_Article::getLoader()->methodHasBeenCalled('filterByLocaleAndWorkflow') + ); } } @@ -1496,15 +1504,15 @@ class CmsControllerArticleViewSelectionFromHorizontalMenuBoxTest extends Abstrac 'picto' => 'bookmark.png', 'preferences' => [], 'sous_menus' => [ - ['type_menu' => 'NEWS', - 'libelle' => 'Nouvelles', - 'picto' => 'vide.gif', - 'preferences' => ['titre' => 'Nouvelles', - 'id_items' => 2, - 'display_order' => 'Selection']] - ] - ]] - ]]; + ['type_menu' => 'NEWS', + 'libelle' => 'Nouvelles', + 'picto' => 'vide.gif', + 'preferences' => ['titre' => 'Nouvelles', + 'id_items' => 2, + 'display_order' => 'Selection']] + ] + ]] + ]]; $this->fixture('Class_Profil', ['id' => 3,