Commit e57e1719 authored by Laurent's avatar Laurent

dev #86160 fix fetch premiere and FNAC description

parent c9f84563
Pipeline #6228 passed with stage
in 31 minutes and 51 seconds
- ticket #86160 : maintenance des enrichissements Premiere
\ No newline at end of file
...@@ -56,6 +56,17 @@ class Class_WebService_Fnac extends Class_WebService_Abstract { ...@@ -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) { public function getUrlLireLaSuite($data) {
$pos = ($pos = striPos($data,"summary")) ? $pos : striPos($data, 'resume'); $pos = ($pos = striPos($data,"summary")) ? $pos : striPos($data, 'resume');
......
...@@ -18,15 +18,10 @@ ...@@ -18,15 +18,10 @@
* along with BOKEH; if not, write to the Free Software * along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * 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"; $url_base="http://www.premiere.fr";
$this->url_base["root"]=$url_base; $this->url_base["root"]=$url_base;
$this->url_base["resume"]=$url_base."/film/@TITRE@/"; $this->url_base["resume"]=$url_base."/film/@TITRE@/";
...@@ -44,14 +39,11 @@ class Class_WebService_Premiere { ...@@ -44,14 +39,11 @@ class Class_WebService_Premiere {
return array(); return array();
} }
//------------------------------------------------------------------------------------------------------
// Résumé
//------------------------------------------------------------------------------------------------------
function get_resume($titre) { function get_resume($titre) {
// Changer l'url pour recuperer la page
$titre=$this->encoder_titre($titre); $titre=$this->encoder_titre($titre);
$url=str_replace("@TITRE@",$titre,$this->url_base["resume"]); $url=str_replace("@TITRE@",$titre,$this->url_base["resume"]);
// Get http de la page
try{ try{
$httpClient = Class_HttpClientFactory::getInstance()->newHttpClient(); $httpClient = Class_HttpClientFactory::getInstance()->newHttpClient();
$httpClient->setUri($url); $httpClient->setUri($url);
...@@ -63,11 +55,11 @@ class Class_WebService_Premiere { ...@@ -63,11 +55,11 @@ class Class_WebService_Premiere {
} }
// Recherche du bon bloc // Recherche du bon bloc
$start = '<div class="field-item even" property="content:encoded">'; $start = 'Synopsis : ';
if (!$pos = strPos($data, $start)) if (!$pos = strPos($data, $start))
return ''; return '';
$pos = $pos + strlen($start); $pos = $pos + strlen($start);
$posfin=strPos($data,'">',$pos); $posfin=strPos($data,'/>',$pos);
return trim(strip_tags(substr($data, $pos, ($posfin-$pos)))); return trim(strip_tags(substr($data, $pos, ($posfin-$pos))));
} }
......
...@@ -54,13 +54,11 @@ class SystemeControllerWebServicesActionTest extends Admin_AbstractControllerTes ...@@ -54,13 +54,11 @@ class SystemeControllerWebServicesActionTest extends Admin_AbstractControllerTes
Class_AdminVar::set('WEBSERVICE_TEST', 1); Class_AdminVar::set('WEBSERVICE_TEST', 1);
$this->dispatch('/admin/systeme/webservices/id_service/Fnac/id_fonction/1'); $this->dispatch('/admin/systeme/webservices/id_service/Fnac/id_fonction/1');
$this->assertXPathContentContains('//pre[@class="resultat"]', $this->assertXPathContentContains('//pre[@class="resultat"]',
'Un campus prestigieux figé sous la neige', 'Un campus prestigieux figé sous la neige');
$this->_response->getBody());
} }
/** /**
* @group no-ci
* @group longtest * @group longtest
* @group integration * @group integration
* @test * @test
...@@ -70,6 +68,6 @@ class SystemeControllerWebServicesActionTest extends Admin_AbstractControllerTes ...@@ -70,6 +68,6 @@ class SystemeControllerWebServicesActionTest extends Admin_AbstractControllerTes
$this->dispatch('/admin/systeme/webservices/id_service/Premiere/id_fonction/1', true); $this->dispatch('/admin/systeme/webservices/id_service/Premiere/id_fonction/1', true);
$this->assertXPathContentContains('//pre[@class="resultat"]', $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
...@@ -20,18 +20,32 @@ ...@@ -20,18 +20,32 @@
*/ */
abstract class FnacTestCase extends PHPUnit_Framework_TestCase { abstract class FnacTestCase extends ModelTestCase {
protected $_fnac; protected $_fnac;
protected $_http_client; protected $_http_client;
public function setUp() { public function setUp() {
$this->_fnac = new Class_WebService_Fnac(); $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); 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() { public function tearDown() {
Class_WebService_Fnac::setDefaultHttpClient(null); Class_WebService_Fnac::setDefaultHttpClient(null);
parent::tearDown(); parent::tearDown();
...@@ -42,23 +56,14 @@ abstract class FnacTestCase extends PHPUnit_Framework_TestCase { ...@@ -42,23 +56,14 @@ abstract class FnacTestCase extends PHPUnit_Framework_TestCase {
class FnacHarryPotterTest extends FnacTestCase { 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 */ /** @test */
public function getResumeShouldFetchItFromPotterSuite() { 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'); $resume = $this->_fnac->getResume('2-07-057267-6');
$this->assertContains('Harry, Ron et Hermione entrent', $resume); $this->assertContains('Harry, Ron et Hermione entrent', $resume);
$this->assertContains('Le sens des responsabilités et du sacrifice, revêtent', $resume); $this->assertContains('Le sens des responsabilités et du sacrifice, revêtent', $resume);
...@@ -69,28 +74,18 @@ class FnacHarryPotterTest extends FnacTestCase { ...@@ -69,28 +74,18 @@ class FnacHarryPotterTest extends FnacTestCase {
class FnacMilleniumTest extends FnacTestCase { class FnacMilleniumTest extends FnacTestCase {
public function setup() { /** @test */
parent::setUp(); public function getResumeShouldFetchItFromMilleniumSuite() {
$this->_openUrlWillAnswer('http://recherche.fnac.com/r/9782742765010',
$this->_http_client $this->_fixtureFileContent('fnac_millenium_front.html'))
->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'))
->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'); $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', $this->assertEquals('Tandis que Lisbeth Salander coule des journées supposées tranquilles aux Caraïbes',
$resume); $resume);
...@@ -101,22 +96,10 @@ class FnacMilleniumTest extends FnacTestCase { ...@@ -101,22 +96,10 @@ class FnacMilleniumTest extends FnacTestCase {
class FnactNoLinkFoundTest 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 */ /** @test */
public function getResumeShourdReturnEmptyString() { public function getResumeShourdReturnEmptyString() {
$this->_openUrlWillAnswer('http://recherche.fnac.com/r/2070572676', 'bla bla bla');
$resume = $this->_fnac->getResume('2-07-057267-6'); $resume = $this->_fnac->getResume('2-07-057267-6');
$this->assertEmpty($resume); $this->assertEmpty($resume);
} }
} }
?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment