Commit f41c2600 authored by Laurent's avatar Laurent
Browse files

dev #65267 update trailer tests

parent 728bb364
......@@ -83,17 +83,17 @@ class Admin_RecordsController extends ZendAfi_Controller_Action {
$this->view->titre = $this->_('Modifier la bande-annonce');
$form = new ZendAfi_Form_RecordTrailer(['action' => $this->view->url()]);
$this->view->form = $form;
if ($this->_request->isPost()
&& $form->isValid($this->_request->getPost())) {
if (!$this->view->error = Class_WebService_AllServices::uploadTrailerForRecord($this->_getParam('trailer_url'),
$this->_getParam('id'))) {
$this->_helper->notify($this->_('La bande-annonce a bien été mise à jour'));
$this->_redirectClose($this->_getReferer());
return;
}
}
if (!$this->_request->isPost() || !$form->isValid($this->_request->getPost()))
return $this;
$this->view->form = $form;
if ($this->view->error = (new Class_WebService_AllServices())
->uploadTrailerForRecord($this->_getParam('url_trailer'),
$this->_getParam('id')))
return $this;
$this->_helper->notify($this->_('La bande-annonce a bien été mise à jour'));
$this->_redirectClose($this->_getReferer());
}
}
......@@ -220,39 +220,9 @@ class NoticeAjaxController extends Zend_Controller_Action {
public function bandeannonceAction() {
session_write_close();
if ($this->service_afi > "") {
$width = $this->_getParam('width', 500);
$height = (int)($width * 4/5);
$args= ['titre' => $this->notice->getRecordTitle(),
'auteur' => $this->notice->getAuteurPrincipal(),
'clef_oeuvre' => $this->notice->getClefOeuvre(),
'type_doc' => $this->notice->getFamilleId(),
'width' => $width,
'height' => $height];
$data=Class_WebService_AllServices::runServiceAfi(6,$args);
$source=$data["source"];
$bo=$data["player"];
$html=$this->notice_html->getBandeAnnonce($source,$bo);
}
else {
$html = $this->notice_html->getNonTrouve($this->view->_("Service non disponible"),true);
}
if (Class_Users::isCurrentUserCanAccesBackend()) {
$url = $this->view->url(['module' => 'admin',
'controller' => 'records',
'action' => 'trailer',
'id' => $this->notice->getId()]);
$html = $html . $this->view->tag('a', $this->_('Modifier la bande-annonce'),
['href' => $url, 'data-popup' => 'true']);
}
$this->_sendResponseWithScripts($html);
$this->_sendResponseWithScripts(
$this->view->trailer($this->notice,
$this->_getParam('width', 500)));
}
......
......@@ -20,6 +20,8 @@
*/
class Class_WebService_AllServices {
use Trait_Translator;
const RETOUR_SERVICE_OK = 2;
const SVC_API = '2.0';
......@@ -144,12 +146,15 @@ class Class_WebService_AllServices {
public static function uploadTrailerForRecord($url, $id) {
public function uploadTrailerForRecord($url, $id) {
$notice = Class_Notice::find($id);
$result = static::runServiceAfiUploadTrailer(array_filter(['trailer_url' => $url,
$result = static::runServiceAfiUploadTrailer(array_filter(['url_trailer' => $url,
'clef_oeuvre' => $notice->getClefOeuvre(),
'type_doc' => $notice->getFamilleId()]));
if (!isset($result['statut_recherche']))
return $this->_('Le service n\'a pas répondu');
if (self::RETOUR_SERVICE_OK != $result['statut_recherche'])
return $result['message'];
}
......
......@@ -24,7 +24,7 @@ class ZendAfi_Form_RecordTrailer extends ZendAfi_Form {
parent::init();
$this
->addElement('url',
'trailer_url',
'url_trailer',
['label' => $this->_('URL de la bande-annonce'),
'size' => 80,
'required' => true,
......
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH 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).
*
* BOKEH 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 BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class ZendAfi_View_Helper_Trailer extends ZendAfi_View_Helper_BaseHelper {
public function trailer($notice, $width) {
return trim(Class_CosmoVar::get('url_services'))
? $this->_renderTrailer($notice, $width)
: $this->_renderServiceUnavailable();
}
protected function _renderServiceUnavailable() {
return (new Class_NoticeHtml())
->getNonTrouve($this->view->_('Service non disponible'),
true);
}
protected function _renderTrailer($notice, $width) {
return
$this->_renderPlayer($notice, $width)
. $this->_renderEditLink($notice);
}
protected function _renderPlayer($notice, $width) {
$height = (int)($width * 4/5);
$args= ['titre' => $notice->getRecordTitle(),
'auteur' => $notice->getAuteurPrincipal(),
'clef_oeuvre' => $notice->getClefOeuvre(),
'type_doc' => $notice->getFamilleId(),
'width' => $width,
'height' => $height];
$data = Class_WebService_AllServices::runServiceAfi(6, $args);
return (new Class_NoticeHtml())->getBandeAnnonce($data['source'],
$data['player']);
}
protected function _renderEditLink($notice) {
if (!Class_Users::isCurrentUserCanAccesBackend())
return '';
$url = $this->view->url(['module' => 'admin',
'controller' => 'records',
'action' => 'trailer',
'id' => $notice->getId()]);
return $this->view->tag('a',
$this->_('Modifier la bande-annonce'),
['href' => $url, 'data-popup' => 'true']);
}
}
......@@ -383,4 +383,80 @@ class RecordsControllerBiographyPostServeurCacheErrorTest extends RecordsControl
public function pageShouldDisplayErrorMessageBiographieNonTrouvee() {
$this->assertXPathContentContains('//p[@class="error"]', 'Biographie non trouvée');
}
}
\ No newline at end of file
}
class RecordsControllerTrailerTest extends RecordsControllerTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/admin/records/trailer/id/12345', true);
}
/** @test */
public function formShouldHaveInputUrlTrailer() {
$this->assertXPath('//form//input[@type="url"][@name="url_trailer"][contains(@placeholder, "ex: https://youtu.be/AUI12X")]');
}
/** @test */
public function formShouldHaveSubmitButtonEnvoyer() {
$this->assertXPath('//form//input[@type="submit"][@value="Envoyer"]');
}
}
class RecordsControllerTrailerPostTest extends RecordsControllerTestCase {
/** @test */
public function withValidUrlPageShouldDisplayTrailerUpdated() {
$this->_http_client
->whenCalled('open_url')
->with('http://cache.org'
.'?url_trailer='.urlencode('http://youtu.be/BEPO2')
.'&clef_oeuvre=HARRY_POTTER'
.'&type_doc=1'
.'&src='.Class_WebService_AllServices::createSecurityKey()
.'&api=2.0'
.'&action=14')
->answers(json_encode(['url_trailer' => 'http://youtu.be/BEPO2',
'statut_recherche' => 2]))
->beStrict();
$this->postDispatch('/admin/records/trailer/id/12345',
['url_trailer' => 'http://youtu.be/BEPO2']);
$this->assertFlashMessengerContentContains('La bande-annonce a bien été mise à jour');
}
/** @test */
public function withInvalidUrlPageShouldDisplayError() {
$this->_http_client
->whenCalled('open_url')
->answers(json_encode(['message' => 'source inconnue',
'statut_recherche' => 0]));
$this->postDispatch('/admin/records/trailer/id/12345',
['url_trailer' => 'http://mavid.eo']);
$this->assertXPathContentContains('//p[@class="error"]', 'source inconnue');
}
/** @test */
public function withErrorFromCacheServerPageShouldDisplayError() {
$this->_http_client
->whenCalled('open_url')
->answers('');
$this->postDispatch('/admin/records/trailer/id/12345',
['url_trailer' => 'http://mavid.eo']);
$this->assertXPathContentContains('//p[@class="error"]'
'Le service n\'a pas répondu');
}
}
......@@ -461,16 +461,66 @@ class NoticeAjaxControllerResNumeriquesFromFrbrLinkNonAdminTest extends NoticeAj
class NoticeAjaxControllerBandeAnnonceTest extends AbstractControllerTestCase {
protected $_storm_default_to_volatile = true;
public function setUp() {
parent::setUp();
Class_CosmoVar::setValueOf('url_services', 'https://websvc.net/main.php');
Class_WebService_AllServices
::setHttpClient(
Storm_Test_ObjectWrapper::mock()
->whenCalled('open_url')
->answers(json_encode(['source' => 'Testing',
'player' => 'toto'])));
$this->fixture('Class_Notice',
['id' => 2,
'unimarc' => file_get_contents(ROOT_PATH . 'tests/fixtures/dvd_potter.uni'),
'clef_oeuvre' => 'POTTER',
'type_doc' => Class_TypeDoc::DVD]);
}
public function tearDown() {
Class_WebService_AllServices::setHttpClient(null);
parent::tearDown();
}
/** @test */
public function shouldContainsSourceTitle() {
Class_WebService_AllServices::setHttpClient(
Storm_Test_ObjectWrapper::mock()
->whenCalled('open_url')
->answers(json_encode(['source' => 'Testing', 'player' => 'toto'])));
$admin = Class_Users::newInstanceWithId(15,['login'=>'admin'])->beAdminPortail();
Zend_Auth::getInstance()->logUser($admin);
$this->dispatch('noticeajax/bandeannonce', true);
$this->assertXPathContentContains('//h3', 'Source : Testing', $this->_response->getBody());
public function responseShouldContainsSourceTitle() {
$this->dispatch('noticeajax/bandeannonce/id/2', true);
$this->assertXPathContentContains('//h3',
'Source : Testing',
$this->_response->getBody());
}
/** @test */
public function asAPatronResponseShouldNotLinkToEditTrailer() {
Zend_Auth::getInstance()
->logUser($this->fixture('Class_Users',
['id' => 15,
'login'=>'someone',
'password' => 'is here',
'id_bib' => 3])->beAbonneSIGB());
$this->dispatch('noticeajax/bandeannonce/id/2', true);
$this->assertNotXPath('//a[contains(@href, "record")]');
}
/** @test */
public function asAdminResponseShouldContainLinkToEditTrailer() {
Zend_Auth::getInstance()
->logUser($this->fixture('Class_Users',
['id' => 15,
'login'=>'someone',
'password' => 'is here',
'id_bib' => 3])->beModoBib());
$this->dispatch('noticeajax/bandeannonce/id/2', true);
$this->assertXPath('//a[@data-popup="true"][contains(@href, "records/trailer/id/2")]');
}
......@@ -481,14 +531,10 @@ class NoticeAjaxControllerBandeAnnonceTest extends AbstractControllerTestCase {
Class_WebService_AllServices::setHttpClient(
Storm_Test_ObjectWrapper::mock()
->whenCalled('open_url')
->with('https://websvc.afi-sa.net/afi_opac_services/main.php?titre=Harry+Potter+%C3%A0+l%27%C3%A9cole+des+sorciers&auteur=Chris+Columbus&width=500&height=400&src=' . $key . '&api=2.0&action=6')
->with('https://websvc.net/main.php?titre=Harry+Potter+%C3%A0+l%27%C3%A9cole+des+sorciers&auteur=Chris+Columbus&clef_oeuvre=POTTER&type_doc=4&width=500&height=400&src=' . $key . '&api=2.0&action=6')
->answers(json_encode(['source' => 'CommeAuCinema', 'player' => '<iframe></iframe>']))
->beStrict());
$this->fixture('Class_Notice',
['id' => 2,
'unimarc' => file_get_contents(ROOT_PATH . 'tests/fixtures/dvd_potter.uni'),
'type_doc' => Class_TypeDoc::DVD]);
$this->dispatch('noticeajax/bandeannonce/id/2', true);
$this->assertXPath('//iframe', $this->_response->getBody());
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment