Browse Source

Merge pull request #2858 from ADmad/3.0-formhelper-end

3.0 formhelper end
Mark Story 12 years ago
parent
commit
7958bc71c7
2 changed files with 13 additions and 118 deletions
  1. 12 39
      src/View/Helper/FormHelper.php
  2. 1 79
      tests/TestCase/View/Helper/FormHelperTest.php

+ 12 - 39
src/View/Helper/FormHelper.php

@@ -448,48 +448,21 @@ class FormHelper extends Helper {
  * Closes an HTML form, cleans up values set by FormHelper::create(), and writes hidden
  * input fields where appropriate.
  *
- * If $options is set a form submit button will be created. Options can be either a string or an array.
- *
- * {{{
- * array usage:
- *
- * array('label' => 'save'); value="save"
- * array('label' => 'save', 'name' => 'Whatever'); value="save" name="Whatever"
- * array('name' => 'Whatever'); value="Submit" name="Whatever"
- * array('label' => 'save', 'name' => 'Whatever', 'div' => 'good') <div class="good"> value="save" name="Whatever"
- * array('label' => 'save', 'name' => 'Whatever', 'div' => array('class' => 'good')); <div class="good"> value="save" name="Whatever"
- * }}}
- *
- * @param string|array $options as a string will use $options as the value of button,
- * @return string a closing FORM tag optional submit button.
+ * @return string A closing FORM tag.
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#closing-the-form
  */
-	public function end($options = null) {
-		$out = null;
-		$submit = null;
+	public function end() {
+		$out = '';
 
-		if ($options !== null) {
-			$submitOptions = array();
-			if (is_string($options)) {
-				$submit = $options;
-			} else {
-				if (isset($options['label'])) {
-					$submit = $options['label'];
-					unset($options['label']);
-				}
-				$submitOptions = $options;
-			}
-			$out .= $this->submit($submit, $submitOptions);
-		}
 		if (
 			$this->requestType !== 'get' &&
-			isset($this->request['_Token']) &&
 			!empty($this->request['_Token'])
 		) {
 			$out .= $this->secure($this->fields);
 			$this->fields = array();
 		}
-		$out .= $this->Html->useTag('formend');
+
+		$out .= $this->formatTemplate('formend', []);
 
 		$this->requestType = null;
 		$this->_context = null;
@@ -532,7 +505,7 @@ class FormHelper extends Helper {
 		$out .= $this->hidden('_Token.unlocked', array(
 			'value' => urlencode($unlocked),
 		));
-		return $this->Html->useTag('hiddenblock', $out);
+		return $this->formatTemplate('hiddenblock', ['content' => $out]);
 	}
 
 /**
@@ -1649,8 +1622,8 @@ class FormHelper extends Helper {
 		}
 
 		$formName = str_replace('.', '', uniqid('post_', true));
-		$formUrl = $this->url($url);
 		$formOptions = array(
+			'action' => $this->url($url),
 			'name' => $formName,
 			'id' => $formName,
 			'style' => 'display:none;',
@@ -1661,10 +1634,10 @@ class FormHelper extends Helper {
 			unset($options['target']);
 		}
 
-		$out = $this->Html->useTag('form', $formUrl, $formOptions);
-		$out .= $this->Html->useTag('hidden', '_method', array(
-			'value' => $requestMethod
-		));
+		$out = $this->formatTemplate('formstart', [
+			'attrs' => $this->_templater->formatAttributes($formOptions)
+		]);
+		$out .= $this->hidden('_method', ['value' => $requestMethod]);
 		$out .= $this->_csrfField();
 
 		$fields = array();
@@ -1676,7 +1649,7 @@ class FormHelper extends Helper {
 			unset($options['data']);
 		}
 		$out .= $this->secure($fields);
-		$out .= $this->Html->useTag('formend');
+		$out .= $this->formatTemplate('formend', []);
 
 		if ($options['block']) {
 			$this->_View->append($options['block'], $out);

+ 1 - 79
tests/TestCase/View/Helper/FormHelperTest.php

@@ -1472,7 +1472,6 @@ class FormHelperTest extends TestCase {
  * @return void
  */
 	public function testSecurityButtonNestedNamed() {
-		$this->markTestIncomplete('Need to revisit once models work again.');
 		$key = 'testKey';
 		$this->Form->request->params['_csrfToken'] = $key;
 
@@ -1925,13 +1924,11 @@ class FormHelperTest extends TestCase {
  * @return void
  */
 	public function testFormSecuredRadio() {
-		$this->markTestIncomplete('Need to revisit once models work again.');
-		$this->Form->request->params['_csrfToken'] = 'testKey';
 		$this->assertEquals(array(), $this->Form->fields);
 		$options = array('1' => 'option1', '2' => 'option2');
 
 		$this->Form->radio('Test.test', $options);
-		$expected = array('Test.test');
+		$expected = array('Test[test]' => '');
 		$this->assertEquals($expected, $this->Form->fields);
 	}
 
@@ -8030,82 +8027,7 @@ class FormHelperTest extends TestCase {
  * @return void
  */
 	public function testFormEnd() {
-		$this->markTestIncomplete('Need to revisit once models work again.');
 		$this->assertEquals('</form>', $this->Form->end());
-
-		$result = $this->Form->end('');
-		$expected = array(
-			'div' => array('class' => 'submit'),
-			'input' => array('type' => 'submit', 'value' => ''),
-			'/div',
-			'/form'
-		);
-		$this->assertTags($result, $expected);
-
-		$result = $this->Form->end(array('label' => ''));
-		$expected = array(
-			'div' => array('class' => 'submit'),
-			'input' => array('type' => 'submit', 'value' => ''),
-			'/div',
-			'/form'
-		);
-		$this->assertTags($result, $expected);
-
-		$result = $this->Form->end('save');
-		$expected = array(
-			'div' => array('class' => 'submit'),
-			'input' => array('type' => 'submit', 'value' => 'save'),
-			'/div',
-			'/form'
-		);
-		$this->assertTags($result, $expected);
-
-		$result = $this->Form->end(array('label' => 'save'));
-		$expected = array(
-			'div' => array('class' => 'submit'),
-			'input' => array('type' => 'submit', 'value' => 'save'),
-			'/div',
-			'/form'
-		);
-		$this->assertTags($result, $expected);
-
-		$result = $this->Form->end(array('label' => 'save', 'name' => 'Whatever'));
-		$expected = array(
-			'div' => array('class' => 'submit'),
-			'input' => array('type' => 'submit', 'value' => 'save', 'name' => 'Whatever'),
-			'/div',
-			'/form'
-		);
-		$this->assertTags($result, $expected);
-
-		$result = $this->Form->end(array('name' => 'Whatever'));
-		$expected = array(
-			'div' => array('class' => 'submit'),
-			'input' => array('type' => 'submit', 'value' => 'Submit', 'name' => 'Whatever'),
-			'/div',
-			'/form'
-		);
-		$this->assertTags($result, $expected);
-
-		$result = $this->Form->end(array('label' => 'save', 'name' => 'Whatever', 'div' => 'good'));
-		$expected = array(
-			'div' => array('class' => 'good'),
-			'input' => array('type' => 'submit', 'value' => 'save', 'name' => 'Whatever'),
-			'/div',
-			'/form'
-		);
-		$this->assertTags($result, $expected);
-
-		$result = $this->Form->end(array(
-			'label' => 'save', 'name' => 'Whatever', 'div' => array('class' => 'good')
-		));
-		$expected = array(
-			'div' => array('class' => 'good'),
-			'input' => array('type' => 'submit', 'value' => 'save', 'name' => 'Whatever'),
-			'/div',
-			'/form'
-		);
-		$this->assertTags($result, $expected);
 	}
 
 /**