Skip to content
Snippets Groups Projects
Commit 6f7ea359 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

Merge branch 'stable' into 'hotline-master'

Stable

See merge request !757
parents f40bd080 d3783cb5
Branches
Tags
1 merge request!780Master
......@@ -5,6 +5,8 @@
- ticket #20851: Améliore le contenu partagé à facebook des articles.
- ticket #22214: Correction de l'api récupération des résumés provenant de la Fnac.
05/03/2015 - v7.1.15
......
......@@ -1495,15 +1495,14 @@ class Class_Notice extends Storm_Model_Abstract {
public function findAllResumes() {
$avis = array();
$avis = [];
if($resume = $this->getResume())
$avis[] = array('source' => 'Bibliothèque',
'texte' => $resume);
$avis[] = ['source' => 'Bibliothèque',
'texte' => $resume];
$providers = array('Class_WebService_Fnac',
'Class_WebService_Babelio',
'Class_WebService_Premiere');
$providers = ['Class_WebService_Fnac',
'Class_WebService_Babelio',
'Class_WebService_Premiere'];
foreach ($providers as $provider_class) {
$provider = new $provider_class();
......
......@@ -16,31 +16,39 @@
*
* 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
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_WebService_Fnac extends Class_WebService_Abstract {
private $url = 'http://www3.fnac.com/advanced/book.do?isbn=';
protected $_search_url = 'http://recherche.fnac.com/r/';
public function getResumes($notice) {
if (!$service = $notice->getIsbnOrEan())
return array();
return [];
if ($resume = $this->getResume($service))
return array(array('source' => 'Editeur',
'texte' => $resume));
return array();
return [ ['source' => 'Editeur',
'texte' => $resume]];
return [];
}
//------------------------------------------------------------------------------------------------------
// Résumé de l'editeur
//------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------
public function getResume($isbn) {
if(!$isbn) return false;
$isbn=str_replace("-","",$isbn);
if(!$isbn)
return false;
$isbn = trim(str_replace("-","",$isbn));
$url = $this->_search_url . $isbn;
$data = self::getHttpClient()->open_url($url);
$data = self::getHttpClient()->open_url($this->url.$isbn);
$url_lire_la_suite = $this->getUrlLireLaSuite($data);
if(!$url_lire_la_suite = $this->getUrlLireLaSuite($data))
return '';
if (!($url_lire_la_suite && (new ZendAfi_Validate_Url())->isValid($url_lire_la_suite)))
return '';
......@@ -51,8 +59,8 @@ class Class_WebService_Fnac extends Class_WebService_Abstract {
public function getUrlLireLaSuite($data) {
$pos=striPos($data,"resume");
if(!$pos)
$pos = striPos($data,"resume");
if(!$pos)
return '';
$pos = strPos($data,"a href=\"",$pos)+8;
......@@ -62,6 +70,9 @@ class Class_WebService_Fnac extends Class_WebService_Abstract {
public function extractResumeFromHTML($html) {
if($pos = striPos($html, 'resMarkContent'))
return $this->extractResumeFormBlk($html);
if ($pos = striPos($html, "avisEdContent"))
return $this->extractLireLaSuiteDivAvisEditeurFromHTML($html);
......@@ -80,6 +91,22 @@ class Class_WebService_Fnac extends Class_WebService_Abstract {
}
protected function extractResumeFormBlk($html) {
$start_string = 'resMarkContent">';
if (!$pos = striPos($html, $start_string))
return '';
$pos = $pos + strlen($start_string);
$posfin = strPos($html, "</", $pos);
$resume = substr($html, $pos, ($posfin - $pos));
return trim($resume);
}
public function extractLireLaSuiteDivAvisEditeurFromHTML($html) {
$pos = strPos($html, "avisEdContent") + 15;
$posfin = strPos($html, "</div>", $pos);
......
......@@ -16,7 +16,7 @@
*
* 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
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
require_once 'AdminAbstractControllerTestCase.php';
......@@ -35,7 +35,7 @@ class SystemeControllerWebServicesIndexActionTest extends Admin_AbstractControll
/** @test */
public function amazonRendAvisShouldBeVisible() {
$this->assertXPathContentContains('//a[contains(@href, "webservices/id_service/Amazon/id_fonction/1")]',
$this->assertXPathContentContains('//a[contains(@href, "webservices/id_service/Amazon/id_fonction/1")]',
'rend_avis(isbn,page)');
}
}
......@@ -44,28 +44,28 @@ class SystemeControllerWebServicesIndexActionTest extends Admin_AbstractControll
class SystemeControllerWebServicesActionTest extends Admin_AbstractControllerTestCase {
/**
/**
* @group longtest
* @group integration
* @test
* @test
*/
public function webServiceFnacGetResumeShouldWork() {
$this->dispatch('/admin/systeme/webservices/id_service/Fnac/id_fonction/1');
$this->assertXPathContentContains('//pre[@class="resultat"]',
'Tandis que Lisbeth Salander',
$this->assertXPathContentContains('//pre[@class="resultat"]',
'Une enquête sur un réseau de prostitution dévoile des secrets d\'espionnage',
$this->_response->getBody());
}
/**
/**
* @group longtest
* @group integration
* @test
* @test
*/
public function webServicePremiereGetResumeShouldWork() {
$this->dispatch('/admin/systeme/webservices/id_service/Premiere/id_fonction/1', true);
$this->assertXPathContentContains('//pre[@class="resultat"]',
'Jake Sully est un ancien marine');
$this->assertXPathContentContains('//pre[@class="resultat"]',
'Jake Sully est un ancien marine', $this->_response->getBody());
}
}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
......@@ -16,7 +16,7 @@
*
* 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
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
......@@ -47,7 +47,7 @@ class FnactHarryPotterTest extends FnacTestCase {
$this->_http_client
->whenCalled('open_url')
->with('http://www3.fnac.com/advanced/book.do?isbn=2070572676')
->with('http://recherche.fnac.com/r/2070572676')
->answers(file_get_contents(realpath(dirname(__FILE__)). '/../../../fixtures/fnac_harry_potter_front.html'))
->whenCalled('open_url')
......@@ -74,11 +74,11 @@ class FnacMilleniumTest extends FnacTestCase {
$this->_http_client
->whenCalled('open_url')
->with('http://www3.fnac.com/advanced/book.do?isbn=9782742765010')
->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-T2-La-fille-qui-revait-d-un-bidon-d-essence-et-d-une-allumette-Stieg-Larsson')
->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'))
->beStrict();
}
......@@ -87,7 +87,7 @@ class FnacMilleniumTest extends FnacTestCase {
/** @test */
public function getResumeShouldFetchItFromPotterSuite() {
$resume = $this->_fnac->getResume('978-2-7427-6501-0');
$this->assertEquals('Lisbeth et Mickael sont de retour dans un roman aussi trépidant que le premier. Nos deux anti-héros sont à nouveau plongés dans une aventure passionnante. Un livre époustoufflant, plein d\'humour et d\'effroi. Vivement le tome 3. Anais, libraire à la Fnac Clermont Q',
$this->assertEquals('Une enquête sur un réseau de prostitution dévoile des secrets d\'espionnage et un lourd passé familial.',
$resume);
}
}
......@@ -101,7 +101,7 @@ class FnactNoLinkFoundTest extends FnacTestCase {
$this->_http_client
->whenCalled('open_url')
->with('http://www3.fnac.com/advanced/book.do?isbn=2070572676')
->with('http://recherche.fnac.com/r/2070572676')
->answers('bla bla bla')
->beStrict();
}
......
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