diff --git a/tests/application/modules/opac/controllers/BibNumeriqueControllerDilicomTest.php b/tests/application/modules/opac/controllers/BibNumeriqueControllerDilicomTest.php new file mode 100644 index 0000000000000000000000000000000000000000..81cbc8965ccb25df4ed1e42b3960a995cf179a9f --- /dev/null +++ b/tests/application/modules/opac/controllers/BibNumeriqueControllerDilicomTest.php @@ -0,0 +1,159 @@ +<?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 + */ + + +abstract class BibNumeriqueContollerDilicomTestCase extends AbstractControllerTestCase { + protected + $_http, + $_time_source; + + public function setUp() { + parent::setUp(); + + $logged_user = $this->fixture('Class_Users', + ['id' => 6, + 'nom'=>'Pito', + 'login'=>'Chat', + 'password'=>'123456', + 'id_site' => 1, + 'idabon' => '12345', + 'user_groups' => [$this->fixture('Class_UserGroup', + ['id' => '20', + 'libelle' => 'Multimedia', + 'rights' => [Class_UserGroup::RIGHT_ACCES_PNB_DILICOM]])]]); + $logged_user->beAbonneSIGB()->assertSave(); + ZendAfi_Auth::getInstance()->logUser($logged_user); + + $this->book = $this->fixture('Class_Album', + ['id' => 3, + 'libelle' => 'Totem et Thora', + 'id_origine' => 'Dilicom-88817216', + 'external_uri' => 'http://www.edenlivres.fr/p/23416', + 'type_doc_id' => Class_TypeDoc::DILICOM, + 'isbn' => '435465', + 'usage_constraints' => [$this->fixture('Class_Album_UsageConstraint', + ['id' => 1, + 'id_album' => 3, + 'titre ' => 'Totem et Thora', + 'usage_type' => Class_Album_UsageConstraint::LOAN_CONSTRAINT, + 'order_line_id' => 'x321'])]]); + + + + RessourcesNumeriquesFixtures::activateDilicom(); + + + $this->_http = Storm_Test_ObjectWrapper::mock(); + Class_WebService_BibNumerique_Dilicom_Hub::setDefaultHttpClient($this->_http); + + $this->_http + ->whenCalled('setAuth') + ->with('afi-bib', 'secretPassword') + ->answers(null); + + $this->_time_source = new TimeSourceForTest('2014-05-02 14:14:14'); + Class_WebService_BibNumerique_Dilicom_Hub::setTimeSource($this->_time_source); + } +} + + + + +class BibNumeriqueContollerDilicomConsultBookActionTest extends BibNumeriqueContollerDilicomTestCase { + public function setUp() { + parent::setUp(); + + $this->_http + ->whenCalled('open_url') + ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/consultBook?glnContractor=123456789&orderLineId=x321' + .'&accessMedium=STREAMING' + .'&localization=IN_SITU' + .'&consultEndDate='.urlencode('2014-05-02T15:14:14+0200') + .'&ean13=435465' + .'&ipAddress=195.251.88.223' + .'&loanId='.base_convert($this->_time_source->time(), 10, 36).'63') + ->answers('{"orderLineId":"54e7473f975a2fa6aa4d3e17","consultEndDate":"2014-05-02T15:14:14+0200","loanId":"3","returnStatus":"OK","returnMessage":[],"requestId":"awvzrcttestpnbv2_000000039_201503051511","link":{"url":"https://pnb-test.centprod.com/v2//link/3056000302801/CONSULT/3/9791023501766-FGR9FJJGJCMXYMB8BO87XR9TPHDN9QNS.do","aformatDescription":"EPUB","mimetype":"application/epub+zip","ean13":"9791023501766","format":"E101"}}') + ->beStrict(); + + + $_SERVER['HTTP_X_FORWARDED_FOR'] = '195.251.88.223'; + + $this->dispatch('/bib-numerique/consult-book/id/3', true); + } + + + public function tearDown() { + Class_WebService_BibNumerique_Dilicom_Hub::setDefaultHttpClient(null); + RessourcesNumeriquesFixtures::deactivateDilicom(); + parent::tearDown(); + } + + + /** @test */ + public function openUrlShouldHaveBeenCalled() { + $this->assertTrue($this->_http->methodHasBeenCalled('open_url')); + } + + + /** @test */ + public function setAuthShouldHaveBeenCalled() { + $this->assertTrue($this->_http->methodHasBeenCalled('setAuth')); + } + + + /** @test */ + public function responseShouldRedirectToConsultBookUrl() { + $this->assertRedirectTo('https://pnb-test.centprod.com/v2//link/3056000302801/CONSULT/3/9791023501766-FGR9FJJGJCMXYMB8BO87XR9TPHDN9QNS.do'); + } +} + + + + +class BibNumeriqueContollerDilicomConsultBookWithErrorsActionTest extends BibNumeriqueContollerDilicomTestCase { + public function setUp() { + parent::setUp(); + + + $this->_http + ->whenCalled('open_url') + ->answers('{"orderLineId":"54e7473f975a2fa6aa4d3e17","consultEndDate":"","loanId":"3","returnStatus":"ERROR","returnMessage":["Crash boom"],"requestId":"awvzrcttestpnbv2_000000039_201503051511","link":{}}'); + + $_SERVER['HTTP_REFERER'] = '/viewnotice/id/3'; + + $this->dispatch('/bib-numerique/consult-book/id/3', true); + } + + + /** @test */ + public function responseShouldRedirectToReferrer() { + $this->assertRedirectTo('/viewnotice/id/3', $this->getResponseLocation()); + } + + + /** @test */ + public function errorMessageShouldBeInNotifications() { + $this->assertFlashMessengerContains('Crash boom'); + } +} + + +?> \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/BibNumeriqueControllerTest.php b/tests/application/modules/opac/controllers/BibNumeriqueControllerTest.php index bfa3cecd63a080f013929dad9d2a747da780a3cf..0f0574acd56f3a794d8e6c7eb7c462b82a9637c1 100644 --- a/tests/application/modules/opac/controllers/BibNumeriqueControllerTest.php +++ b/tests/application/modules/opac/controllers/BibNumeriqueControllerTest.php @@ -18,7 +18,6 @@ * along with BOKEH; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -require_once 'AbstractControllerTestCase.php'; class BibNumeriqueControllerViewAlbumActionTest extends AbstractControllerTestCase { /** @test */ @@ -1017,99 +1016,4 @@ class BibNumeriqueControllerFullScreenEpubTest extends BibNumeriqueControllerAlb } } - - - -class BibNumeriqueContollerConsultBookActionTest extends AbstractControllerTestCase { - protected - $_http; - - public function setUp() { - parent::setUp(); - - $logged_user = $this->fixture('Class_Users', - ['id' => 6, - 'nom'=>'Pito', - 'login'=>'Chat', - 'password'=>'123456', - 'id_site' => 1, - 'idabon' => '12345', - 'user_groups' => [$this->fixture('Class_UserGroup', - ['id' => '20', - 'libelle' => 'Multimedia', - 'rights' => [Class_UserGroup::RIGHT_ACCES_PNB_DILICOM]])]]); - $logged_user->beAbonneSIGB()->assertSave(); - ZendAfi_Auth::getInstance()->logUser($logged_user); - - $this->book = $this->fixture('Class_Album', - ['id' => 3, - 'libelle' => 'Totem et Thora', - 'id_origine' => 'Dilicom-88817216', - 'external_uri' => 'http://www.edenlivres.fr/p/23416', - 'type_doc_id' => Class_TypeDoc::DILICOM, - 'isbn' => '435465', - 'usage_constraints' => [$this->fixture('Class_Album_UsageConstraint', - ['id' => 1, - 'id_album' => 3, - 'titre ' => 'Totem et Thora', - 'usage_type' => Class_Album_UsageConstraint::LOAN_CONSTRAINT, - 'order_line_id' => 'x321'])]]); - - - - RessourcesNumeriquesFixtures::activateDilicom(); - - - $this->_http = Storm_Test_ObjectWrapper::mock(); - Class_WebService_BibNumerique_Dilicom_Hub::setDefaultHttpClient($this->_http); - $time_source = new TimeSourceForTest('2014-05-02 14:14:14'); - Class_WebService_BibNumerique_Dilicom_Hub::setTimeSource($time_source); - - - $this->_http - ->whenCalled('setAuth') - ->with('afi-bib', 'secretPassword') - ->answers(null) - - ->whenCalled('open_url') - ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/consultBook?glnContractor=123456789&orderLineId=x321' - .'&accessMedium=STREAMING' - .'&localization=IN_SITU' - .'&consultEndDate='.urlencode('2014-05-02T15:14:14+0200') - .'&ean13=435465' - .'&ipAddress=195.251.88.223' - .'&loanId='.base_convert($time_source->time(), 10, 36).'63') - ->answers('{"orderLineId":"54e7473f975a2fa6aa4d3e17","consultEndDate":"2014-05-02T15:14:14+0200","loanId":"3","returnStatus":"OK","returnMessage":[],"requestId":"awvzrcttestpnbv2_000000039_201503051511","link":{"url":"https://pnb-test.centprod.com/v2//link/3056000302801/CONSULT/3/9791023501766-FGR9FJJGJCMXYMB8BO87XR9TPHDN9QNS.do","aformatDescription":"EPUB","mimetype":"application/epub+zip","ean13":"9791023501766","format":"E101"}}') - ->beStrict(); - - - $_SERVER['HTTP_X_FORWARDED_FOR'] = '195.251.88.223'; - - $this->dispatch('/bib-numerique/consult-book/id/3', true); - } - - - public function tearDown() { - Class_WebService_BibNumerique_Dilicom_Hub::setDefaultHttpClient(null); - RessourcesNumeriquesFixtures::deactivateDilicom(); - parent::tearDown(); - } - - - /** @test */ - public function openUrlShouldHaveBeenCalled() { - $this->assertTrue($this->_http->methodHasBeenCalled('open_url')); - } - - - /** @test */ - public function setAuthShouldHaveBeenCalled() { - $this->assertTrue($this->_http->methodHasBeenCalled('setAuth')); - } - - - /** @test */ - public function responseShouldRedirectToConsultBookUrl() { - $this->assertRedirectTo('https://pnb-test.centprod.com/v2//link/3056000302801/CONSULT/3/9791023501766-FGR9FJJGJCMXYMB8BO87XR9TPHDN9QNS.do'); - } -} +?> \ No newline at end of file