-
Ghislain Loas authored36bd7d53
AbonneControllerSuggestionAchatNanookTest.php 8.26 KiB
<?php
/**
* Copyright (c) 2012-2014, 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
*/
require_once 'tests/fixtures/NanookFixtures.php';
abstract class AbstractAbonneControllerSuggestionAchatNanookTestCase extends AbstractControllerTestCase {
protected
$_storm_default_to_volatile = true,
$_francis;
public function setUp() {
parent::setUp();
$logger = $this->mock()
->whenCalled('log')->answers(true)
->whenCalled('logError')
->willDo(
function($url, $message) {
throw new RuntimeException($url . ' :: ' . $message);
});
Class_WebService_SIGB_AbstractService::setLogger($logger);
$sigb_conf = $this->fixture('Class_IntBib',
['id' => 3,
'comm_params' => ['url_serveur' => 'nanookService'],
'comm_sigb' => Class_IntBib::COM_NANOOK]);
$tatim = $this->fixture('Class_Bib', ['id' => 12,
'libelle' => 'Tatim bib',
'int_bib' => $sigb_conf]);
$sigb_conf->setIdBib(12);
$this->_francis = $this->fixture('Class_Users', ['id' => 3,
'id_sigb' => '187',
'login' => 'francis',
'password' => 'test',
'int_bib' => $sigb_conf]);
ZendAfi_Auth::getInstance()->logUser($this->_francis);
$this->mock_web_client = $this->mock();
$this->mock_web_client
->whenCalled('open_url')
->with('http://nanookService/service/AuthenticatePatron/username/francis/password/test')
->answers(NanookFixtures::albatorAuthenticatePatronResponse())
->whenCalled('open_url')
->with('http://nanookService/service/GetPatronInfo/patronId/187')
->answers(NanookFixtures::albatorPatronInfoResponse())
->whenCalled('postData')
->with('http://nanookService/service/CreateSuggest/patronId/187',
['site' => '12',
'title' => 'fu',
'author' => 'mf',
'isbnean' => '2-07-0541 27_4',
'desclink' => '',
'comment' => 'no'])
->answers(NanookFixtures::createSuggestFuSucces())
->whenCalled('postData')
->with('http://nanookService/service/CreateSuggest/patronId/187',
['site' => '12',
'title' => 'fu',
'author' => 'Ye',
'isbnean' => '2-07-0541 27_4',
'desclink' => '',
'comment' => 'no'])
->answers(NanookFixtures::createSuggestFuError())
->beStrict();
$sigb_comm = Class_IntBib::find(3)->getSIGBComm();
$sigb_comm->setWebClient($this->mock_web_client);
}
public function tearDown() {
Class_IntBib::find(3)->getSIGBComm()->setWebClient(null);
parent::tearDown();
}
}
class AbonneControllerSuggestionAchatNanookListTest extends AbstractAbonneControllerSuggestionAchatNanookTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/opac/abonne/suggestion-achat', true);
}
/** @test */
public function pageShouldContainsSuggestionFromNanook() {
$this->assertXPathContentContains('//table//tr[1]//td[2]', 'Purple for the win');
}
/** @test */
public function albatorShouldBePresent() {
$this->assertXPathContentContains('//table//tr[1]//td[3]', 'albator');
}
/** @test */
public function bibLalbelShouldBeTatimBib() {
$this->assertXPathContentContains('//table//tr[1]/td[4]', 'Tatim bib');
}
/** @test */
public function noteSuggestFromBokehShouldBePresent() {
$this->assertXPathContentContains('//table//tr[1]/td[6]', 'Suggest from Bokeh');
}
/** @test */
public function isbnShouldBePresent() {
$this->assertXPathContentContains('//table//tr[1]/td[1]', '123456789');
}
/** @test */
public function urlShouldBePresent() {
$this->assertXPathContentContains('//table//tr[1]/td[5]', 'http://www.Suggest.url');
}
}
class AbonneControllerSuggestionAchatNanookAddTest extends AbstractAbonneControllerSuggestionAchatNanookTestCase {
protected $_storm_default_to_volatile = true;
public function setUp() {
parent::setUp();
$this->dispatch('/opac/abonne/suggestion-achat-add', true);
}
/** @test */
public function formShouldContainsTextAreaForComment() {
$this->assertXPath('//form//textarea[@name="Comment"]');
}
/** @test */
public function formShouldContainsInputForTitle() {
$this->assertXPath('//form//input[@name="Title"][@placeholder="ex: Harry Potter à l\'école des sorciers"]');
}
/** @test */
public function formShouldContainsInputForAuthor() {
$this->assertXPath('//form//input[@name="Author"][@placeholder="ex: Joanne Kathleen Rowling"]');
}
/** @test */
public function formShouldContainsInputForIsbn() {
$this->assertXPath('//form//input[@name="Isbn"][@placeholder="ex: 2-07-054127-4"]');
}
/** @test */
public function formShouldContainsInputForUrl() {
$this->assertXPath('//form//input[@name="Url"][@placeholder="http://www..."]');
}
/** @test */
public function formShouldContainsSite() {
$this->assertXPath('//form//input[@name="Library"][@value="Tatim bib"][@disabled="1"]');
}
}
class AbonneControllerSuggestionAchatNanookAddPostTest extends AbstractAbonneControllerSuggestionAchatNanookTestCase {
protected $_storm_default_to_volatile = true;
public function setUp() {
parent::setUp();
$mock_transport = new MockMailTransport();
Zend_Mail::setDefaultTransport($mock_transport);
$this->postDispatch('/opac/abonne/suggestion-achat-add', ['Site' => '12',
'Title' => 'fu',
'Author' => 'mf',
'Isbn' => '2-07-0541 27_4',
'Url' => '',
'Comment' => 'no']);
}
/** @test */
public function suggestionShouldHaveBeenSend() {
$this->assertFlashMessengerContains(['notification' => ['message' => 'Suggestion d\'achat enregistrée']]);
}
/** @test */
public function shouldRedirect() {
$this->assertRedirect();
}
}
class AbonneControllerSuggestionAchatNanookAddPostErrorsTest extends AbstractAbonneControllerSuggestionAchatNanookTestCase {
protected $_storm_default_to_volatile = true;
public function setUp() {
parent::setUp();
$mock_transport = new MockMailTransport();
Zend_Mail::setDefaultTransport($mock_transport);
$this->postDispatch('/opac/abonne/suggestion-achat-add', ['Site' => '12',
'Title' => 'fu',
'Author' => 'Ye',
'Isbn' => '2-07-0541 27_4',
'Url' => '',
'Comment' => 'no']);
}
/** @test */
public function suggestionShouldHaveBeenSend() {
$this->assertFlashMessengerContains(['notification' => ['message' => 'Suggestion d\'achat enregistrée']]);
}
/** @test */
public function shouldRedirect() {
$this->assertRedirect();
}
}