diff --git a/VERSIONS_WIP/86160 b/VERSIONS_WIP/86160 new file mode 100644 index 0000000000000000000000000000000000000000..8f4a0caa0dc2fb9bb3c960058eecc2ad9cf92ea4 --- /dev/null +++ b/VERSIONS_WIP/86160 @@ -0,0 +1 @@ + - ticket #86160 : maintenance des enrichissements Premiere \ No newline at end of file diff --git a/library/Class/WebService/Fnac.php b/library/Class/WebService/Fnac.php index 47fea507b1745d35b0aa5f6a2ad22e98166074ab..a793f23424d5d30cff739e0d850864083960bde8 100644 --- a/library/Class/WebService/Fnac.php +++ b/library/Class/WebService/Fnac.php @@ -56,6 +56,17 @@ class Class_WebService_Fnac extends Class_WebService_Abstract { } + public function httpGet($url,$options = []) { + return parent::httpGet($url, ['headers' => $this->httpHeaders()]); + } + + + public function httpHeaders() { + return ['User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64; rv:66.0) Gecko/20100101 Firefox/66.0', + 'Accept-Language' => 'fr-FR']; + } + + public function getUrlLireLaSuite($data) { $pos = ($pos = striPos($data,"summary")) ? $pos : striPos($data, 'resume'); diff --git a/library/Class/WebService/Premiere.php b/library/Class/WebService/Premiere.php index 722cc0181afc2f3d1f657b67f98a0ddc396802ba..83f331afe65c78986af92df9f723eda477d949c6 100644 --- a/library/Class/WebService/Premiere.php +++ b/library/Class/WebService/Premiere.php @@ -18,15 +18,10 @@ * along with BOKEH; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -////////////////////////////////////////////////////////////////////////////////////////// -// OPAC3 - PREMIERE.fr -////////////////////////////////////////////////////////////////////////////////////////// -class Class_WebService_Premiere { - var $url_base; // Urls de base - function __construct() - { +class Class_WebService_Premiere { + function __construct() { $url_base="http://www.premiere.fr"; $this->url_base["root"]=$url_base; $this->url_base["resume"]=$url_base."/film/@TITRE@/"; @@ -44,14 +39,11 @@ class Class_WebService_Premiere { return array(); } -//------------------------------------------------------------------------------------------------------ -// Résumé -//------------------------------------------------------------------------------------------------------ + function get_resume($titre) { - // Changer l'url pour recuperer la page $titre=$this->encoder_titre($titre); $url=str_replace("@TITRE@",$titre,$this->url_base["resume"]); - // Get http de la page + try{ $httpClient = Class_HttpClientFactory::getInstance()->newHttpClient(); $httpClient->setUri($url); @@ -63,11 +55,11 @@ class Class_WebService_Premiere { } // Recherche du bon bloc - $start = '<div class="field-item even" property="content:encoded">'; + $start = 'Synopsis : '; if (!$pos = strPos($data, $start)) return ''; $pos = $pos + strlen($start); - $posfin=strPos($data,'">',$pos); + $posfin=strPos($data,'/>',$pos); return trim(strip_tags(substr($data, $pos, ($posfin-$pos)))); } diff --git a/tests/application/modules/admin/controllers/SystemeControllerWebServicesTest.php b/tests/application/modules/admin/controllers/SystemeControllerWebServicesTest.php index 0834aa3952b5512b591f6e38bb9521869a40787d..e562f28fe138b60f94b116383acdd222741573c0 100644 --- a/tests/application/modules/admin/controllers/SystemeControllerWebServicesTest.php +++ b/tests/application/modules/admin/controllers/SystemeControllerWebServicesTest.php @@ -54,13 +54,11 @@ class SystemeControllerWebServicesActionTest extends Admin_AbstractControllerTes Class_AdminVar::set('WEBSERVICE_TEST', 1); $this->dispatch('/admin/systeme/webservices/id_service/Fnac/id_fonction/1'); $this->assertXPathContentContains('//pre[@class="resultat"]', - 'Un campus prestigieux figé sous la neige', - $this->_response->getBody()); + 'Un campus prestigieux figé sous la neige'); } /** - * @group no-ci * @group longtest * @group integration * @test @@ -70,6 +68,6 @@ class SystemeControllerWebServicesActionTest extends Admin_AbstractControllerTes $this->dispatch('/admin/systeme/webservices/id_service/Premiere/id_fonction/1', true); $this->assertXPathContentContains('//pre[@class="resultat"]', - 'Jake Sully est un ancien marine', $this->_response->getBody()); + 'Jake Sully est un ancien marine'); } } \ No newline at end of file diff --git a/tests/library/Class/WebService/FnacTest.php b/tests/library/Class/WebService/FnacTest.php index 37b8ffbed8c7b9ca589566dfd735e3bd64b52320..60fd00648a41de9ca977f35c8277d374ce4b7f30 100644 --- a/tests/library/Class/WebService/FnacTest.php +++ b/tests/library/Class/WebService/FnacTest.php @@ -20,18 +20,32 @@ */ -abstract class FnacTestCase extends PHPUnit_Framework_TestCase { +abstract class FnacTestCase extends ModelTestCase { protected $_fnac; protected $_http_client; public function setUp() { $this->_fnac = new Class_WebService_Fnac(); - $this->_http_client = Storm_Test_ObjectWrapper::mock(); + $this->_http_client = $this->mock()->beStrict(); Class_WebService_Fnac::setDefaultHttpClient($this->_http_client); } + protected function _openUrlWillAnswer($url, $answer) { + $this->_http_client + ->whenCalled('open_url') + ->with($url, ['headers' => $this->_fnac->httpHeaders()]) + ->answers($answer); + + return $this; + } + + protected function _fixtureFileContent($file) { + return file_get_contents(__DIR__ . '/../../../fixtures/' . $file); + } + + public function tearDown() { Class_WebService_Fnac::setDefaultHttpClient(null); parent::tearDown(); @@ -42,23 +56,14 @@ abstract class FnacTestCase extends PHPUnit_Framework_TestCase { class FnacHarryPotterTest extends FnacTestCase { - public function setup() { - parent::setUp(); - - $this->_http_client - ->whenCalled('open_url') - ->with('http://recherche.fnac.com/r/2070572676') - ->answers(file_get_contents(realpath(dirname(__FILE__)). '/../../../fixtures/fnac_harry_potter_front.html')) - - ->whenCalled('open_url') - ->with('http://livre.fnac.com/a1715839/Harry-Potter-T6-Harry-Potter-et-le-Prince-de-Sang-Mele-J-K-Rowling') - ->answers(file_get_contents(realpath(dirname(__FILE__)). '/../../../fixtures/fnac_harry_potter_suite.html')) - ->beStrict(); - } - - /** @test */ public function getResumeShouldFetchItFromPotterSuite() { + $this->_openUrlWillAnswer('http://recherche.fnac.com/r/2070572676', + $this->_fixtureFileContent('fnac_harry_potter_front.html')) + ->_openUrlWillAnswer('http://livre.fnac.com/a1715839/Harry-Potter-T6-Harry-Potter-et-le-Prince-de-Sang-Mele-J-K-Rowling', + $this->_fixtureFileContent('fnac_harry_potter_suite.html')) + ; + $resume = $this->_fnac->getResume('2-07-057267-6'); $this->assertContains('Harry, Ron et Hermione entrent', $resume); $this->assertContains('Le sens des responsabilités et du sacrifice, revêtent', $resume); @@ -69,28 +74,18 @@ class FnacHarryPotterTest extends FnacTestCase { class FnacMilleniumTest extends FnacTestCase { - public function setup() { - parent::setUp(); - - $this->_http_client - ->whenCalled('open_url') - ->with('http://recherche.fnac.com/r/9782742765010') - ->answers(file_get_contents(realpath(dirname(__FILE__)). '/../../../fixtures/fnac_millenium_front.html')) - - ->whenCalled('open_url') - ->with('http://livre.fnac.com/a1891354/Millenium-Tome-2-La-fille-qui-revait-d-un-bidon-d-essence-et-d-une-allumette-Stieg-Larsson?NUMERICAL=Y#FORMAT=ePub') - ->answers(file_get_contents(realpath(dirname(__FILE__)). '/../../../fixtures/fnac_millenium_suite.html')) - - ->whenCalled('open_url') - ->with('http://livre.fnac.com/a1891354/Millenium-Tome-2-La-fille-qui-revait-d-un-bidon-d-essence-et-d-une-allumette-Stieg-Larsson#ficheResume') - ->answers(file_get_contents(realpath(dirname(__FILE__)). '/../../../fixtures/fnac_millenium_suite.html')) + /** @test */ + public function getResumeShouldFetchItFromMilleniumSuite() { + $this->_openUrlWillAnswer('http://recherche.fnac.com/r/9782742765010', + $this->_fixtureFileContent('fnac_millenium_front.html')) - ->beStrict(); - } + ->_openUrlWillAnswer('http://livre.fnac.com/a1891354/Millenium-Tome-2-La-fille-qui-revait-d-un-bidon-d-essence-et-d-une-allumette-Stieg-Larsson?NUMERICAL=Y#FORMAT=ePub', + $this->_fixtureFileContent('fnac_millenium_suite.html')) + ->_openUrlWillAnswer('http://livre.fnac.com/a1891354/Millenium-Tome-2-La-fille-qui-revait-d-un-bidon-d-essence-et-d-une-allumette-Stieg-Larsson#ficheResume', + $this->_fixtureFileContent('fnac_millenium_suite.html')) + ; - /** @test */ - public function getResumeShouldFetchItFromMilleniumSuite() { $resume = $this->_fnac->getResume('978-2-7427-6501-0'); $this->assertEquals('Tandis que Lisbeth Salander coule des journées supposées tranquilles aux Caraïbes', $resume); @@ -101,22 +96,10 @@ class FnacMilleniumTest extends FnacTestCase { class FnactNoLinkFoundTest extends FnacTestCase { - public function setup() { - parent::setUp(); - - $this->_http_client - ->whenCalled('open_url') - ->with('http://recherche.fnac.com/r/2070572676') - ->answers('bla bla bla') - ->beStrict(); - } - - /** @test */ public function getResumeShourdReturnEmptyString() { + $this->_openUrlWillAnswer('http://recherche.fnac.com/r/2070572676', 'bla bla bla'); $resume = $this->_fnac->getResume('2-07-057267-6'); $this->assertEmpty($resume); } } - -?> \ No newline at end of file