Fix sub views substitution

This commit is contained in:
Nicolas Le Goff
2013-03-21 16:06:06 +01:00
committed by Romain Neutron
parent 04dad80692
commit 93aa9be0fa
3 changed files with 124 additions and 61 deletions

View File

@@ -205,13 +205,13 @@ class Tools implements ControllerProviderInterface
, $request->get('record_id')
);
$media = $app['Core']['mediavorus']->guess($file);
$media = $app['Core']['mediavorus']->guess(new \SplFileInfo($tmpFile));
$record->substitute_subdef('thumbnail', $media);
$success = true;
} catch (\Exception $e) {
$errorMessage = $e->getMessage();
$errorMessage = _('An error occured');
}
} else {
$errorMessage = _('file is not valid');

View File

@@ -57,7 +57,7 @@
</a>
</li>
{% endif %}
{% if selectionLength == 1 and registry.get('GV_seeOngChgDoc') %}
{% if selectionLength == 1 and (registry.get('GV_seeOngChgDoc') or registry.get('GV_seeNewThumb')) %}
<li>
<a href="#substitution">
{% trans "substitution" %}
@@ -73,7 +73,7 @@
{% endif %}
</ul>
</div>
{# subef section #}
{# subdef section #}
<div id="subdefs" class="tabBox">
<form id="new-img-form" action="/prod/tools/image/" method="post">
<fieldset style='border:1px solid #999; padding:20px;'>
@@ -269,10 +269,13 @@
{% endif %}
{# hd sub section #}
{% if selectionLength == 1 %}
{% if selectionLength == 1 and (registry.get('GV_seeOngChgDoc') or registry.get('GV_seeNewThumb')) %}
{% for record in selection %}
<div id="substitution" class="tabBox">
{% if "unknown" == record.get_type() %}
<i class="icon-warning-sign icon-white"></i>{% trans "Substitution is not possible for this kind of record" %}
{% else %}
{% if registry.get('GV_seeOngChgDoc') %}
<div id="substitution-hd">
<form
@@ -333,6 +336,7 @@
<div class='resultAction'></div>
</div>
{% endif %}
{% endif %}
</div>
{% endfor %}
{% endif %}

View File

@@ -0,0 +1,59 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
use Symfony\Component\HttpFoundation\File\UploadedFile;
class ControllerToolsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
protected $client;
protected $tmpFile;
public function setUp()
{
parent::setUp();
$this->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 testRouteChangeThumb()
{
$record = static::$records['record_1'];
$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();
$content = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$this->assertFalse(strpos(_('An error occured'), $content));
$this->assertFalse(strpos(_('file is not valid'), $content));
}
}