diff --git a/VERSIONS_HOTLINE/81755 b/VERSIONS_HOTLINE/81755 new file mode 100644 index 0000000000000000000000000000000000000000..c4f46a156546aa90fe98a6ec3e3fd519c975c24f --- /dev/null +++ b/VERSIONS_HOTLINE/81755 @@ -0,0 +1 @@ + - ticket #81755 : Agenda : correction du filtrage des événements récurrents \ No newline at end of file diff --git a/application/modules/opac/controllers/CmsController.php b/application/modules/opac/controllers/CmsController.php index 70c434e69b4dc32a3402b9931b9d98509844d2fa..990fd61d4e290410e6043d8cf63bc7941a9fdfee 100644 --- a/application/modules/opac/controllers/CmsController.php +++ b/application/modules/opac/controllers/CmsController.php @@ -71,7 +71,6 @@ class CmsController extends ZendAfi_Controller_Action { $articles = Class_Article::getArticlesByPreferences($preferences); $articles = Class_Article::filterByLocaleAndWorkflow($articles); - $articles = Class_Article::filterByDay(strtotime($this->_getParam('d')), $articles); $articles = Class_Article::groupByBibId($articles); if ((count($articles) == 1) && isset($articles[0])) @@ -273,7 +272,6 @@ class CmsController extends ZendAfi_Controller_Action { protected function _viewArticlesByPreferences($preferences) { $articles = Class_Article::getLoader()->getArticlesByPreferences($preferences); $articles = Class_Article::getLoader()->filterByLocaleAndWorkflow($articles); - $articles = Class_Article::getLoader()->filterByDay(strtotime($this->_getParam('d')), $articles); $this->view->articles = $articles; diff --git a/library/Class/Article.php b/library/Class/Article.php index d6e82d74380a5027ce794656eeff26fb38e4f307..802e1d56f88e99a342963ac078005998010fe7b4 100644 --- a/library/Class/Article.php +++ b/library/Class/Article.php @@ -370,11 +370,10 @@ class ArticleLoader extends Storm_Model_Loader { $articles = $this->_sortArticles( - $this->_filterByCustomFields( - Class_Article::getLoader()->findAll($select), - $this->_custom_fields)); - - + $this->_filterByDay($this->_event_date, + $this->_filterByCustomFields( + Class_Article::getLoader()->findAll($select), + $this->_custom_fields))); if ( ($this->_sort_order == 'Selection') @@ -471,11 +470,11 @@ class ArticleLoader extends Storm_Model_Loader { } - public function filterByDay($day, $articles) { + protected function _filterByDay($day, $articles) { if(!$day) return $articles; - $day_num = date("w", $day); + $day_num = date("w", strtotime($day)); return array_filter($articles, function($event) use ($day_num) { diff --git a/tests/application/modules/opac/controllers/CmsControllerTest.php b/tests/application/modules/opac/controllers/CmsControllerTest.php index de9601ef0bf93a650648b1c378f691bdc582702f..6b862adb24d5f80d63a428890131730f562b1795 100644 --- a/tests/application/modules/opac/controllers/CmsControllerTest.php +++ b/tests/application/modules/opac/controllers/CmsControllerTest.php @@ -404,58 +404,6 @@ class CmsControllerArticleViewByDateOnMonthTest extends AbstractControllerTestCa - -class CmsControllerArticleViewByDatePickDayTest extends AbstractCmsControllerArticleViewByDateTest { - - public function setUp() { - parent::setUp(); - $this->display_mode='Title'; - } - - - /** @test */ - public function feteDeLaFriteShouldBePresentOnSaturday() { - parent::fixturesForDispatch(); - Class_Article::find(9)->setPickDay('6')->save(); - $this->dispatch('/cms/articleviewbydate?d=2011-09-03&id_module=8&id_profil=2&select_id_categorie=all', true); - - $this->assertXpathContentContains('//ul//li//a', 'La fête de la frite'); - } - - - /** @test */ - public function feteDeLaFriteShouldBePresentOnSunday() { - parent::fixturesForDispatch(); - Class_Article::find(9)->setPickDay('0')->save(); - $this->dispatch('/cms/articleviewbydate?d=2011-09-04&id_module=8&id_profil=2&select_id_categorie=all', true); - - $this->assertXpathContentContains('//ul//li//a', 'La fête de la frite'); - } - - - /** @test */ - public function feteDeLaFriteShouldBePresentOnMondayAndSunday() { - parent::fixturesForDispatch(); - Class_Article::find(9)->setPickDay('0,6')->save(); - $this->dispatch('/cms/articleviewbydate?d=2011-09-04&id_module=8&id_profil=2&select_id_categorie=all', true); - - $this->assertXpathContentContains('//ul//li//a', 'La fête de la frite'); - } - - - /** @test */ - public function feteDeLaFriteShouldNotBePresentOnThuesday() { - parent::fixturesForDispatch(); - Class_Article::find(9)->setPickDay('0,1,3,4,5,6')->save(); - $this->dispatch('/cms/articleviewbydate?d=2011-09-06&id_module=8&id_profil=2&select_id_categorie=all', true); - - $this->assertNotXpathContentContains('//ul//li//a', 'La fête de la frite'); - } -} - - - - class CmsControllerArticleViewByDateTest extends AbstractCmsControllerArticleViewByDateTest { public function setUp() { parent::setUp(); diff --git a/tests/library/Class/ArticleLoaderTest.php b/tests/library/Class/ArticleLoaderTest.php index 12a9251597fa0051d0cb0da8a4897817927df113..4ebb6445c88bd68dc5586ef875ac28943fde6572 100644 --- a/tests/library/Class/ArticleLoaderTest.php +++ b/tests/library/Class/ArticleLoaderTest.php @@ -19,10 +19,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -class ArticleLoaderGetArticlesByPreferencesTest extends ModelTestCase { - const WHERE_VISIBLE_CLAUSE = - '((DEBUT IS NULL) OR (DEBUT <= CURDATE())) AND ((FIN IS NULL) OR (FIN >= CURDATE()))'; +abstract class ArticleLoaderGetArticlesByPreferencesTestCase extends ModelTestCase { public function setUp() { $this->select = new Zend_Db_Table_Select(new Storm_Model_Table(array('name' => 'cms_article'))); @@ -35,29 +33,7 @@ class ArticleLoaderGetArticlesByPreferencesTest extends ModelTestCase { $this->tbl_articles ->expects($this->any()) ->method('fetchAll') - ->will($this->returnValue($this->_buildRowset(array(array( - 'ID_ARTICLE' => 23, - 'ID_CAT' => 2, - 'TITRE' => 'Fête de la pomme', - 'DATE_CREATION' => '2011-04-02', - 'DEBUT' => '2011-10-02', - 'FIN' => '2011-10-22', - 'EVENTS_DEBUT' => '2011-10-20'), - - array('ID_ARTICLE' => 18, - 'ID_CAT' => 2, - 'TITRE' => 'Fête de la poire', - 'DATE_CREATION' => '2010-03-25', - 'DEBUT' => '2010-03-25', - 'EVENTS_DEBUT' => '2010-03-25'), - - array('ID_ARTICLE' => 55, - 'ID_CAT' => 4, - 'TITRE' => 'Fête de la banane', - 'DEBUT' => '2011-01-01', - 'DATE_CREATION' => '2011-05-01', - 'EVENTS_DEBUT' => '2011-03-25', - 'EVENTS_FIN' => '2011-03-27'))))); + ->will($this->returnValue($this->_buildRowset($this->_articlesFixtures()))); Class_ArticleCategorie::getLoader() ->newInstanceWithId(2) @@ -70,15 +46,51 @@ class ArticleLoaderGetArticlesByPreferencesTest extends ModelTestCase { } - public function assertSelect($expected) { - $this->assertEquals("SELECT `cms_article`.* FROM `cms_article` ".$expected, - str_replace("\n", "", $this->select->assemble())); + protected function _articlesFixtures() { + return [ + [ + 'ID_ARTICLE' => 23, + 'ID_CAT' => 2, + 'TITRE' => 'Fête de la pomme', + 'DATE_CREATION' => '2011-04-02', + 'DEBUT' => '2011-10-02', + 'FIN' => '2011-10-22', + 'EVENTS_DEBUT' => '2011-10-20'], + + ['ID_ARTICLE' => 18, + 'ID_CAT' => 2, + 'TITRE' => 'Fête de la poire', + 'DATE_CREATION' => '2010-03-25', + 'DEBUT' => '2010-03-25', + 'EVENTS_DEBUT' => '2010-03-25'], + + ['ID_ARTICLE' => 55, + 'ID_CAT' => 4, + 'TITRE' => 'Fête de la banane', + 'DEBUT' => '2011-01-01', + 'DATE_CREATION' => '2011-05-01', + 'EVENTS_DEBUT' => '2011-03-25', + 'EVENTS_FIN' => '2011-03-27'] + ]; } public function getArticles($prefs) { return Class_Article::getLoader()->getArticlesByPreferences($prefs); } +} + + + + +class ArticleLoaderGetArticlesByPreferencesTest extends ArticleLoaderGetArticlesByPreferencesTestCase { + const WHERE_VISIBLE_CLAUSE = + '((DEBUT IS NULL) OR (DEBUT <= CURDATE())) AND ((FIN IS NULL) OR (FIN >= CURDATE()))'; + + public function assertSelect($expected) { + $this->assertEquals("SELECT `cms_article`.* FROM `cms_article` ".$expected, + str_replace("\n", "", $this->select->assemble())); + } /** @test */ @@ -658,4 +670,52 @@ extends ArticleLoaderGroupByBibTestCase { ); } } -?> \ No newline at end of file + + + + +class ArticleLoaderFilterByDayTest extends ArticleLoaderGetArticlesByPreferencesTestCase { + protected function _articlesFixtures() { + return [ + [ + 'ID_ARTICLE' => 23, + 'TITRE' => 'Fête de la pomme', + 'PICK_DAY' => '6'], + + ['ID_ARTICLE' => 18, + 'TITRE' => 'Fête de la poire', + 'PICK_DAY' => '0'], + + ['ID_ARTICLE' => 55, + 'TITRE' => 'Fête de la banane', + 'PICK_DAY' => '0,6'], + + ['ID_ARTICLE' => 57, + 'TITRE' => 'Fête de la frite', + 'PICK_DAY' => '0,1,3,4,5,6'] + ]; + } + + + protected function _getArticlesId($prefs) { + return array_values(array_map(function($a) { return $a->getId(); }, + $this->getArticles($prefs))); + } + + + /** @test */ + public function onSaturdayShouldGetFetePommeBananeFrite() { + $this->assertEquals([23, 55, 57], + $this->_getArticlesId(['event_date' => '2011-09-03'])); + } + + + /** @test */ + public function onSundayShouldGetFetePoireBananeFrite() { + $this->assertEquals([18, 55, 57], + $this->_getArticlesId(['event_date' => '2011-09-04'])); + } +} + + +?>