Skip to content
Snippets Groups Projects
Commit ff03d6d0 authored by Alex Arnaud's avatar Alex Arnaud
Browse files

hotline #16456 - Fix tests for web sites thumbnails

parent 79adb5a4
Branches
Tags
4 merge requests!529Hotline 6.56,!428Master,!427Hotline 6.53,!423Hotline#16456 change the way retrieving site images
......@@ -33,7 +33,7 @@ class ZendAfi_View_Helper_WebThumbnail extends ZendAfi_View_Helper_BaseHelper {
$filename = $this->fileNameFromUrl($url);
$filepath = $this->fullPath($filename);
if (!file_exists($filepath))
if (!$this->getFileWriter()->fileExists($filepath))
return BASE_URL."/sito/webthumbnail?url=$url";
return $this->fullUrl($filename);
......
......@@ -136,4 +136,18 @@ class SitoControllerSitoViewIdTest extends SitoControllerTestCase {
}
}
class SitoControllerSitoWebThumbnailUrl extends SitoControllerTestCase {
public function setup() {
parent::setUp();
$this->dispatch('/sito/webthumbnail?url=http://linuxfr.org');
}
/** @test */ public function siteLinuxThumbnailUrlShouldBelinuxfrOrgDotJpg() {
$this->assertRedirectTo(BASE_URL.'/userfiles/web_thumbnails/linuxfr_org.jpg');
}
}
?>
......@@ -109,23 +109,23 @@ class ZendAfi_View_Helper_Notice_MurForSiteTest extends ZendAfi_View_Helper_Noti
]);
$notice->beSite();
$bluga = Storm_Test_ObjectWrapper::mock();
$bluga->whenCalled('fetchUrlToFile')
->with('http://www.abes.fr/',
'..'.BASE_URL.'/userfiles/web_thumbnails/www_abes_fr_.jpg')
->answers(true)
->beStrict();
$file_writer = Storm_Test_ObjectWrapper::mock()
->whenCalled('dirExists')
->answers(true)
->whenCalled('fileExists')
->answers(true);
ZendAfi_View_Helper_WebThumbnail::setThumbnailer($bluga);
ZendAfi_View_Helper_WebThumbnail::setFileWriter($file_writer);
$this->_html = $this->_helper->notice_Mur($notice);
}
public function tearDown() {
ZendAfi_View_Helper_WebThumbnail::setFileWriter(null);
parent::tearDown();
}
/** @test */
public function divShouldNotContainsWebserviceVignette() {
......
......@@ -33,6 +33,7 @@ abstract class ViewHelperWebThumbnailTestCase extends ViewHelperTestCase {
public function tearDown() {
$this->helper->setThumbnailer(null);
$this->helper->setFileWriter(null);
parent::tearDown();
}
}
......@@ -44,7 +45,13 @@ class ViewHelperWebThumbnailTestReturnedUrl extends ViewHelperWebThumbnailTestCa
parent::setUp();
$this->thumbnailer = $this->mock();
$this->helper->setThumbnailer($this->thumbnailer);
$this->google_thumbnail_path = USERFILESPATH.'/web_thumbnails/www_google_com.jpg';
$this->_file_writer = Storm_Test_ObjectWrapper::mock()
->whenCalled('fileExists')->answers(false)
->whenCalled('dirExists')->answers(true);
$this->helper->setFileWriter($this->_file_writer);
$this->google_thumbnail_path = USERFILESPATH.'/web_thumbnails/www_google_com.jpg';
}
......@@ -63,14 +70,17 @@ class ViewHelperWebThumbnailTestReturnedUrl extends ViewHelperWebThumbnailTestCa
->answers(true);
$url = $this->helper->webThumbnail('http://www.google.com');
$this->assertEquals(BASE_URL . '/userfiles/web_thumbnails/www_google_com.jpg',
$this->assertEquals(BASE_URL . '/sito/webthumbnail?url=http://www.google.com',
$url);
}
/** @test */
public function googleDotComThumbnailUrlWithExistingFile() {
touch($this->google_thumbnail_path);
$this->_file_writer
->whenCalled('fileExists')
->with($this->google_thumbnail_path)
->answers(true);
$this->assertFalse($this->thumbnailer->methodHasBeenCalled('fetchUrlToFile'));
......@@ -82,6 +92,11 @@ class ViewHelperWebThumbnailTestReturnedUrl extends ViewHelperWebThumbnailTestCa
/** @test */
public function subpageUrlWithParams() {
$this->_file_writer
->whenCalled('fileExists')
->with(USERFILESPATH.'/web_thumbnails/www_google_fr_search_sourceid_chrome_ie_UTF-8_q_harry_potter.jpg')
->answers(true);
$this->thumbnailer
->whenCalled('fetchUrlToFile')
->with('http://www.google.fr/search?sourceid=chrome&ie=UTF-8&q=harry+potter',
......@@ -96,6 +111,11 @@ class ViewHelperWebThumbnailTestReturnedUrl extends ViewHelperWebThumbnailTestCa
/** @test */
public function subpageUrlWithSpacesAndHTMLEntites() {
$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',
......@@ -110,6 +130,11 @@ class ViewHelperWebThumbnailTestReturnedUrl extends ViewHelperWebThumbnailTestCa
/** @test */
public function thumbnailerCannotFetchImageReturnsEmptyUrl() {
$this->_file_writer
->whenCalled('fileExists')
->with($this->google_thumbnail_path)
->answers(false);
$this->thumbnailer
->whenCalled('fetchUrlToFile')
->with('http://www.google.com',
......@@ -117,11 +142,13 @@ class ViewHelperWebThumbnailTestReturnedUrl extends ViewHelperWebThumbnailTestCa
->answers(false);
$url = $this->helper->webThumbnail('http://www.google.com');
$this->assertEquals('', $url);
$this->assertEquals(BASE_URL.'/sito/webthumbnail?url=http://www.google.com', $url);
}
}
class ViewHelperWebThumbnailTestThumbnailer extends ViewHelperWebThumbnailTestCase {
/** @test */
public function thumbnailerDefaultsToBluga() {
......
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