From a3e5de7ceaca57f270170f6d054dd7e6c0397b18 Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@git-test.afi-sa.fr> Date: Fri, 14 Sep 2012 08:52:12 +0000 Subject: [PATCH] =?UTF-8?q?G=C3=A9n=C3=A9ration=20du=20flux=20RSS=20pour?= =?UTF-8?q?=20un=20album=20multim=C3=A9dia,=20compatibilit=C3=A9=20Miro?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/BibNumeriqueController.php | 1 + library/ZendAfi/View/Helper/AbsoluteUrl.php | 14 +++- .../View/Helper/Album/RssFeedVisitor.php | 21 ++++-- .../View/Helper/Album/XspfPlaylistVisitor.php | 11 +-- .../AlbumControllerVideoAndAudioTest.php | 2 +- .../BibNumeriqueControllerTest.php | 68 ++++++++++++++++++- .../ZendAfi/View/Helper/RenderAlbumTest.php | 2 +- 7 files changed, 97 insertions(+), 22 deletions(-) diff --git a/application/modules/opac/controllers/BibNumeriqueController.php b/application/modules/opac/controllers/BibNumeriqueController.php index 35db5c7a88a..9a6390bd514 100644 --- a/application/modules/opac/controllers/BibNumeriqueController.php +++ b/application/modules/opac/controllers/BibNumeriqueController.php @@ -64,6 +64,7 @@ class BibNumeriqueController extends Zend_Controller_Action { $album = Class_Album::getLoader()->find((int)$this->_getParam('id')); $rss = $this->view->album_RssFeedVisitor($album); $this->_response->setBody($rss); + $this->_response->setHeader('Content-Type', 'application/rss+xml', true); } diff --git a/library/ZendAfi/View/Helper/AbsoluteUrl.php b/library/ZendAfi/View/Helper/AbsoluteUrl.php index 7912538ccc4..0e60e306afd 100644 --- a/library/ZendAfi/View/Helper/AbsoluteUrl.php +++ b/library/ZendAfi/View/Helper/AbsoluteUrl.php @@ -19,7 +19,17 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class ZendAfi_View_Helper_AbsoluteUrl extends Zend_View_Helper_HtmlElement { - public function absoluteUrl(array $urlOptions = array(), $name = null, $reset = false, $encode = true) { - return 'http://'.$_SERVER["HTTP_HOST"].$this->view->url($urlOptions, $name, $reset, $encode); + public function absoluteUrl($url_array_or_string = [], $name = null, $reset = false, $encode = true) { + $url = is_string($url_array_or_string) + ? $url_array_or_string + : $this->view->url($url_array_or_string, $name, $reset, $encode); + + if (preg_match('/http[s]?:\/\//', $url)) + return $url; + + if (0 !== strpos($url, BASE_URL)) + $url = BASE_URL . $url; + + return 'http://' . $_SERVER['SERVER_NAME'] . $url; } } \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/Album/RssFeedVisitor.php b/library/ZendAfi/View/Helper/Album/RssFeedVisitor.php index 40ea3cfcc7a..59ace7a9dcb 100644 --- a/library/ZendAfi/View/Helper/Album/RssFeedVisitor.php +++ b/library/ZendAfi/View/Helper/Album/RssFeedVisitor.php @@ -23,23 +23,30 @@ class ZendAfi_View_Helper_Album_RssFeedVisitor extends Zend_View_Helper_Abstrac protected $_data_rss; public function album_rssFeedVisitor($album) { - $this->_data_rss = [ - 'title' => $album->getTitre(), - 'link' => '', - 'charset' => 'utf-8', - 'description' => '', - 'lastUpdate' => time()]; - $album->acceptVisitor($this); $feed = Zend_Feed::importArray($this->_data_rss, 'rss'); return $feed->saveXML(); } + public function visitAlbum($album) { + $this->_data_rss = [ + 'title' => $album->getTitre(), + 'link' => $this->view->absoluteUrl($album->getPermalink()), + 'charset' => 'utf-8', + 'description' => $album->getDescription(), + 'lastUpdate' => strtotime($album->getDateMaj()), + 'entries' => []]; } + public function visitRessource($ressource, $index) { + $this->_data_rss['entries'] []= [ + 'title' => $ressource->getTitre(), + 'link' => $this->view->absoluteUrl($ressource->getOriginalUrl()), + 'description' => $ressource->getDescription() + ]; } } diff --git a/library/ZendAfi/View/Helper/Album/XspfPlaylistVisitor.php b/library/ZendAfi/View/Helper/Album/XspfPlaylistVisitor.php index 63f863b7da1..76ec15f349d 100644 --- a/library/ZendAfi/View/Helper/Album/XspfPlaylistVisitor.php +++ b/library/ZendAfi/View/Helper/Album/XspfPlaylistVisitor.php @@ -41,17 +41,10 @@ class ZendAfi_View_Helper_Album_XspfPlaylistVisitor extends Zend_View_Helper_Ab public function visitRessource($ressource, $index) { $this->_tracks []= $this->_builder->track( $this->_builder->title($ressource->getTitre()) - .$this->_builder->image($this->absoluteUrl($ressource->getThumbnailUrl())) - .$this->_builder->location($this->absoluteUrl($ressource->getOriginalUrl())) + .$this->_builder->image($this->view->absoluteUrl($ressource->getThumbnailUrl())) + .$this->_builder->location($this->view->absoluteUrl($ressource->getOriginalUrl())) ); } - - - public function absoluteUrl($url) { - if (preg_match('/http[s]?:\/\//', $url)) - return $url; - return 'http://' . $_SERVER['SERVER_NAME'] . $url; - } } diff --git a/tests/application/modules/admin/controllers/AlbumControllerVideoAndAudioTest.php b/tests/application/modules/admin/controllers/AlbumControllerVideoAndAudioTest.php index 7852b631f84..b78a082bf4d 100644 --- a/tests/application/modules/admin/controllers/AlbumControllerVideoAndAudioTest.php +++ b/tests/application/modules/admin/controllers/AlbumControllerVideoAndAudioTest.php @@ -21,7 +21,7 @@ require_once 'AlbumControllerTest.php'; -class Admin_AlbumControllerVideoAndAudio extends Admin_AlbumControllerTestCase { +class Admin_AlbumControllerVideoAndAudioTest extends Admin_AlbumControllerTestCase { protected $_xpath; public function setUp() { diff --git a/tests/application/modules/opac/controllers/BibNumeriqueControllerTest.php b/tests/application/modules/opac/controllers/BibNumeriqueControllerTest.php index 0c9bb0c8c59..91a4e2c71cf 100644 --- a/tests/application/modules/opac/controllers/BibNumeriqueControllerTest.php +++ b/tests/application/modules/opac/controllers/BibNumeriqueControllerTest.php @@ -524,6 +524,8 @@ abstract class BibNumeriqueControllerAlbumMultiMediasTestCase extends AbstractCo $album = Class_Album::newInstanceWithId(999) ->beDiaporama() ->setTitre('Plein de medias') + ->setDateMaj('2012-02-17 10:00:00') + ->setDescription('<p>pour passer la soirée</p>') ->setRessources([Class_AlbumRessource::newInstanceWithId(2) ->setFichier('mimi_jolie.mp3') ->setTitre('Emilie jolie') @@ -532,7 +534,8 @@ abstract class BibNumeriqueControllerAlbumMultiMediasTestCase extends AbstractCo Class_AlbumRessource::newInstanceWithId(4) ->setFichier('dark_night.mp4') ->setTitre('Batman Dark Knight') - ->setVignette('batman.jpg'), + ->setVignette('batman.jpg') + ->setDescription('Une nouvelle aventure du justicier noir'), Class_AlbumRessource::newInstanceWithId(5) ->setUrl('http://progressive.totaleclips.com.edgesuite.net/107/e107950_227.mp4') @@ -555,7 +558,6 @@ class BibNumeriqueControllerAlbumMultiMediasXSPFTest extends BibNumeriqueControl $this->dispatch('/opac/bib-numerique/album-xspf-playlist/id/999.xspf', true); } - /** @test */ public function headerShouldContainsContentTypeXspf() { @@ -650,12 +652,74 @@ class BibNumeriqueControllerAlbumMultiMediasRSSTest extends BibNumeriqueControll } + /** @test */ + public function headerShouldContainsContentTypeRss() { + $this->assertHeaderContains('Content-Type', 'application/rss+xml'); + } + + /** @test */ public function titleShouldBePleinDeMedias() { $this->_xpath->assertXPathContentContains($this->_response->getBody(), '//channel/title', 'Plein de medias'); } + + + /** @test */ + public function descriptionShouldBePourPasserLaSoiree() { + $this->_xpath->assertXPathContentContains($this->_response->getBody(), + '//channel/description', + '<p>pour passer la soirée</p>'); + } + + + /** @test */ + public function linkShouldBeBibNumeriqueNoticeId999() { + $this->_xpath->assertXPathContentContains($this->_response->getBody(), + '//channel/link', + 'http://localhost'.BASE_URL.'/bib-numerique/notice/id/999'); + } + + + /** @test */ + public function pubDateShouldBeFri17Feb2012() { + $this->_xpath->assertXPathContentContains($this->_response->getBody(), + '//channel/pubDate', + 'Fri, 17 Feb 2012'); + } + + + /** @test */ + public function firstItemTibleShouldBeEmilieJolie() { + $this->_xpath->assertXPathContentContains($this->_response->getBody(), + '//channel/item[1]/title', + 'Emilie jolie'); + } + + + /** @test */ + public function firstItemLinkShouldBeMediaMimiJolieMp3() { + $this->_xpath->assertXPathContentContains($this->_response->getBody(), + '//channel/item[1]/link', + 'http://localhost'.BASE_URL.'/userfiles/album/999/big/media/mimi_jolie.mp3'); + } + + + /** @test */ + public function secondItemTitleShouldBeDarkKnight() { + $this->_xpath->assertXPathContentContains($this->_response->getBody(), + '//channel/item[2]/title', + 'Batman Dark Knight'); + } + + + /** @test */ + public function secondItemDescriptionShouldBeAventureJusticierNoir() { + $this->_xpath->assertXPathContentContains($this->_response->getBody(), + '//channel/item[2]/description', + 'Une nouvelle aventure du justicier noir'); + } } diff --git a/tests/library/ZendAfi/View/Helper/RenderAlbumTest.php b/tests/library/ZendAfi/View/Helper/RenderAlbumTest.php index c3af23c667c..152a77c79f7 100644 --- a/tests/library/ZendAfi/View/Helper/RenderAlbumTest.php +++ b/tests/library/ZendAfi/View/Helper/RenderAlbumTest.php @@ -63,7 +63,7 @@ class ZendAfi_View_Helper_RenderAlbumEPUBTest extends ZendAfi_View_Helper_Render /** @test */ public function pageShouldContainsLinkToDownloadEPUB() { $this->assertXPathContentContains($this->html, - '//a[contains(@href, "'.BASE_URL.'/bib-numerique/download-resource/id/123")]', + '//a[@href="/bib-numerique/download-resource/id/123"]', 'versailles.epub'); } } -- GitLab