Skip to content
This repository
Browse code

Hidden divs created by FormHelper can now be customized.

  • Loading branch information...
commit 28951865c66e84efdb20065a13ecadf51cf0c0f1 1 parent 771cfde
ADmad authored September 03, 2012
24  lib/Cake/Test/Case/View/Helper/FormHelperTest.php
@@ -792,14 +792,32 @@ public function testFormSecurityFields() {
792 792
 		$this->Form->request['_Token'] = array('key' => $key);
793 793
 		$result = $this->Form->secure($fields);
794 794
 
795  
-		$expected = Security::hash(serialize($fields) . Configure::read('Security.salt'));
796  
-		$expected .= ':' . 'Model.valid';
  795
+		$hash = Security::hash(serialize($fields) . Configure::read('Security.salt'));
  796
+		$hash .= ':' . 'Model.valid';
  797
+		$hash = urlencode($hash);
797 798
 
798 799
 		$expected = array(
799 800
 			'div' => array('style' => 'display:none;'),
800 801
 			array('input' => array(
801 802
 				'type' => 'hidden', 'name' => 'data[_Token][fields]',
802  
-				'value' => urlencode($expected), 'id' => 'preg:/TokenFields\d+/'
  803
+				'value' => $hash, 'id' => 'preg:/TokenFields\d+/'
  804
+			)),
  805
+			array('input' => array(
  806
+				'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
  807
+				'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
  808
+			)),
  809
+			'/div'
  810
+		);
  811
+		$this->assertTags($result, $expected);
  812
+
  813
+		$path = CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS;
  814
+		$this->Form->Html->loadConfig('htmlhelper_tags', $path);
  815
+		$result = $this->Form->secure($fields);
  816
+		$expected = array(
  817
+			'div' => array('class' => 'hidden'),
  818
+			array('input' => array(
  819
+				'type' => 'hidden', 'name' => 'data[_Token][fields]',
  820
+				'value' => $hash, 'id' => 'preg:/TokenFields\d+/'
803 821
 			)),
804 822
 			array('input' => array(
805 823
 				'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
3  lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
@@ -1863,7 +1863,8 @@ public function testLoadConfig() {
1863 1863
 		$expected = array(
1864 1864
 			'tags' => array(
1865 1865
 				'form' => 'start form',
1866  
-				'formend' => 'finish form'
  1866
+				'formend' => 'finish form',
  1867
+				'hiddenblock' => '<div class="hidden">%s</div>'
1867 1868
 			)
1868 1869
 		);
1869 1870
 		$this->assertEquals($expected, $result);
3  lib/Cake/Test/test_app/Config/htmlhelper_tags.php
@@ -3,6 +3,7 @@
3 3
 $config = array(
4 4
 	'tags' => array(
5 5
 		'form' => 'start form',
6  
-		'formend' => 'finish form'
  6
+		'formend' => 'finish form',
  7
+		'hiddenblock' => '<div class="hidden">%s</div>'
7 8
 	)
8 9
 );
4  lib/Cake/View/Helper/FormHelper.php
@@ -428,7 +428,7 @@ public function create($model = null, $options = array()) {
428 428
 		$append .= $this->_csrfField();
429 429
 
430 430
 		if (!empty($append)) {
431  
-			$append = $this->Html->useTag('block', ' style="display:none;"', $append);
  431
+			$append = $this->Html->useTag('hiddenblock', $append);
432 432
 		}
433 433
 
434 434
 		if ($model !== false) {
@@ -545,7 +545,7 @@ public function secure($fields = array()) {
545 545
 			'value' => urlencode($unlocked),
546 546
 			'id' => 'TokenUnlocked' . mt_rand()
547 547
 		));
548  
-		return $this->Html->useTag('block', ' style="display:none;"', $out);
  548
+		return $this->Html->useTag('hiddenblock', $out);
549 549
 	}
550 550
 
551 551
 /**
1  lib/Cake/View/Helper/HtmlHelper.php
@@ -78,6 +78,7 @@ class HtmlHelper extends AppHelper {
78 78
 		'block' => '<div%s>%s</div>',
79 79
 		'blockstart' => '<div%s>',
80 80
 		'blockend' => '</div>',
  81
+		'hiddenblock' => '<div style="display:none;">%s</div>',
81 82
 		'tag' => '<%s%s>%s</%s>',
82 83
 		'tagstart' => '<%s%s>',
83 84
 		'tagend' => '</%s>',

0 notes on commit 2895186

Please sign in to comment.
Something went wrong with that request. Please try again.