diff --git a/tests/library/Class/WebService/SIGB/CarthameTest.php b/tests/library/Class/WebService/SIGB/CarthameTest.php index c5a5636d35b73e89f1cb31498fff5d04613058fe..d2e99611c43a6dc69e987c351a261dcfbd08c09c 100644 --- a/tests/library/Class/WebService/SIGB/CarthameTest.php +++ b/tests/library/Class/WebService/SIGB/CarthameTest.php @@ -18,12 +18,22 @@ * along with AFI-OPAC 2.0; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -class CarthameGetServiceTest extends PHPUnit_Framework_TestCase { - public function setUp() { + +abstract class CarthameTestCase extends Storm_Test_ModelTestCase { + public function tearDown() { Class_WebService_SIGB_Carthame::reset(); + parent::tearDown(); + } +} + + +class CarthameGetServiceTest extends CarthameTestCase { + public function setUp() { + parent::setUp(); $this->service = Class_WebService_SIGB_Carthame::getService(['url_serveur' => 'http://ifr.ro/webservices/index.php']); } + /** @test */ public function getServiceShouldCreateAnInstanceOfCarthameService() { $this->assertInstanceOf('Class_WebService_SIGB_Carthame_Service', @@ -37,18 +47,13 @@ class CarthameGetServiceTest extends PHPUnit_Framework_TestCase { /** @test */ public function getServiceWithoutSchemeShouldAddHttpScheme() { - Class_WebService_SIGB_Carthame::reset(); $this->service = Class_WebService_SIGB_Carthame::getService(['url_serveur' => 'ifr.ro/webservices/index.php']); $this->assertEquals('http://ifr.ro/webservices/index.php', $this->service->getServerRoot()); } - } -abstract class CarthameTestCase extends Storm_Test_ModelTestCase { - /** @var Storm_Test_ObjectWrapper */ +abstract class CarthameOperationTestCase extends CarthameTestCase { protected $mock_web_client; - - /** @var Class_WebService_SIGB_Carthame_Service */ protected $service; public function setUp() { @@ -64,78 +69,7 @@ abstract class CarthameTestCase extends Storm_Test_ModelTestCase { } -class KarviTest extends Storm_Test_ModelTestCase { - /** @var Storm_Test_ObjectWrapper */ - protected $mock_web_client; - - /** @var Class_WebService_SIGB_Carthame_Service */ - protected $service; - - public function setUp() { - parent::setUp(); - $this->mock_web_client = Storm_Test_ObjectWrapper::on(new Class_WebService_SimpleWebClient()) - ->whenCalled('open_url') - ->answers(''); - - $this->service = Class_WebService_SIGB_Carthame::getService( - ['url_serveur' => 'http://ifr.ro/webservices/index.php', - 'key' => 'MyClientId']) - ->setWebClient($this->mock_web_client); - - $this->pbarroca = Class_Users::newInstance() - ->setLogin('pbarroca') - ->setPassword('1974'); - - $this->_exemplaire_millenium = Class_Exemplaire::newInstanceWithId(123) - ->setIdOrigine('Millenium'); - } - - - /** @test */ - public function getNoticeRequestShouldContainMyClientId() { - $this->service->getNotice('I86355'); - $this->assertQueryContains('MyClientId'); - } - - - /** @test */ - public function getEmprunteurRequestShouldContainMyClientId() { - $this->service->getEmprunteur($this->pbarroca); - $this->assertQueryContains('MyClientId'); - } - - - /** @test */ - public function reserverExemplaireRequestShouldContainMyClientId() { - $this->service->reserverExemplaire($this->pbarroca, - $this->_exemplaire_millenium, - 'Institut F'); - $this->assertQueryContains('MyClientId'); - } - - - /** @test */ - public function supprimerReservationRequestShouldContainMyClientId() { - $this->service->supprimerReservation($this->pbarroca, '42'); - $this->assertQueryContains('MyClientId'); - } - - - /** @test */ - public function prolongerPretRequestShouldContainMyClientId() { - $this->service->prolongerPret($this->pbarroca, '42'); - $this->assertQueryContains('MyClientId'); - } - - - protected function assertQueryContains($value) { - $query = $this->mock_web_client->getFirstAttributeForLastCallOn('open_url'); - $this->assertTrue(false !== strpos($query, $value), $query); - } -} - - -class CarthameNoticeAlbatorTest extends CarthameTestCase { +class CarthameNoticeAlbatorTest extends CarthameOperationTestCase { /** @var Class_WebService_SIGB_Notice */ protected $albator; @@ -165,7 +99,7 @@ class CarthameNoticeAlbatorTest extends CarthameTestCase { -class CarthameAnonymousNoticeTest extends CarthameTestCase { +class CarthameAnonymousNoticeTest extends CarthameOperationTestCase { /** @var Class_WebService_SIGB_Notice */ protected $anonymous; @@ -258,46 +192,36 @@ class CarthameAnonymousNoticeTest extends CarthameTestCase { -class CarthameEmprunteurPatrickBTest extends CarthameTestCase { +class CarthameEmprunteurPatrickBTest extends CarthameOperationTestCase { /** @var Class_WebService_SIGB_Emprunteur */ protected $emprunteur; public function setUp() { parent::setUp(); - $exemplaire = Class_Exemplaire::newInstanceWithId(3, - ['id_origine' => 'L8984', - 'id_notice' => '123', - 'id_bib' => 47]); - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Exemplaire') - ->whenCalled('findFirstBy')->answers(null) - - ->whenCalled('findFirstBy') - ->with(['id_origine' => 'L8984']) - ->answers($exemplaire); - + $exemplaire = $this->fixture('Class_Exemplaire', ['id' => 3, + 'id_origine' => 'L8984', + 'id_notice' => '123', + 'id_bib' => 47]); - Class_Notice::getLoader() - ->newInstanceWithId(123) - ->setTitrePrincipal('Harry Potter') - ->setAuteurPrincipal('JK Rowling'); + $this->fixture('Class_Notice', ['id' => 123, + 'titre_principal' => 'Harry Potter', + 'auteur_principal' => 'JK Rowling']); - Class_Bib::getLoader() - ->newInstanceWithId(47) - ->setLibelle('Bucarest'); + $this->fixture('Class_Bib', ['id' => 47, + 'libelle' => 'Bucarest']); $this->mock_web_client->whenCalled('open_url') ->with('http://ifr.ro/webservices/index.php?sigb=ktm&version=standalone&action=login&username=pbarroca&password=1974') ->answers(CarthameTestFixtures::createEmprunteurPatrickBLoginXml()) - ->getWrapper() ->whenCalled('open_url') ->with('http://ifr.ro/webservices/index.php?sigb=ktm&version=standalone&action=accountDetails&userid=3') ->answers(CarthameTestFixtures::createEmprunteurPatrickBXml()) ; $this->emprunteur = $this->service->getEmprunteur( - Class_Users::getLoader()->newInstance() + Class_Users::newInstance() ->setLogin('pbarroca') ->setPassword('1974')); @@ -442,12 +366,15 @@ class CarthameEmprunteurPatrickBTest extends CarthameTestCase { } -class CarthameOperationsTest extends CarthameTestCase { +class CarthameOperationsTest extends CarthameOperationTestCase { public function setUp() { parent::setUp(); - $this->_exemplaire_millenium = Class_Exemplaire::getLoader() - ->newInstanceWithId(123) - ->setIdOrigine('Millenium'); + $this->_exemplaire_millenium = $this->fixture('Class_Exemplaire', + ['id' => 123, + 'id_origine' => 'Millenium']); + $this->_user = Class_Users::newInstance() + ->setLogin('pbarroca') + ->setPassword('1974'); } @@ -488,9 +415,7 @@ class CarthameOperationsTest extends CarthameTestCase { $this->assertEquals( array('statut' => true, 'erreur' => ''), - $this->service->reserverExemplaire(Class_Users::getLoader()->newInstance() - ->setLogin('pbarroca') - ->setPassword('1974'), + $this->service->reserverExemplaire($this->_user, $this->_exemplaire_millenium, 'Cluj-Napoc')); @@ -520,10 +445,9 @@ class CarthameOperationsTest extends CarthameTestCase { </root>'); $this->assertEquals( - array('statut' => false, 'erreur' => 'Réservation impossible. Autorisée seulement sur Iasi,Timisoara'), - $this->service->reserverExemplaire(Class_Users::getLoader()->newInstance() - ->setLogin('pbarroca') - ->setPassword('1974'), + ['statut' => false, + 'erreur' => 'Réservation impossible. Autorisée seulement sur Iasi,Timisoara'], + $this->service->reserverExemplaire($this->_user, $this->_exemplaire_millenium, 'Cluj-Napoc')); @@ -559,10 +483,9 @@ class CarthameOperationsTest extends CarthameTestCase { ->beStrict(); $this->assertEquals( - array('statut' => false, 'erreur' => $message), - $this->service->reserverExemplaire(Class_Users::getLoader()->newInstance() - ->setLogin('pbarroca') - ->setPassword('1974'), $this->_exemplaire_millenium, '1') + ['statut' => false, 'erreur' => $message], + $this->service->reserverExemplaire($this->_user, + $this->_exemplaire_millenium, '1') ); } @@ -589,10 +512,8 @@ class CarthameOperationsTest extends CarthameTestCase { '); $this->assertEquals( - array('statut' => true, 'erreur' => ''), - $this->service->supprimerReservation(Class_Users::getLoader()->newInstance() - ->setLogin('pbarroca') - ->setPassword('1974'), 'MillRes') + ['statut' => true, 'erreur' => ''], + $this->service->supprimerReservation($this->_user, 'MillRes') ); } @@ -613,10 +534,8 @@ class CarthameOperationsTest extends CarthameTestCase { '); $this->assertEquals( - array('statut' => false, 'erreur' => 'Error from WS'), - $this->service->supprimerReservation(Class_Users::getLoader()->newInstance() - ->setLogin('pbarroca') - ->setPassword('1974'), 'HarrRes') + ['statut' => false, 'erreur' => 'Error from WS'], + $this->service->supprimerReservation($this->_user, 'HarrRes') ); } @@ -636,10 +555,8 @@ class CarthameOperationsTest extends CarthameTestCase { '); $this->assertEquals( - array('statut' => true, 'erreur' => ''), - $this->service->prolongerPret(Class_Users::getLoader()->newInstance() - ->setLogin('pbarroca') - ->setPassword('1974'), 'Millenium') + ['statut' => true, 'erreur' => ''], + $this->service->prolongerPret($this->_user, 'Millenium') ); } @@ -660,16 +577,83 @@ class CarthameOperationsTest extends CarthameTestCase { '); $this->assertEquals( - array('statut' => false, 'erreur' => 'Error from WS'), - $this->service->prolongerPret(Class_Users::getLoader()->newInstance() - ->setLogin('pbarroca') - ->setPassword('1974'), '095124224') + ['statut' => false, 'erreur' => 'Error from WS'], + $this->service->prolongerPret($this->_user, '095124224') ); } } + +class CarthameKarviTest extends CarthameTestCase { + protected $mock_web_client; + protected $service; + + public function setUp() { + parent::setUp(); + $this->mock_web_client = Storm_Test_ObjectWrapper::on(new Class_WebService_SimpleWebClient()) + ->whenCalled('open_url') + ->answers(''); + + $this->service = Class_WebService_SIGB_Carthame::getService( + ['url_serveur' => 'http://ifr.ro/webservices/index.php', + 'key' => 'MyClientId']) + ->setWebClient($this->mock_web_client); + + $this->_user = Class_Users::newInstance() + ->setLogin('pbarroca') + ->setPassword('1974'); + + $this->_exemplaire_millenium = Class_Exemplaire::newInstanceWithId(123) + ->setIdOrigine('Millenium'); + } + + + /** @test */ + public function getNoticeRequestShouldContainMyClientId() { + $this->service->getNotice('I86355'); + $this->assertQueryContains('MyClientId'); + } + + + /** @test */ + public function getEmprunteurRequestShouldContainMyClientId() { + $this->service->getEmprunteur($this->_user); + $this->assertQueryContains('MyClientId'); + } + + + /** @test */ + public function reserverExemplaireRequestShouldContainMyClientId() { + $this->service->reserverExemplaire($this->_user, + $this->_exemplaire_millenium, + 'Institut F'); + $this->assertQueryContains('MyClientId'); + } + + + /** @test */ + public function supprimerReservationRequestShouldContainMyClientId() { + $this->service->supprimerReservation($this->_user, '42'); + $this->assertQueryContains('MyClientId'); + } + + + /** @test */ + public function prolongerPretRequestShouldContainMyClientId() { + $this->service->prolongerPret($this->_user, '42'); + $this->assertQueryContains('MyClientId'); + } + + + protected function assertQueryContains($value) { + $query = $this->mock_web_client->getFirstAttributeForLastCallOn('open_url'); + $this->assertTrue(false !== strpos($query, $value), $query); + } +} + + class CarthameTestFixtures { public static function createEmprunteurPatrickBXml() { return '<?xml version="1.0"?>