From 05ad0cfc405c8c5202cf5fb3aae59f9a0aa94e8c Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@git-test.afi-sa.fr> Date: Mon, 15 Jul 2013 11:03:14 +0000 Subject: [PATCH] Visu articles / calendrier: si que articles portail, n'affiche pas la mention "portail" #9360 --- .../opac/controllers/CmsController.php | 13 ++++-- .../views/scripts/cms/articleviewbydate.phtml | 4 +- library/Class/Article.php | 15 +++---- library/Class/Bib.php | 5 +++ .../opac/controllers/CmsControllerTest.php | 42 ++++++++++++++++++- tests/library/Class/ArticleLoaderTest.php | 16 +++---- 6 files changed, 72 insertions(+), 23 deletions(-) diff --git a/application/modules/opac/controllers/CmsController.php b/application/modules/opac/controllers/CmsController.php index d2bb05f570a..a1c2db279df 100644 --- a/application/modules/opac/controllers/CmsController.php +++ b/application/modules/opac/controllers/CmsController.php @@ -55,11 +55,18 @@ class CmsController extends Zend_Controller_Action { $preferences['id_categorie'] = $id_cat; $articles = Class_Article::getLoader()->getArticlesByPreferences($preferences); - $articles = Class_Article::getLoader()->filterByLocaleAndWorkflow($articles); + $articles = Class_Article::getLoader()->groupByBibId($articles); - $this->view->articles = Class_Article::getLoader()->groupByBib($articles); - + if ((count($articles) == 1) && isset($articles[0])) + $libelle_bibs = [0 => '']; + else { + foreach(array_keys($articles) as $bib_id) + $libelle_bibs[$bib_id] = Class_Bib::find($bib_id)->getLibelle(); + } + + $this->view->articles = $articles; + $this->view->libelle_bibs = $libelle_bibs; } diff --git a/application/modules/opac/views/scripts/cms/articleviewbydate.phtml b/application/modules/opac/views/scripts/cms/articleviewbydate.phtml index 8f1c411e370..ca261d5667e 100644 --- a/application/modules/opac/views/scripts/cms/articleviewbydate.phtml +++ b/application/modules/opac/views/scripts/cms/articleviewbydate.phtml @@ -4,8 +4,8 @@ <div class="calendar_event_list articleviewbydate"> <?php if (0 < count($this->articles)) { ?> <ul> - <?php foreach ($this->articles as $bibliotheque => $articles) { ?> - <li><h2><?php echo ('' == $bibliotheque) ? $this->_('Portail') : $bibliotheque;?></h2> + <?php foreach ($this->articles as $bib_id => $articles) { ?> + <li><h2><?php echo $this->libelle_bibs[$bib_id]; ?></h2> <ul> <?php foreach ($articles as $article) { ?> diff --git a/library/Class/Article.php b/library/Class/Article.php index bd500b913ed..5755587bee8 100644 --- a/library/Class/Article.php +++ b/library/Class/Article.php @@ -313,20 +313,17 @@ class ArticleLoader extends Storm_Model_Loader { * @param array $articles * @return array */ - public static function groupByBib(array $articles) { - $grouped = array(); + public static function groupByBibId(array $articles) { + $grouped = []; foreach ($articles as $article) { - $label = ($bib = $article->getBib()) - ? $bib->getLibelle() - : ''; + $bib_id = ($bib = $article->getBib()) ? $bib->getId() : 0; - if (array_key_exists($label, $grouped)) { - $grouped[$label][] = $article; + if (array_key_exists($bib_id, $grouped)) { + $grouped[$bib_id][] = $article; } else { - $grouped[$label] = array($article); + $grouped[$bib_id] = array($article); } - } return $grouped; diff --git a/library/Class/Bib.php b/library/Class/Bib.php index 39d594031cc..7a4cdb42c51 100644 --- a/library/Class/Bib.php +++ b/library/Class/Bib.php @@ -138,6 +138,11 @@ class Class_Bib extends Storm_Model_Abstract { } + public function isPortail() { + return $this->getId() === 0; + } + + //---------------------------------------------------------------------------- // Rend une bib //---------------------------------------------------------------------------- diff --git a/tests/application/modules/opac/controllers/CmsControllerTest.php b/tests/application/modules/opac/controllers/CmsControllerTest.php index 6fafabd30a3..e3646f91ddf 100644 --- a/tests/application/modules/opac/controllers/CmsControllerTest.php +++ b/tests/application/modules/opac/controllers/CmsControllerTest.php @@ -235,45 +235,53 @@ class CmsControllerArticleViewByDateTest extends AbstractControllerTestCase { )); - $this->dispatch('/cms/articleviewbydate?d=2011-09-03&id_module=8&id_profil=2&select_id_categorie=all'); + $this->dispatch('/cms/articleviewbydate?d=2011-09-03&id_module=8&id_profil=2&select_id_categorie=all', true); } + /** @test */ public function feteDeLaBananeShouldBePresent() { $this->assertXpathContentContains('//ul//li//a', 'La fête de la banane'); } + /** @test */ public function feteDeLaBananeAnchorShouldLinkToActionViewArticleOne() { $this->assertXpathContentContains('//ul//li//a[contains(@href, "cms/articleview/id/1")]', 'La fête de la banane'); } + /** @test */ public function dateForFeteDeLaBananeShouldBePresent() { $this->assertXpathContentContains('//ul//li//span', 'Du 03 septembre au 03 octobre'); } + /** @test */ public function feteDeLaFriteShouldBePresent() { $this->assertXpathContentContains('//ul//li//a', 'La fête de la frite'); } + /** @test */ public function dateForFeteDeLaFriteShouldBePresent() { $this->assertXpathContentContains('//ul//li//span', 'Le 03 septembre'); } + /** @test */ public function bibliothequeLibelleShouldBePresent() { $this->assertXpathContentContains('//h2', 'Bonlieu'); } + /** @test */ public function emptyBibliothequeLibelleShouldBeDisplayedAsPortail() { $this->assertXpathContentContains('//h2', 'Portail'); } + /** @test */ function byPeferencesParamShouldNotContainsIdCategory() { $this->assertFalse(array_key_exists("id_categorie", @@ -282,6 +290,38 @@ class CmsControllerArticleViewByDateTest extends AbstractControllerTestCase { } + + +class CmsControllerArticleViewByDateWithOnlyArticlePortailTest extends AbstractControllerTestCase { + protected $_article_loader; + + public function setUp() { + parent::setUp(); + + $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'])]) + ]); + + $this->dispatch('/cms/articleviewbydate?d=2011-09-03&id_module=8&id_profil=2&select_id_categorie=all', true); + } + + + /** @test */ + public function emptyBibliothequeLibelleShouldNotBeDisplayedAsPortail() { + $this->assertNotXpathContentContains('//h2', 'Portail', $this->_response->getBody()); + } +} + + + + class CmsControllerArticleViewByDateCategorie23AndNoProfilParamTest extends AbstractControllerTestCase { protected $_article_loader; diff --git a/tests/library/Class/ArticleLoaderTest.php b/tests/library/Class/ArticleLoaderTest.php index 62feb9a5ab2..84fa00097da 100644 --- a/tests/library/Class/ArticleLoaderTest.php +++ b/tests/library/Class/ArticleLoaderTest.php @@ -314,7 +314,7 @@ abstract class ArticleLoaderGroupByBibTestCase extends ModelTestCase { protected function setUp() { parent::setUp(); - $this->articles = ArticleLoader::groupByBib($this->_getArticlesFixture()); + $this->articles = ArticleLoader::groupByBibId($this->_getArticlesFixture()); } } @@ -329,8 +329,8 @@ class ArticleLoaderGroupByBibWithoutBibTest extends ArticleLoaderGroupByBibTestC } /** @test */ - public function keyShouldBeEmptyString() { - $this->assertEquals('', key($this->articles)); + public function keyShouldBeZero() { + $this->assertEquals(0, key($this->articles)); } /** @test */ @@ -365,8 +365,8 @@ extends ArticleLoaderGroupByBibTestCase { /** @test */ - public function keyShouldBeBonlieu() { - $this->assertEquals('Bonlieu', key($this->articles)); + public function keyShouldBeOne() { + $this->assertEquals(1, key($this->articles)); } @@ -490,21 +490,21 @@ extends ArticleLoaderGroupByBibTestCase { /** @test */ public function keysShouldBePortailAndLaTurbine() { - $this->assertEquals(array('Portail', 'La Turbine'), array_keys($this->articles)); + $this->assertEquals([0, 2], array_keys($this->articles)); } /** @test */ public function firstArticleShouldBeGroupedUnderPortail() { $fixtures = $this->_getArticlesFixture(); - $this->assertEquals($fixtures[0], $this->articles['Portail'][0]); + $this->assertEquals($fixtures[0], $this->articles[0][0]); } /** @test */ public function secondArticleShouldBeGroupedUnderLaTurbine() { $fixtures = $this->_getArticlesFixture(); - $this->assertEquals($fixtures[1], $this->articles['La Turbine'][0]); + $this->assertEquals($fixtures[1], $this->articles[2][0]); } -- GitLab