diff --git a/.gitattributes b/.gitattributes index 00ec2a3c55500232d08093eee4bf51623e942d04..15ce8918dae841c583f55f369cbc37bac890b4bd 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3449,6 +3449,7 @@ tests/application/modules/admin/controllers/ProfilControllerPageAccueilTest.php tests/application/modules/admin/controllers/ProfilControllerProfilJeunesseAndAdultesWithMenusTest.php -text tests/application/modules/admin/controllers/ProfilControllerTest.php -text tests/application/modules/admin/controllers/SystemeControllerTest.php -text +tests/application/modules/admin/controllers/SystemeControllerWebServicesTest.php -text tests/application/modules/admin/controllers/UploadControllerTest.php -text tests/application/modules/admin/controllers/UserGroupControllerTest.php -text tests/application/modules/admin/controllers/UsersControllerTest.php -text diff --git a/application/modules/admin/views/scripts/systeme/webservices.phtml b/application/modules/admin/views/scripts/systeme/webservices.phtml index 7a55b7ae0034f50ea95b215ffe4df577f9b04eb3..f3a8f278c2c9adca18666827b3d4352a547b8137 100644 --- a/application/modules/admin/views/scripts/systeme/webservices.phtml +++ b/application/modules/admin/views/scripts/systeme/webservices.phtml @@ -1,21 +1,18 @@ <?php echo '<div class="web_services">'; echo '<ul>'; -foreach($this->services as $id_service => $service) -{ +foreach($this->services as $id_service => $service) { echo '<li class="service"><a class="ws" href="'.BASE_URL.'/admin/systeme/webservices/id_service/'.$id_service.'"><b>'.$id_service.'</b></a>'; echo '<ul>'; - $id_fonction=0; - foreach($service["services"] as $fonction) - { + $id_fonction = 0; + foreach($service["services"] as $fonction) { $id_fonction++; echo '<li class="fonction"><a class="ws" href="'.BASE_URL.'/admin/systeme/webservices/id_service/'.$id_service.'/id_fonction/'.$id_fonction.'">'.str_replace("@","",$fonction).'</a>'; - if($this->tests[$id_service][$id_fonction]) - { + if (isset($this->tests[$id_service][$id_fonction])) { $texte=$this->tests[$id_service][$id_fonction]; //if(is_array($texte)) //{ - echo '<pre style="font-size:11px;width:680px;max-height:290px;overflow:auto;background-color:#F0F0F0;padding:3px;border:1px solid #C8C8C8">'; + echo '<pre class="resultat" style="font-size:11px;width:680px;max-height:290px;overflow:auto;background-color:#F0F0F0;padding:3px;border:1px solid #C8C8C8">'; print_r($texte); echo '</pre>'; //} diff --git a/library/Class/WebService/AllServices.php b/library/Class/WebService/AllServices.php index a5cd3153236dcb0373cac94bebad9398019149bc..d0e440aecf0dde4e0e71e0c71f95bdb446e6f17c 100644 --- a/library/Class/WebService/AllServices.php +++ b/library/Class/WebService/AllServices.php @@ -76,7 +76,7 @@ class Class_WebService_AllServices ), "Fnac" => array ( - "valeurs" => array("isbn" => "978-2-07-061239-0"), + "valeurs" => array("isbn" => "978-2-7427-6501-0"), "services" => array("getResume(@isbn)") ), "OAI" => array @@ -126,6 +126,7 @@ class Class_WebService_AllServices if(!$id_service) return false; $instruction="\$cls=new Class_WebService_".$id_service."();"; eval($instruction); + $num_fonction = 0; foreach($this->services[$id_service]["services"] as $instruction) { $num_fonction++; diff --git a/library/Class/WebService/Fnac.php b/library/Class/WebService/Fnac.php index 69be45a65ea311653e52ed616df1b952dddf8250..309c4471dd516aa613bfdda3cdd978db0701c016 100644 --- a/library/Class/WebService/Fnac.php +++ b/library/Class/WebService/Fnac.php @@ -1,6 +1,6 @@ <?php /** - * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. * * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by @@ -43,10 +43,9 @@ class Class_WebService_Fnac } //------------------------------------------------------------------------------------------------------ -// Résumé de l'editeur +// Résumé de l'editeur //------------------------------------------------------------------------------------------------------ - public function getResume($isbn) - { + public function getResume($isbn) { if(!$isbn) return false; $isbn=str_replace("-","",$isbn); @@ -56,22 +55,17 @@ class Class_WebService_Fnac $httpClient->setUri($url); $response = $httpClient->request(); $data = $response->getBody(); - - // Bloc editeur - $pos=strPos($data,"avisediteur"); + $matches = array(); + $pos=striPos($data,"resume"); if(!$pos) - return false; + return array(); - $pos=striPos($data,"lireLaSuite",$pos); - if(!$pos) - return false; + $pos = strPos($data,">",$pos)+1; + $posfin = strPos($data,"</div",$pos); + $resume = substr($data,$pos,($posfin-$pos)); - $pos=strPos($data,">",$pos)+1; - $posfin=strPos($data,"</div>",$pos); - $resume=substr($data,$pos,($posfin-$pos)); - //tracedebug($resume,true); - return $resume; + return trim(str_replace('Avis de la Fnac :', '', strip_tags($resume))); } } \ No newline at end of file diff --git a/tests/application/modules/admin/controllers/SystemeControllerTest.php b/tests/application/modules/admin/controllers/SystemeControllerTest.php index 067c057d4c302553ef0a4b6be380df5451309b52..1d35a625bf9fe29ab1035c2358e81d54dc5d58ad 100644 --- a/tests/application/modules/admin/controllers/SystemeControllerTest.php +++ b/tests/application/modules/admin/controllers/SystemeControllerTest.php @@ -21,29 +21,6 @@ require_once 'AdminAbstractControllerTestCase.php'; -class SystemeControllerWebServicesActionTest extends Admin_AbstractControllerTestCase { - public function setUp() { - parent::setUp(); - $this->dispatch('admin/systeme/webservices'); - } - - - /** @test */ - public function titleShouldBeTestDesWebServices() { - $this->assertXPathContentContains('//h1', 'Test des Web Services'); - } - - - /** @test */ - public function amazonRendAvisShouldBeVisible() { - $this->assertXPathContentContains('//a[contains(@href, "webservices/id_service/Amazon/id_fonction/1")]', - 'rend_avis(isbn,page)'); - } -} - - - - class SystemeControllerMailTestActionTest extends Admin_AbstractControllerTestCase { public function setUp() { parent::setUp(); diff --git a/tests/application/modules/admin/controllers/SystemeControllerWebServicesTest.php b/tests/application/modules/admin/controllers/SystemeControllerWebServicesTest.php new file mode 100644 index 0000000000000000000000000000000000000000..8f3b9294d3b13539f241c44deaf42d76d2425bf6 --- /dev/null +++ b/tests/application/modules/admin/controllers/SystemeControllerWebServicesTest.php @@ -0,0 +1,59 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 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). + * + * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +require_once 'AdminAbstractControllerTestCase.php'; + +class SystemeControllerWebServicesIndexActionTest extends Admin_AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + $this->dispatch('admin/systeme/webservices'); + } + + + /** @test */ + public function titleShouldBeTestDesWebServices() { + $this->assertXPathContentContains('//h1', 'Test des Web Services'); + } + + + /** @test */ + public function amazonRendAvisShouldBeVisible() { + $this->assertXPathContentContains('//a[contains(@href, "webservices/id_service/Amazon/id_fonction/1")]', + 'rend_avis(isbn,page)'); + } +} + + + + +class SystemeControllerWebServicesActionTest extends Admin_AbstractControllerTestCase { + /** + * @group longtest + * @group integration + * @test + */ + public function webServiceFnacGetResumeShouldWork() { + $this->dispatch('/admin/systeme/webservices/id_service/Fnac/id_fonction/1'); + $this->assertXPathContentContains('//pre[@class="resultat"]', + 'Tandis que Lisbeth Salander'); + } +} + +?> \ No newline at end of file