diff --git a/application/modules/opac/controllers/RssController.php b/application/modules/opac/controllers/RssController.php index 7d9319d8b53e2bf903d428f3245fac566af27d61..4b71c07e5ef1f09c79814cd68c43cbe39d8d727f 100644 --- a/application/modules/opac/controllers/RssController.php +++ b/application/modules/opac/controllers/RssController.php @@ -231,7 +231,7 @@ class RssController extends Zend_Controller_Action $data_rss = array( 'titre' => $this->view->_('Modérations'), 'description' => $this->view->_('Données en attente de modération'), - 'lien' => 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'], + 'lien' => $this->view->absoluteUrl($this->getRequest()->getRequestUri()), 'items' => array()); $moderer = new Class_Moderer(); @@ -239,16 +239,18 @@ class RssController extends Zend_Controller_Action //on n'affiche pas les catégories où il n'y a aucune donnée à modérer foreach($modstats as $stat) { if ($stat['count']==0) continue; - $data_rss["items"][]= array( - 'titre' => $stat['label'].': '.$stat['count'], - 'lien' => 'http://'.$_SERVER['SERVER_NAME'].$stat['url']); + $data_rss["items"][]= [ + 'titre' => $stat['label'].': '.$stat['count'], + 'lien' => $this->view->absoluteUrl($stat['url']), + ]; } if (count($data_rss['items']) == 0) $data_rss["items"][]= array('titre' => $this->view->_('Aucune donnée à modérer')); - $flux = $class_rss->createFluxRss($data_rss); - echo $flux; + $this->getHelper('ViewRenderer')->setNoRender(); + $this->getResponse()->setHeader('Content-Type', 'text/html;charset=utf-8') ; + $this->getResponse()->setBody($this->view->renderRss($data_rss)) ; } @@ -264,7 +266,7 @@ class RssController extends Zend_Controller_Action $data_rss["titre"] = $preferences['titre']; $data_rss["description"] = $this->view->_("Critiques de la sélection: %s", $preferences['titre']); - $data_rss["lien"] = urlencode(urlencode($profil->urlForModule('blog', 'viewcritiques', $id_module))); + $data_rss["lien"] = $profil->urlForModule('blog', 'viewcritiques', $id_module); $data_rss["items"] = []; $avis_helper = $this->view->getHelper('Avis'); @@ -275,17 +277,14 @@ class RssController extends Zend_Controller_Action $desc = $avis_helper->avis($avis, 0, $vignette_link_to_avis = true); $entry = array("titre" => $avis->getEntete(), - "lien" => 'http://'.$_SERVER['SERVER_NAME'].BASE_URL.'/blog/viewavis/id/'.$avis->getFirstNotice()->getId().'-'.$avis->getIdUser(), + "lien" => $this->view->absoluteUrl('/blog/viewavis/id/'.$avis->getFirstNotice()->getId().'-'.$avis->getIdUser()), "desc" => '<![CDATA['.$this->filtreNews($desc).']]>'); $data_rss["items"][] = $entry; } - $class_rss = new Class_Rss(); - $flux = $class_rss->createFluxRss($data_rss); - echo $flux; - - $viewRenderer = $this->getHelper('ViewRenderer'); - $viewRenderer->setNoRender(); + $this->getHelper('ViewRenderer')->setNoRender(); + $this->getResponse()->setHeader('Content-Type', 'text/html;charset=utf-8') ; + $this->getResponse()->setBody($this->view->renderRss($data_rss)) ; } @@ -306,24 +305,27 @@ class RssController extends Zend_Controller_Action foreach($user_avis as $avis) { $desc = $avis_helper->avis($avis, 0, $vignette_link_to_avis = true); - $items [] = array('titre' => $avis->getEntete(), - 'lien' => sprintf('http://%s/opac/blog/viewavis/id/%s', - $_SERVER['SERVER_NAME'].BASE_URL, - $avis->getId()), - 'desc' => '<![CDATA[' . $this->filtreNews($desc) . ']]>', - 'pubDate' => strtotime($avis->getDateAvis())); + $items [] = ['titre' => $avis->getEntete(), + 'lien' => $this->view->absoluteUrl([ + 'controller' => 'blog', + 'action' => 'viewavis', + 'id' => $avis->getId(), + ], null, true), + 'desc' => '<![CDATA[' . $this->filtreNews($desc) . ']]>', + 'pubDate' => strtotime($avis->getDateAvis())]; } - $data_rss = array( 'titre' => sprintf('Avis de %s', $username), - 'lien' => sprintf('http://%s/blog/viewauteur/id/%d', - $_SERVER['SERVER_NAME'].BASE_URL, - $id), - 'items' => $items); - $rss = (new Class_Rss())->createFluxRss($data_rss); + $data_rss = ['titre' => sprintf('Avis de %s', $username), + 'lien' => $this->view->absoluteUrl([ + 'controller' => 'blog', + 'action' => 'viewauteur', + 'id', $id, + ]), + 'items' => $items]; $this->getHelper('ViewRenderer')->setNoRender(); - $this->_response->setHeader('Content-Type', 'application/rss+xml;charset=utf-8') ; - $this->_response->setBody($rss); + $this->getResponse()->setHeader('Content-Type', 'text/html;charset=utf-8') ; + $this->getResponse()->setBody($this->view->renderRss($data_rss)) ; } @@ -351,29 +353,30 @@ class RssController extends Zend_Controller_Action $titre = $preferences['titre']; } - $items = []; foreach($notices as $notice) { $items[] = [ 'titre' => $notice["titre"] . ', ' . $notice["auteur"], - 'lien' => 'http://' . $_SERVER['SERVER_NAME'] . BASE_URL . '/recherche/viewnotice/id/' . $notice['id_notice'], + 'lien' => $this->view->absoluteUrl([ + 'controller' => 'recherche', + 'action' => 'viewnotice', + 'id' => $notice['id_notice'], + ], null, true), 'desc' => '<![CDATA[' . $this->_noticeRssDescription($notice) . ']]>', 'pubDate' => strtotime($notice['date_maj']), ]; } $rss_array = [ 'titre' => $titre, - 'lien' => 'http://' . $_SERVER['SERVER_NAME'].BASE_URL, + 'lien' => $this->view->absoluteUrl(), 'description' => $titre, 'lastBuildDate' => time(), 'items' => $items, ]; - $rss = (new Class_Rss())->createFluxRss($rss_array); - $this->getHelper('ViewRenderer')->setNoRender(); $this->getResponse()->setHeader('Content-Type', 'text/html;charset=utf-8') ; - $this->getResponse()->setBody($rss) ; + $this->getResponse()->setBody($this->view->renderRss($rss_array)) ; } diff --git a/library/Class/Catalogue.php b/library/Class/Catalogue.php index afe53bb4d2f1b525637e2e3108f608df84d896b6..51b4f684a8a4408d1cf9489d26bb8ef1490f490a 100644 --- a/library/Class/Catalogue.php +++ b/library/Class/Catalogue.php @@ -262,6 +262,89 @@ class CatalogueLoader extends Storm_Model_Loader { public function findWithSamePathAs($treeNode) { return Class_Catalogue::getRoot()->findByPath($treeNode->getPath()); } + + public function fetchAllNoticesByPreferences($preferences, $cache_vignette) { + $requetes=$this->getRequetes($preferences); + if (!array_key_exists("req_liste", $requetes)) + return array(); + + $req_liste = str_replace('select *', + 'select notices.id_notice, notices.editeur, notices.annee, notices.date_creation, notices.date_maj, notices.facettes, notices.clef_oeuvre', + $requetes["req_liste"]); + + $catalogue=fetchAll($req_liste); + if (!$catalogue) + return []; + + $class_notice = new Class_Notice(); + $class_img = new Class_WebService_Vignette(); + + $notices = []; + foreach($catalogue as $notice) { + $enreg = ($model = Class_Notice::find($notice['id_notice'])) + ? $model->getNotice('JA') : []; + $vignette = ''; + if ($cache_vignette) { + if($cache_vignette=="url") $mode=false; else $mode=true; + $vignette=$class_img->getImage($enreg["id_notice"],$mode); + } + + if (!$cache_vignette or $vignette) { + $notices[] = ["id_notice" => $enreg["id_notice"], + "titre" => $enreg["J"], + "auteur" => $enreg["A"], + "vignette" => $vignette, + "type_doc" => $enreg["type_doc"], + "editeur" => $notice["editeur"], + "annee" => $notice["annee"], + "date_creation" => $notice["date_creation"], + "date_maj" => $notice["date_maj"], + "facettes" => $notice["facettes"], + "clef_oeuvre" => $notice["clef_oeuvre"]]; + } + } + + return $notices; + } + + public function getRequetes($preferences, $fields = null) { + if (isset($preferences["id_panier"]) + && (0 !== (int)$preferences["id_panier"])) + return $this->getRequetesPanier($preferences); + + $against = $this->selectionFacettesForCatalogueRequestByPreferences($preferences); + if ($catalogue = $this->getLoader()->find($preferences['id_catalogue'])) { + $conditions = array($this->getLoader()->facetsClauseFor($catalogue, $against)); + + $conditions []= $this->getLoader()->docTypeClauseFor($catalogue); + $conditions []= $this->getLoader()->yearClauseFor($catalogue); + $conditions []= $this->getLoader()->coteClauseFor($catalogue); + $conditions []= $this->getLoader()->nouveauteClauseFor($catalogue); + } else { + $conditions = $against ? array("MATCH(facettes) AGAINST('".$against."' IN BOOLEAN MODE)") : array(); + } + + if (isset($preferences['only_img']) && ($preferences['only_img'] == 1)) + $conditions[] = "url_vignette > '' and url_vignette != 'NO'"; + + $join = (isset($preferences['avec_avis']) && ($preferences['avec_avis'] == 1)) + ? ' INNER JOIN notices_avis ON notices.clef_oeuvre=notices_avis.clef_oeuvre ' + : ''; + + if ($where = implode(' and ', array_filter($conditions))) + $where = ' where '.$where; + + $order_by = $this->orderByForCatalogueRequestByPreferences($preferences); + $limite = $this->limitForCatalogueRequestByPreferences($preferences); + + $select_fields = $fields ? implode(',', $fields): '*'; + + $ret['req_liste'] = 'select ' . $select_fields . ' from notices ' . $join . $where . $order_by . $limite; + $ret['req_comptage'] = 'select count(*) from notices ' . $join . $where; + $ret['req_facettes'] = 'select notices.id_notice, type_doc, facettes from notices ' . $join . $where . $limite; + + return $ret; + } } @@ -460,7 +543,7 @@ class Class_Catalogue extends Storm_Model_Abstract { return (new Storm_Cache()) ->memoize([$preferences, __CLASS__, __FUNCTION__, $cache_vignette], function() use ($preferences, $cache_vignette) { - return $this->_fetchAllNoticesByPreferences($preferences, $cache_vignette); + return Class_Catalogue::getLoader()->fetchAllNoticesByPreferences($preferences, $cache_vignette); }); } @@ -481,49 +564,6 @@ class Class_Catalogue extends Storm_Model_Abstract { } - public function _fetchAllNoticesByPreferences($preferences, $cache_vignette) { - $requetes=$this->getRequetes($preferences); - if (!array_key_exists("req_liste", $requetes)) - return array(); - - $req_liste = str_replace('select *', - 'select notices.id_notice, notices.editeur, notices.annee, notices.date_creation, notices.date_maj, notices.facettes, notices.clef_oeuvre', - $requetes["req_liste"]); - - $catalogue=fetchAll($req_liste); - if (!$catalogue) - return []; - - $class_notice = new Class_Notice(); - $class_img = new Class_WebService_Vignette(); - - $notices = []; - foreach($catalogue as $notice) { - $enreg = ($model = Class_Notice::find($notice['id_notice'])) - ? $model->getNotice('JA') : []; - $vignette = ''; - if ($cache_vignette) { - if($cache_vignette=="url") $mode=false; else $mode=true; - $vignette=$class_img->getImage($enreg["id_notice"],$mode); - } - - if (!$cache_vignette or $vignette) { - $notices[] = ["id_notice" => $enreg["id_notice"], - "titre" => $enreg["J"], - "auteur" => $enreg["A"], - "vignette" => $vignette, - "type_doc" => $enreg["type_doc"], - "editeur" => $notice["editeur"], - "annee" => $notice["annee"], - "date_creation" => $notice["date_creation"], - "date_maj" => $notice["date_maj"], - "facettes" => $notice["facettes"], - "clef_oeuvre" => $notice["clef_oeuvre"]]; - } - } - - return $notices; - } public function transformArrayToUrlStringAndConcatenateMatiereDeweyPcdm4($facets) { @@ -597,44 +637,6 @@ class Class_Catalogue extends Storm_Model_Abstract { - public function getRequetes($preferences, $fields = null) { - if (isset($preferences["id_panier"]) - && (0 !== (int)$preferences["id_panier"])) - return $this->getRequetesPanier($preferences); - - $against = $this->selectionFacettesForCatalogueRequestByPreferences($preferences); - if ($catalogue = $this->getLoader()->find($preferences['id_catalogue'])) { - $conditions = array($this->getLoader()->facetsClauseFor($catalogue, $against)); - - $conditions []= $this->getLoader()->docTypeClauseFor($catalogue); - $conditions []= $this->getLoader()->yearClauseFor($catalogue); - $conditions []= $this->getLoader()->coteClauseFor($catalogue); - $conditions []= $this->getLoader()->nouveauteClauseFor($catalogue); - } else { - $conditions = $against ? array("MATCH(facettes) AGAINST('".$against."' IN BOOLEAN MODE)") : array(); - } - - if (isset($preferences['only_img']) && ($preferences['only_img'] == 1)) - $conditions[] = "url_vignette > '' and url_vignette != 'NO'"; - - $join = (isset($preferences['avec_avis']) && ($preferences['avec_avis'] == 1)) - ? ' INNER JOIN notices_avis ON notices.clef_oeuvre=notices_avis.clef_oeuvre ' - : ''; - - if ($where = implode(' and ', array_filter($conditions))) - $where = ' where '.$where; - - $order_by = $this->orderByForCatalogueRequestByPreferences($preferences); - $limite = $this->limitForCatalogueRequestByPreferences($preferences); - - $select_fields = $fields ? implode(',', $fields): '*'; - - $ret['req_liste'] = 'select ' . $select_fields . ' from notices ' . $join . $where . $order_by . $limite; - $ret['req_comptage'] = 'select count(*) from notices ' . $join . $where; - $ret['req_facettes'] = 'select notices.id_notice, type_doc, facettes from notices ' . $join . $where . $limite; - - return $ret; - } public function selectionFacettesForCatalogueRequestByPreferences($preferences) { @@ -1125,4 +1127,4 @@ class AllNoticesCatalogue extends Class_Catalogue { } } -?> \ No newline at end of file +?> diff --git a/library/Class/Rss.php b/library/Class/Rss.php index 58e438fa33726b19aefc8770ce90ad36aef3069f..9377e21f959e6f46ee74641772a9955fd85dbfef 100644 --- a/library/Class/Rss.php +++ b/library/Class/Rss.php @@ -496,75 +496,6 @@ class Class_Rss extends Storm_Model_Abstract { return $errorMessage; } - - /* créaion d'un flux - $data_array = 'titre', - 'description', - 'lien', - 'items' = array('titre','lien','desc') - */ - public function createFluxRss($data_array) { - $flux='<?xml version="1.0" ?> - <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/"> - <channel> - <title>'.$data_array["titre"].'</title> - <link>'.$data_array["lien"].'</link>'; - if (isset($data_array['description'])) { - $flux .= '<description>'.$data_array["description"].'</description>'; - } - if (isset($data_array['lastBuildDate'])) { - $lastBuildDate = date(DATE_RSS, $data_array['lastBuildDate']); - $flux .= '<lastBuildDate>' . $lastBuildDate . '</lastBuildDate>'; - } - $flux .= '<image> - <url>http://'.$_SERVER['SERVER_NAME'].URL_IMG.'site/logo.jpg</url> - <link>'.$data_array["lien"].'</link> - <title>'.$data_array["titre"].'</title> - </image>'; - - foreach($data_array["items"] as $item) { - $media_contents = $this->getMediaContentsFromHTMLDescription($item['desc']); - $flux .= '<item>' - . '<title>'.$item["titre"].'</title>' - . '<link>'.$item["lien"].'</link>' - . '<description>'.$item["desc"].'</description>'; - if (isset($item['pubDate'])) { - $pubDate = date(DATE_RSS, $item['pubDate']); - $flux .= '<pubDate>' . $pubDate . '</pubDate>'; - } - foreach ($media_contents as $mc) { - $flux .= '<media:content url="' . $mc['url'] . '"/>'; - } - $flux .= '</item>'; - } - - $flux.='</channel></rss>'; - return($flux); - } - - protected function getMediaContentsFromHTMLDescription($description) { - $media_contents = []; - - if (preg_match('/<img/', $description)) { - $description = preg_replace('/<!\[CDATA\[(.*)\]\]>/s', '$1', $description); - $doc = new DOMDocument(); - $doc->loadHTML($description); - $imgs = $doc->getElementsByTagName('img'); - - foreach ($imgs as $img) { - $url = $img->attributes->getNamedItem('src')->nodeValue; - if ($url[0] == '/') { - $url = 'http://' . $_SERVER['SERVER_NAME'] . $url; - } - $media_contents[] = [ - 'url' => $url, - ]; - } - - return $media_contents; - } - } - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // ARBRE pour lister les cat+ subcat sur lindex admin //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/library/ZendAfi/View/Helper/RenderRss.php b/library/ZendAfi/View/Helper/RenderRss.php new file mode 100644 index 0000000000000000000000000000000000000000..a332f4103ea96ff9de7ae6170f47aca2abab2442 --- /dev/null +++ b/library/ZendAfi/View/Helper/RenderRss.php @@ -0,0 +1,84 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +class ZendAfi_View_Helper_RenderRss extends Zend_View_Helper_Abstract { + public function renderRss($data) { + $flux='<?xml version="1.0" ?> + <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/"> + <channel> + <title>'.$data["titre"].'</title> + <link>'.$data["lien"].'</link>'; + if (isset($data['description'])) { + $flux .= '<description>'.$data["description"].'</description>'; + } + if (isset($data['lastBuildDate'])) { + $lastBuildDate = date(DATE_RSS, $data['lastBuildDate']); + $flux .= '<lastBuildDate>' . $lastBuildDate . '</lastBuildDate>'; + } + $flux .= '<image> + <url>' . $this->view->absoluteUrl(URL_IMG.'site/logo.jpg</url>') + . '<link>'.$data["lien"].'</link> + <title>'.$data["titre"].'</title> + </image>'; + + foreach($data["items"] as $item) { + $desc = isset($item['desc']) ? $item['desc'] : ''; + $media_contents = $this->getMediaContentsFromHTMLDescription($desc); + $flux .= '<item>' + . '<title>'.$item["titre"].'</title>' + . '<link>'.$item["lien"].'</link>' + . '<description>'.$desc.'</description>'; + if (isset($item['pubDate'])) { + $pubDate = date(DATE_RSS, $item['pubDate']); + $flux .= '<pubDate>' . $pubDate . '</pubDate>'; + } + foreach ($media_contents as $mc) { + $flux .= '<media:content url="' . $mc['url'] . '"/>'; + } + $flux .= '</item>'; + } + + $flux .= '</channel></rss>'; + + return $flux; + } + + protected function getMediaContentsFromHTMLDescription($description) { + $media_contents = []; + + if (preg_match('/<img/', $description)) { + $description = preg_replace('/<!\[CDATA\[(.*)\]\]>/s', '$1', $description); + $doc = new DOMDocument(); + $doc->loadHTML($description); + $imgs = $doc->getElementsByTagName('img'); + + foreach ($imgs as $img) { + $url = $img->attributes->getNamedItem('src')->nodeValue; + if ($url) { + $media_contents[] = [ + 'url' => $this->view->absoluteUrl(htmlspecialchars($url)), + ]; + } + } + } + + return $media_contents; + } +} diff --git a/tests/application/modules/opac/controllers/AbonneControllerAvisTest.php b/tests/application/modules/opac/controllers/AbonneControllerAvisTest.php index 343fca9b677e92b0aae80e1ee5e6e46fa237c0b6..9ffc7b40d27d7eaa4480efd1cfdc508f3e8deaf0 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerAvisTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerAvisTest.php @@ -503,7 +503,7 @@ class AbonneControllerAvisRssControllerViewAvisUserTest extends AvisControllersF /** @test */ function firstItemLinkShouldBeBlogViewAvisId13() { $this->assertXPathContentContains('//channel/item/link', - "http://localhost" . BASE_URL . "/opac/blog/viewavis/id/13",$this->_response->getBody()); + "http://localhost" . BASE_URL . "/blog/viewavis/id/13",$this->_response->getBody()); } @@ -887,4 +887,4 @@ class AbonneControllerDeleteAvisNoticeAdminLoggedActionTest extends AbstractCont } } -?> \ No newline at end of file +?> diff --git a/tests/application/modules/opac/controllers/RssControllerTest.php b/tests/application/modules/opac/controllers/RssControllerTest.php index a22f1a4c89054828f8b0990a9fbe01a5537727e6..92ba7efb352051214064505b7b83b1190c2acda7 100644 --- a/tests/application/modules/opac/controllers/RssControllerTest.php +++ b/tests/application/modules/opac/controllers/RssControllerTest.php @@ -116,6 +116,212 @@ class RssControllerKiosqueInexistingProfilTest extends AbstractControllerTestCas +class RssControllerKiosqueTest extends AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + + $profil = $this->fixture('Class_Profil', [ + 'id' => 76, + 'libelle' => 'Profil Rss Kiosque', + ]); + $profil->setCfgAccueil([ + 'modules' => [ + '10' => [ + 'division' => '2', + 'type_module' => 'KIOSQUE', + 'id_catalogue' => 1, + ] + ], + 'options' => [] + ]); + + $notice1 = $this->fixture('Class_Notice', [ + 'id' => 1, + 'id_notice' => '1', + 'titre' => 'Notice 1', + 'auteur' => 'Author 1', + "vignette" => 'notice1.jpg', + "type_doc" => '', + "editeur" => '', + "annee" => '', + "date_creation" => time(), + "date_maj" => time(), + "facettes" => '', + "clef_oeuvre" => '' + ])->toArray(); + $notice2 = $this->fixture('Class_Notice', [ + 'id' => 2, + 'id_notice'=> 2, + 'titre' => 'Notice 2', + 'auteur' => 'Auteur 2', + "vignette" => 'notice2.jpg', + "type_doc" => '', + "editeur" => '', + "annee" => '', + "date_creation" => time(), + "date_maj" => time(), + "facettes" => '', + "clef_oeuvre" => '' + ])->toArray(); + $notice3 = $this->fixture('Class_Notice', [ + 'id' => 3, + 'id_notice' => 3, + 'titre' => 'Notice 3', + 'auteur' => 'Auteur 1', + "vignette" => 'notice3.jpg', + "type_doc" => '', + "editeur" => '', + "annee" => '', + "date_creation" => time(), + "date_maj" => time(), + "facettes" => '', + "clef_oeuvre" => '' + ])->toArray(); + + $catalogue = $this->fixture('Class_Catalogue', [ + 'id' => 1, + 'libelle' => 'Catalogue RSS Kiosque', + ]); + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue') + ->whenCalled('fetchAllNoticesByPreferences') + ->answers([$notice1, $notice2, $notice3]); + + $this->dispatch('/rss/kiosque/id_profil/76/id_module/10', true); + } + + + /** @test */ + public function rssShouldContainsThreeItems() { + $this->assertXPath('//item[3]'); + } + + + /** @test */ + public function rssOfNotice1ShouldContainsImgUrl() { + $this->assertXPath('//item[1]//media:content[contains(@url,"'.BASE_URL.'/notice1.jpg")]'); + } + + /** @test */ + public function rssLinkShouldContainBaseUrl() { + $this->assertXPathContentContains('//link', BASE_URL); + } + + /** @test */ + public function rssImageUrlShouldContainExpectedUrl() { + $this->assertXPathContentContains('//image/url', URL_IMG . 'site/logo.jpg'); + } + +} + + +class RssControllerModerationsTest extends AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + + $this->dispatch('/rss/moderations', true); + } + + /** @test */ + public function rssLinkShouldContainBaseUrl() { + $this->assertXPathContentContains('//channel/link', BASE_URL . '/rss/moderations'); + } + + /** @test */ + public function rssImageUrlShouldContainExpectedUrl() { + $this->assertXPathContentContains('//image/url', URL_IMG . 'site/logo.jpg'); + } + +} + + + +class RssControllerCritiquesTest extends AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + + $profil = $this->fixture('Class_Profil', [ + 'id' => 76, + 'libelle' => 'Profil Rss Critiques', + ]); + $profil->setCfgAccueil([ + 'modules' => [ + '10' => [ + 'division' => '2', + 'type_module' => 'CRITIQUES', + ] + ], + 'options' => [] + ]); + + $notice1 = $this->fixture('Class_Notice', [ + 'id' => 1, + 'id_notice' => '1', + 'titre' => 'Notice 1', + 'auteur' => 'Author 1', + "vignette" => 'notice1.jpg', + "type_doc" => '', + "editeur" => '', + "annee" => '', + "date_creation" => time(), + "date_maj" => time(), + "facettes" => '', + "clef_oeuvre" => '' + ]); + + $avis = [ + $this->fixture('Class_AvisNotice', [ + 'id' => 1, + 'id_user' => 1, + 'avis' => 'Testing comment', + 'entete' => 'Testing comment', + 'note' => 4, + 'clef_oeuvre' => 'testing-comment', + 'date_avis' => '2012-01-01', + ]), + $this->fixture('Class_AvisNotice', [ + 'id' => 2, + 'id_user' => 1, + 'avis' => 'Testing comment', + 'entete' => 'Testing comment', + 'note' => 4, + 'clef_oeuvre' => 'testing-comment', + 'date_avis' => '2012-01-01', + ]), + ]; + + $avis[0]->setNotice($notice1); + $avis[1]->setNotice($notice1); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_AvisNotice') + ->whenCalled('getAvisFromPreferences') + ->answers($avis); + + $this->dispatch('/rss/critiques/id_profil/76/id_module/10', true); + } + + + /** @test */ + public function rssShouldContainsTwoItems() { + $this->assertXPath('//item[2]'); + } + + /** @test */ + public function rssLinkShouldContainExpectedUrl() { + $this->assertXPathContentContains('//channel/link', BASE_URL); + } + + /** @test */ + public function rssImageUrlShouldContainExpectedUrl() { + $this->assertXPathContentContains('//image/url', URL_IMG . 'site/logo.jpg'); + } + + /** @test */ + public function rssItemUrlShouldContainExpectedUrl() { + $this->assertXPathContentContains('//item[1]/link', BASE_URL . '/blog/viewavis/id/1'); + } + +} + class RssFixtures { public static function lemondeRSS() { @@ -266,4 +472,4 @@ class RssFixtures { </channel> </rss>'; } -} \ No newline at end of file +} diff --git a/tests/library/Class/RssTest.php b/tests/library/Class/RssTest.php deleted file mode 100644 index f85e12b934750579afd90533ad87d6d7fa1872fd..0000000000000000000000000000000000000000 --- a/tests/library/Class/RssTest.php +++ /dev/null @@ -1,62 +0,0 @@ -<?php -/** - * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. - * - * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify - * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by - * the Free Software Foundation. - * - * There are special exceptions to the terms and conditions of the AGPL as it - * is applied to this software (see README file). - * - * AFI-OPAC 2.0 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU AFFERO GENERAL PUBLIC LICENSE for more details. - * - * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE - * along with AFI-OPAC 2.0; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -class RssTest extends PHPUnit_Framework_TestCase { - /** @var Class_Rss */ - protected $rss; - - public function setUp() { - parent::setUp(); - $this->rss = new Class_Rss(); - } - - /** @test */ - public function descriptionWithImgShouldUseMediaNamespace() { - $data = [ - 'titre' => "Test title", - 'lien' => "http://example.com/rss", - 'description' => "Test description", - 'items' => [ - [ - 'titre' => "Item 1 title", - 'lien' => "http://example.com/item1", - 'desc' => "<![CDATA[" - . "<div>Item 1 description</div>" - . "<img src=\"http://example.com/item1.png\">" - . "<img src=\"http://example.com/item2.png\">" - . "]]>", - ], - ], - ]; - - $rss_string = $this->rss->createFluxRss($data); - $xml = simplexml_load_string($rss_string, 'SimpleXMLElement', LIBXML_NOCDATA); - $mc_elements = $xml->xpath('//media:content'); - - $this->assertCount(2, $mc_elements); - - $this->assertEquals("http://example.com/item1.png", - $mc_elements[0]->attributes()->url); - - $this->assertEquals("http://example.com/item2.png", - $mc_elements[1]->attributes()->url); - } -}