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

Merge branch 'hotline#24383-text-replacements-can-contain-tags' into 'stable'

Hotline#24383 text replacements can contain tags

See merge request !906
parents 95e19dad aade2713
Branches
Tags
3 merge requests!915Master,!914Hotline master,!913Stable
- ticket #24383 : Les balises deviennent autorisées dans la variable TEXT_REPLACEMENTS
\ No newline at end of file
......@@ -60,44 +60,49 @@ class Admin_IndexController extends ZendAfi_Controller_Action {
public function shouldEncodeVar($cle) {
return in_array($cle->getId(),
public function shouldEncodeVar($id) {
return in_array($id,
['REGISTER_OK', 'RESA_CONDITION', 'TEXTE_MAIL_RESA',
'USER_VALIDATED', 'USER_NON_VALIDATED']);
}
protected function shouldAddSlashes($id) {
return in_array($id, ['JS_STAT', 'TEXT_REPLACEMENTS']);
}
public function adminvareditAction() {
$id = $this->_getParam('cle');
$cle = Class_AdminVar::getLoader()->find($id);
$var = Class_AdminVar::find($id);
if ($this->_request->isPost()) {
$filter = new Zend_Filter_StripTags();
$new_valeur = $this->_request->getPost('valeur');
if ($this->shouldEncodeVar($cle)) {
$cle->setValeur(urlencode($new_valeur));
if ($this->shouldEncodeVar($var->getId())) {
$var->setValeur(urlencode($new_valeur));
} else if ($cle->getId() == 'JS_STAT') {
$cle->setValeur(addslashes($new_valeur));
} else if ($this->shouldAddSlashes($var->getId())) {
$var->setValeur(addslashes($new_valeur));
} else {
$cle->setValeur(trim($filter->filter($new_valeur)));
$var->setValeur(trim($filter->filter($new_valeur)));
}
$cle->save();
$var->save();
$this->_helper->notify('Variable '.$id.' sauvegardée');
$this->_redirect('admin/index/adminvaredit/cle/'.$id);
return;
}
$this->view->var_valeur = $this->shouldEncodeVar($cle)
? urldecode($cle->getValeur())
: $cle->getValeur();
$this->view->var_valeur = $this->shouldEncodeVar($var->getId())
? urldecode($var->getValeur())
: $var->getValeur();
$this->view->var_cle = $cle->getId();
$this->view->tuto = Class_AdminVar::helpFor($cle->getId());
$this->view->titre = 'Modifier la variable: ' . $cle->getId();
$this->view->var_cle = $var->getId();
$this->view->tuto = Class_AdminVar::helpFor($var->getId());
$this->view->titre = 'Modifier la variable: ' . $var->getId();
}
......
......@@ -39,13 +39,11 @@ class AdminIndexControllerIndexActionTest extends AdminIndexControllerTestCase {
public function setUp() {
parent::setUp();
Class_AdminVar::getLoader()
->newInstanceWithId('LANGUES')
->setValeur('');
$this->fixture('Class_AdminVar', ['id' => 'LANGUES', 'valeur' => '']);
$this->dispatch('/admin/index', true);
}
/** @test */
function menuGaucheTraductionsShouldBeHidden() {
$this->assertNotXPathContentContains('//a', 'Traductions');
......@@ -150,12 +148,9 @@ class AdminIndexControllerAdminVarEditModoBlogActionTest extends Admin_AbstractC
public function setUp() {
parent::setUp();
$this->modo_blog = Storm_Test_ObjectWrapper::onLoaderOfModel('Class_AdminVar')
->whenCalled('save')
->answers('true')
->getWrapper()
->newInstanceWithId('MODO_BLOG')
->setValeur('1');
$this->modo_blog = $this->fixture('Class_AdminVar',
['id' => 'MODO_BLOG',
'valeur' => '1']);
}
......@@ -168,12 +163,10 @@ class AdminIndexControllerAdminVarEditModoBlogActionTest extends Admin_AbstractC
/** @test */
public function postTwoToMODO_BLOG() {
$this
->getRequest()
->setMethod('POST')
->setPost(array('cle' => 'MODO_BLOG',
'valeur' => "<b>2 \n</b>"));
$this->dispatch('/admin/index/adminvaredit/cle/MODO_BLOG');
$this->postDispatch('/admin/index/adminvaredit/cle/MODO_BLOG',
['cle' => 'MODO_BLOG',
'valeur' => "<b>2 \n</b>"]);
$this->assertEquals(2, $this->modo_blog->getValeur());
$this->assertRedirectTo('/admin/index/adminvaredit/cle/MODO_BLOG');
$this->assertFlashMessengerContains('Variable MODO_BLOG sauvegardée');
......@@ -189,29 +182,43 @@ class AdminIndexControllerAdminVarEditResaConditionActionTest extends Admin_Abst
public function setUp() {
parent::setUp();
$this->_resa_condition = Class_AdminVar::getLoader()
->newInstanceWithId('RESA_CONDITION')
->setValeur('Mes+conditions+de+reservation');
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_AdminVar')
->whenCalled('save')
->answers(true);
$this->_resa_condition = $this->fixture('Class_AdminVar',
['id' => 'RESA_CONDITION',
'valeur' => 'Mes+conditions+de+reservation']);
}
/** @test */
public function editResaConditionShouldDecodeItsValeur() {
$this->dispatch('/admin/index/adminvaredit/cle/RESA_CONDITION');
$this->assertXPathContentContains('//textarea', 'Mes conditions de reservation');
$this->assertXPathContentContains('//textarea', 'Mes conditions de reservation',
$this->_response->getBody());
}
/** @test */
public function postResaConditionShouldEncodeItsValeur() {
$this->postDispatch('/admin/index/adminvaredit/cle/RESA_CONDITION',
array('valeur' => 'Il faut demander'));
['valeur' => 'Il faut demander']);
$this->assertEquals('Il+faut+demander', $this->_resa_condition->getValeur());
}
}
?>
\ No newline at end of file
/** @see http://forge.afi-sa.fr/issues/24383 */
class AdminIndexControllerAdminVarEditTextReplacementsActionTest extends Admin_AbstractControllerTestCase {
/** @test */
public function postShouldNotStripTags() {
$this->fixture('Class_AdminVar',
['id' => 'TEXT_REPLACEMENTS', 'valeur' => '']);
$value = 'Votre réservation est enregistrée.<br>Nous vous informerons quand le document%s sera disponible pour être retiré à : %s';
$this->postDispatch('/admin/index/adminvaredit/cle/TEXT_REPLACEMENTS',
['valeur' => $value]);
$this->assertEquals($value, Class_AdminVar::get('TEXT_REPLACEMENTS'));
}
}
\ No newline at end of file
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