From 5f5a015df26f9bc20e4cb06a3b108adfabe21b53 Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-sa.fr> Date: Tue, 30 Oct 2018 15:27:36 +0100 Subject: [PATCH] dev #78660 fix tests --- library/Class/Testing/HttpResponse.php | 27 +++++++++++++++++++ library/Class/WebService/Abstract.php | 3 +-- .../Action/Helper/ListViewMode/Album.php | 6 +++++ .../DigitalResource/Dashboard/Harvest.php | 16 +++++++---- .../DiMusic/tests/DiMusicTest.php | 6 ++--- .../Skilleos/tests/SkilleosTest.php | 11 +++----- .../StoryPlayR/tests/StoryPlayRTest.php | 6 +++-- .../ToutApprendre/tests/ToutApprendreTest.php | 6 ----- .../Class/WebService/Album/VignetteTest.php | 10 +++---- 9 files changed, 60 insertions(+), 31 deletions(-) create mode 100644 library/Class/Testing/HttpResponse.php diff --git a/library/Class/Testing/HttpResponse.php b/library/Class/Testing/HttpResponse.php new file mode 100644 index 00000000000..847aed64142 --- /dev/null +++ b/library/Class/Testing/HttpResponse.php @@ -0,0 +1,27 @@ +<?php +/** + * Copyright (c) 2012-2017, 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 Class_Testing_HttpResponse extends Class_Entity { + public function isSuccessful() { + return true; + } +} \ No newline at end of file diff --git a/library/Class/WebService/Abstract.php b/library/Class/WebService/Abstract.php index 51977f04bee..ab848cf14d1 100644 --- a/library/Class/WebService/Abstract.php +++ b/library/Class/WebService/Abstract.php @@ -36,9 +36,8 @@ class Class_WebService_Abstract { public static function getHttpClient() { - if (static::$_http_client==null || !isset(static::$_http_client)) { + if (static::$_http_client==null || !isset(static::$_http_client)) static::$_http_client = new Class_WebService_SimpleWebClient(); - } return static::$_http_client; } diff --git a/library/ZendAfi/Controller/Action/Helper/ListViewMode/Album.php b/library/ZendAfi/Controller/Action/Helper/ListViewMode/Album.php index 183007782ce..15e7732c2be 100644 --- a/library/ZendAfi/Controller/Action/Helper/ListViewMode/Album.php +++ b/library/ZendAfi/Controller/Action/Helper/ListViewMode/Album.php @@ -138,4 +138,10 @@ class ZendAfi_Controller_Action_Helper_ListViewMode_Album extends ZendAfi_Contro public function getStrategyLabel() { return 'album'; } + + + protected function getSearchColumns() { + return ['titre', + 'type_doc_id']; + } } \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/DigitalResource/Dashboard/Harvest.php b/library/ZendAfi/View/Helper/DigitalResource/Dashboard/Harvest.php index e3f8e6aa9dd..4f1fff36495 100644 --- a/library/ZendAfi/View/Helper/DigitalResource/Dashboard/Harvest.php +++ b/library/ZendAfi/View/Helper/DigitalResource/Dashboard/Harvest.php @@ -155,20 +155,26 @@ class ZendAfi_View_Helper_DigitalResource_Dashboard_Harvest extends ZendAfi_View if(!$count = $config->countAlbums()) return $this->_tagWarning($this->_('Aucun album présent pour cette ressource')); - $first_album = Class_Album::findFirstWithPosterBy(['type_doc_id' => $config->getDocType(), - 'order' => 'titre asc']); - $albums_link = $this->_tagAnchor($this->view->absoluteUrl(['module' => 'admin', 'controller' => 'album', 'action' => 'index', - 'cat_id' => $first_album->getRootCategoryId()], null, true), + 'title_search' => $config->getDocType()], null, true), $this->_('Voir les albums'), ['target' => '_blank']); return implode([$this->_tag('h4', $this->_('Nombre d\'albums présents dans Bokeh : %d', $count)), $albums_link, - $this->_tag('h4', + $this->_thumbnailing($config)]); + } + + + protected function _thumbnailing($config) { + if (!$first_album = Class_Album::findFirstWithPosterBy(['type_doc_id' => $config->getDocType(), + 'order' => 'titre asc'])) + return ''; + + return implode([$this->_tag('h4', $this->_('Tentative de vignettage de l\'album "%s" : ', $first_album->getTitre())), $this->_tagPre($this->_('Image source : %s', $first_album->getPoster())), $this->_renderThumbnailerLog($first_album)]); diff --git a/library/digital_resources/DiMusic/tests/DiMusicTest.php b/library/digital_resources/DiMusic/tests/DiMusicTest.php index d7e84caa5d2..20301543a77 100644 --- a/library/digital_resources/DiMusic/tests/DiMusicTest.php +++ b/library/digital_resources/DiMusic/tests/DiMusicTest.php @@ -133,8 +133,8 @@ class DiMusicDashboardActivatedTest extends DiMusicActivatedTestCase { ->assertSave(); Class_WebService_BibNumerique_Vignette::setHttpClient($this->mock() - ->whenCalled('open_url') - ->answers(true)); + ->whenCalled('getResponse') + ->answers(new Class_Testing_HttpResponse(['Body' => true]))); ZendAfi_Auth::getInstance() ->logUser($this->fixture('Class_Users', @@ -179,7 +179,7 @@ class DiMusicDashboardActivatedTest extends DiMusicActivatedTestCase { /** @test */ public function harvestUrlShouldBeDisplay() { - $this->assertContains('<pre>https://export.divercities.eu/oai?verb=ListRecords&metadataPrefix=oai1dtouch_dc&set=music</pre>', + $this->assertContains('<pre>https://export.divercities.eu/oai?verb=ListRecords&metadataPrefix=oai1dtouch_dc&set=music</pre>', $this->_response->getBody()); } diff --git a/library/digital_resources/Skilleos/tests/SkilleosTest.php b/library/digital_resources/Skilleos/tests/SkilleosTest.php index f93255d6371..7ac2a9cbebf 100644 --- a/library/digital_resources/Skilleos/tests/SkilleosTest.php +++ b/library/digital_resources/Skilleos/tests/SkilleosTest.php @@ -191,17 +191,14 @@ abstract class SkilleosServiceTestCase extends AbstractControllerTestCase { ->with('http://moncompte.skilleos.com/rest/api/trainings', ['headers' => ['Authorization' => "Bearer YTEzMDA1M2Q1ZGRmYmE0YjJkNWQ3MGY3ZGUyYTI3ZWJkMjBjOGI2NzIzMDIzMDc0MDAyYTE0NGJjMTRmMzkzMg"]]) ->answers($results_json) - ->whenCalled('open_url') - ->with('https://moncompte.skilleos.com/uploads/ressources/default/0001/11/thumb_10683_default_big.png') - ->answers(null) - ->whenCalled('open_url') + ->whenCalled('getResponse') ->with('https://moncompte.skilleos.com/uploads/ressources/default/0001/12/thumb_11659_default_big.png') - ->answers(null) + ->answers(new Class_Testing_HttpResponse(['Body' => null])) - ->whenCalled('open_url') + ->whenCalled('getResponse') ->with('https://moncompte.skilleos.com/uploads/ressources/default/0001/11/thumb_10672_default_big.png') - ->answers(null) + ->answers(new Class_Testing_HttpResponse(['Body' => null])) ->beStrict(); diff --git a/library/digital_resources/StoryPlayR/tests/StoryPlayRTest.php b/library/digital_resources/StoryPlayR/tests/StoryPlayRTest.php index d407c124c34..2507c83340c 100644 --- a/library/digital_resources/StoryPlayR/tests/StoryPlayRTest.php +++ b/library/digital_resources/StoryPlayR/tests/StoryPlayRTest.php @@ -107,9 +107,11 @@ class StoryPlayRDashboardActivatedTest extends StoryPlayRActivatedTestCase { 'https://preprod.storyplayr.com/api/opds-with-links'); Class_WebService_BibNumerique_Vignette::setHttpClient($this->mock() - ->whenCalled('open_url') + ->whenCalled('getResponse') ->with('https://preprod.storyplayr.com/api/library/17fcdd4f-0c1c-4515-a0cf-594f41b03550/thumbnail/large') - ->answers('image')); + ->answers(new Class_Testing_HttpResponse(['Body' => 'image']))); + + $album = $this->fixture('Class_Album', ['id' => 20, diff --git a/library/digital_resources/ToutApprendre/tests/ToutApprendreTest.php b/library/digital_resources/ToutApprendre/tests/ToutApprendreTest.php index 1241af5ef9c..2b44f4a8bd0 100644 --- a/library/digital_resources/ToutApprendre/tests/ToutApprendreTest.php +++ b/library/digital_resources/ToutApprendre/tests/ToutApprendreTest.php @@ -129,12 +129,6 @@ class ToutApprendreDashboardActivatedTest extends ToutApprendreActivatedTestCase } - /** @test */ - public function sourceImageShouldBeValid() { - $this->assertXPathContentContains('//pre','Image source : '); - } - - /** @test */ public function doctypeImageUrlShouldBePresent() { $this->assertXPath('//h4/img[contains(@src, "/digital-resource/typedoc-icon/id/ToutApprendre")]'); diff --git a/tests/library/Class/WebService/Album/VignetteTest.php b/tests/library/Class/WebService/Album/VignetteTest.php index ce93a68cda6..2f56063f7b1 100644 --- a/tests/library/Class/WebService/Album/VignetteTest.php +++ b/tests/library/Class/WebService/Album/VignetteTest.php @@ -75,9 +75,8 @@ abstract class Class_WebService_Album_VignetteBlancheNeigeTestCase extends Class $this->_http_client - ->whenCalled('open_url') - ->with('http://mediatheque.com/blanche_neige.jpg') - ->answers('an image'); + ->whenCalled('getResponse') + ->answers(new Class_Testing_HttpResponse(['Body' => 'an image'])); $this->_vignette->setFileWriter($this->_file_writer = Storm_Test_ObjectWrapper::mock()); $this->_file_writer @@ -178,9 +177,8 @@ class Class_WebService_Album_VignetteBlancheNeigeErrorsTest extends Class_WebSer /** @test */ public function withoutDataShouldNotSaveImage() { $this->_http_client - ->whenCalled('open_url') - ->with($this->_album->getPoster()) - ->answers(''); + ->whenCalled('getResponse') + ->answers(new Class_Testing_HttpResponse(['Body' => ''])); $this->_vignette->updateAlbum($this->_album); $this->assertFalse($this->_file_writer->methodHasBeenCalled('putContents')); -- GitLab