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

Merge branch...

Merge branch 'hotline_#17191_fix_sito_html_img_if_bluga_disabled_and_no_local_img' into 'hotline_6.54'

Hotline #17191 fix sito html img if bluga disabled and no local img

See merge request !474
parents a5d66148 deae708d
Branches
Tags
4 merge requests!529Hotline 6.56,!512Master,!484Master,!483Hotline 6.54
- ticket #17191 : supprime la balise image dans la boite sitothèque si bluga n'est pas activé ou si la vignette du site n'est pas sur le serveur
\ No newline at end of file
......@@ -428,6 +428,11 @@
}
public static function isBlugaEnabled() {
return '' != self::get('BLUGA_API_KEY');
}
public static function isAfficherDispoSurRechercheEnabled() {
return self::isModuleEnabled('AFFICHER_DISPONIBILITE_SUR_RECHERCHE');
}
......
......@@ -16,7 +16,7 @@
*
* 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
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
//////////////////////////////////////////////////////////////////////////////////////////
// OPAC3 : Créer un thumbnail d'un site web et renvoi l'adresse de l'image
......@@ -32,18 +32,25 @@ class ZendAfi_View_Helper_WebThumbnail extends ZendAfi_View_Helper_BaseHelper {
$filename = $this->fileNameFromUrl($url);
$filepath = $this->fullPath($filename);
if (!$this->getFileWriter()->fileExists($filepath))
return BASE_URL."/sito/webthumbnail?url=$url";
if (!$this->getFileWriter()->fileExists($filepath)) {
return Class_AdminVar::isBlugaEnabled()
? $this->view->absoluteUrl(['controller' => 'sito',
'action' => 'webthumbnail',
'url' =>$url], null, true)
: '';
}
return $this->fullUrl($filename);
}
public function getThumbsDir() {
$path = USERFILESPATH.'/'.self::THUMBS_DIR.'/';
return str_replace('//', '/', $path);
}
public function checkThumbsDir() {
$dir = $this->getThumbsDir();
$file_writer = $this->getFileWriter();
......
......@@ -16,7 +16,7 @@
*
* 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
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
require_once 'ViewHelperTestCase.php';
require_once 'ZendAfi/View/Helper/WebThumbnail.php';
......@@ -28,6 +28,7 @@ abstract class ViewHelperWebThumbnailTestCase extends ViewHelperTestCase {
public function setUp() {
parent::setUp();
$this->helper = new ZendAfi_View_Helper_WebThumbnail();
$this->helper->setView(new ZendAfi_Controller_Action_Helper_View());
}
......@@ -45,7 +46,7 @@ class ViewHelperWebThumbnailTestReturnedUrl extends ViewHelperWebThumbnailTestCa
parent::setUp();
$this->thumbnailer = $this->mock();
$this->helper->setThumbnailer($this->thumbnailer);
$this->_file_writer = Storm_Test_ObjectWrapper::mock()
->whenCalled('fileExists')->answers(false)
->whenCalled('dirExists')->answers(true);
......@@ -64,13 +65,14 @@ $this->google_thumbnail_path = USERFILESPATH.'/web_thumbnails/www_google_com.jpg
/** @test */
public function googleDotComThumbnailUrl() {
Class_AdminVar::newInstanceWithId('BLUGA_API_KEY', ['valeur' => '12345']);
$this->thumbnailer
->whenCalled('fetchUrlToFile')
->with('http://www.google.com', $this->google_thumbnail_path)
->answers(true);
$url = $this->helper->webThumbnail('http://www.google.com');
$this->assertEquals(BASE_URL . '/sito/webthumbnail?url=http://www.google.com',
$this->assertContains('/sito/webthumbnail/url/'.urlencode('http://www.google.com'),
$url);
}
......@@ -78,6 +80,8 @@ $this->google_thumbnail_path = USERFILESPATH.'/web_thumbnails/www_google_com.jpg
/** @test */
public function googleDotComThumbnailUrlWithExistingFile() {
$this->_file_writer
->whenCalled('dirExists')
->answers(true)
->whenCalled('fileExists')
->with($this->google_thumbnail_path)
->answers(true);
......@@ -99,7 +103,7 @@ $this->google_thumbnail_path = USERFILESPATH.'/web_thumbnails/www_google_com.jpg
$this->thumbnailer
->whenCalled('fetchUrlToFile')
->with('http://www.google.fr/search?sourceid=chrome&ie=UTF-8&q=harry+potter',
->with('http://www.google.fr/search?sourceid=chrome&ie=UTF-8&q=harry+potter',
USERFILESPATH.'/web_thumbnails/www_google_fr_search_sourceid_chrome_ie_UTF-8_q_harry_potter.jpg')
->answers(true);
......@@ -111,14 +115,14 @@ $this->google_thumbnail_path = USERFILESPATH.'/web_thumbnails/www_google_com.jpg
/** @test */
public function subpageUrlWithSpacesAndHTMLEntites() {
$this->_file_writer
$this->_file_writer
->whenCalled('fileExists')
->with(USERFILESPATH.'/web_thumbnails/astrolabe_fr_my_search.jpg')
->answers(true);
$this->thumbnailer
->whenCalled('fetchUrlToFile')
->with('https://astrolabe.fr/my%20search',
->with('https://astrolabe.fr/my%20search',
USERFILESPATH.'/web_thumbnails/astrolabe_fr_my_search.jpg')
->answers(true);
......@@ -129,7 +133,9 @@ $this->google_thumbnail_path = USERFILESPATH.'/web_thumbnails/www_google_com.jpg
/** @test */
public function thumbnailerCannotFetchImageReturnsEmptyUrl() {
public function thumbnailerCannotFetchImageAndBlugaDisabledReturnsEmptyUrl() {
Class_AdminVar::newInstanceWithId('BLUGA_API_KEY', ['valeur' => '']);
$this->_file_writer
->whenCalled('fileExists')
->with($this->google_thumbnail_path)
......@@ -137,13 +143,33 @@ $this->google_thumbnail_path = USERFILESPATH.'/web_thumbnails/www_google_com.jpg
$this->thumbnailer
->whenCalled('fetchUrlToFile')
->with('http://www.google.com',
->with('http://www.google.com',
$this->google_thumbnail_path)
->answers(false);
$url = $this->helper->webThumbnail('http://www.google.com');
$this->assertEquals(BASE_URL.'/sito/webthumbnail?url=http://www.google.com', $url);
$this->assertEquals('', $url);
}
/** @test */
public function thumbnailerCannotFetchImageAndBlugaEnabledReturnsWebthumbnailUrl() {
Class_AdminVar::newInstanceWithId('BLUGA_API_KEY', ['valeur' => '12345']);
$this->_file_writer
->whenCalled('fileExists')
->with($this->google_thumbnail_path)
->answers(false);
$this->thumbnailer
->whenCalled('fetchUrlToFile')
->with('http://www.google.com',
$this->google_thumbnail_path)
->answers(false);
$url = $this->helper->webThumbnail('http://www.google.com');
$this->assertContains(BASE_URL.'/sito/webthumbnail/url/'.urlencode('http://www.google.com'), $url);
}
}
......@@ -177,7 +203,7 @@ class WebThumbnailerTestFetchFile extends ViewHelperTestCase {
/** @test */
public function fetchGoogleWithoutProxy() {
Zend_Registry::set('cfg',
Zend_Registry::set('cfg',
new Zend_Config(['proxy' => ['host' => null, 'port' => null]]));
$this->_fetchGoogle();
......@@ -189,15 +215,15 @@ class WebThumbnailerTestFetchFile extends ViewHelperTestCase {
/** @test */
public function fetchGoogleThroughProxy() {
Zend_Registry::set('cfg',
new Zend_Config(['proxy' =>
Zend_Registry::set('cfg',
new Zend_Config(['proxy' =>
['host' => '192.168.2.1',
'port' => '8180',
'user' => 'afi',
'pass' => 'pafgjl']]));
$this->_fetchGoogle();
$this->assertEquals(new Bluga_HTTP_Request_Uri('tcp://192.168.2.1:8180'),
$this->assertEquals(new Bluga_HTTP_Request_Uri('tcp://192.168.2.1:8180'),
$this->bluga->httpRequestAdapter->proxy);
$this->assertEquals(" Basic ".base64_encode('afi:pafgjl'),
$this->bluga->httpRequestAdapter->headers['Proxy-Authorization']);
......@@ -206,15 +232,15 @@ class WebThumbnailerTestFetchFile extends ViewHelperTestCase {
/** @test */
public function fetchGoogleThroughProxyWithoutAuth() {
Zend_Registry::set('cfg',
new Zend_Config(['proxy' =>
Zend_Registry::set('cfg',
new Zend_Config(['proxy' =>
['host' => '192.168.2.3',
'port' => '3128',
'user' => null,
'pass' => null]]));
$this->_fetchGoogle();
$this->assertEquals(new Bluga_HTTP_Request_Uri('tcp://192.168.2.3:3128'),
$this->assertEquals(new Bluga_HTTP_Request_Uri('tcp://192.168.2.3:3128'),
$this->bluga->httpRequestAdapter->proxy);
$this->assertFalse(array_key_exists('Proxy-Authorization',
$this->bluga->httpRequestAdapter->headers));
......@@ -239,13 +265,13 @@ class WebThumbnailerTestFetchFile extends ViewHelperTestCase {
->whenCalled('checkJobStatus')->answers(null)
->whenCalled('fetchToFile')->with($job, 'thumbnails/google_com.jpg')->answers(null);
$this->assertTrue($this->thumbnailer->fetchUrlToFile('http://google.com',
$this->assertTrue($this->thumbnailer->fetchUrlToFile('http://google.com',
'thumbnails/google_com.jpg'));
}
public function testFetchGoogleWithoutKeyReturnsFalse() {
$this->assertFalse($this->thumbnailer->fetchUrlToFile('http://google.com',
$this->assertFalse($this->thumbnailer->fetchUrlToFile('http://google.com',
'thumbnails/google_com.jpg'));
}
}
......
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