diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Tools.php b/lib/Alchemy/Phrasea/Controller/Prod/Tools.php index 8ce0e327bf..d8a4430715 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Tools.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Tools.php @@ -200,7 +200,6 @@ class Tools implements ControllerProviderInterface $success = true; $message = _('Thumbnail has been successfully substitued'); } catch (\Exception $e) { - var_dump($e->getMessage()); $message = _('file is not valid'); } } else { diff --git a/templates/web/prod/actions/Tools/index.html.twig b/templates/web/prod/actions/Tools/index.html.twig index 320c3df3d3..cd5ad0eb41 100644 --- a/templates/web/prod/actions/Tools/index.html.twig +++ b/templates/web/prod/actions/Tools/index.html.twig @@ -131,7 +131,7 @@ {% set height = record.get_technical_infos(dataH) %} {% if width and height %} - {% set ratio = width / height %} + {% set ratio = (width / height)|number_format(2, '.') %} {% else %} {% set ratio = '' %} {% endif %} diff --git a/tests/Alchemy/Phrasea/Controller/Prod/ToolsTest.php b/tests/Alchemy/Phrasea/Controller/Prod/ToolsTest.php new file mode 100644 index 0000000000..5227d0fa2a --- /dev/null +++ b/tests/Alchemy/Phrasea/Controller/Prod/ToolsTest.php @@ -0,0 +1,75 @@ +client = $this->createClient(); + $this->tmpFile = sys_get_temp_dir() . '/' . time() . mt_rand(1000, 9999) . '.jpg'; + copy(__DIR__ . '/../../../../testfiles/cestlafete.jpg', $this->tmpFile); + } + + public function tearDown() + { + if (file_exists($this->tmpFile)) { + unlink($this->tmpFile); + } + parent::tearDown(); + } + + public function createApplication() + { + $app = require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php'; + + $app['debug'] = true; + unset($app['exception_handler']); + + return $app; + } + + public function testRouteChangeDoc() + { + $record = static::$records['record_1']; + + $crawler = $this->client->request('POST', '/tools/hddoc/', array( + 'sbas_id' => $record->get_sbas_id(), + 'record_id' => $record->get_record_id(), + ), array( + 'newHD' => new UploadedFile( + $this->tmpFile, 'KIKOO.JPG', 'image/jpg', 2000 + ) + )); + + $response = $this->client->getResponse(); + $message = trim($crawler->filterXPath('//div')->text()); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals(_('Document has been successfully substitued'), $message); + } + + public function testRouteChangeThumb() + { + $record = static::$records['record_1']; + + $crawler = $this->client->request('POST', '/tools/chgthumb/', array( + 'sbas_id' => $record->get_sbas_id(), + 'record_id' => $record->get_record_id(), + ), array( + 'newThumb' => new UploadedFile( + $this->tmpFile, 'KIKOO.JPG', 'image/jpg', 2000 + ) + )); + + $response = $this->client->getResponse(); + $message = trim($crawler->filterXPath('//div')->text()); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals(_('Thumbnail has been successfully substitued'), $message); + } +} diff --git a/www/prod/ThumbExtractor.js b/www/prod/ThumbExtractor.js index c4bbd77c3b..b235aa51cd 100644 --- a/www/prod/ThumbExtractor.js +++ b/www/prod/ThumbExtractor.js @@ -14,11 +14,13 @@ var maxH = elementDomNode.getHeight(); if ('' !== elementDomNode.getAspectRatio()) { - var h = Math.round(w * (1 / elementDomNode.getAspectRatio())); + var ratio = parseFloat(elementDomNode.getAspectRatio()); + + var h = Math.round(w * (1 / ratio)); if (h > maxH) { var h = maxH; - var w = Math.round(h * elementDomNode.getAspectRatio()); + var w = Math.round(h * ratio); } } else { var h = maxH;