Changing FormHelper::create() back to being model-oriented

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5879 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2007-10-23 02:36:07 +00:00
parent c86f10b3e4
commit 585d0fc645
2 changed files with 16 additions and 5 deletions

View file

@ -157,7 +157,7 @@ class FormHelper extends AppHelper {
if (empty($options['url']) || is_array($options['url'])) {
$options = (array)$options;
if (!isset($this->params['controller']) && !empty($model) && $model != $defaultModel) {
if (!empty($model) && $model != $defaultModel) {
$controller = Inflector::underscore(Inflector::pluralize($model));
} else {
$controller = Inflector::underscore($this->params['controller']);

View file

@ -482,7 +482,9 @@ class FormHelperTest extends CakeTestCase {
$this->assertEqual($result, '<label for="PersonFirstName">Your first name</label>');
$result = $this->Form->label('Person.first_name', 'Your first name', array('class' => 'my-class'));
$this->assertEqual($result, '<label for="PersonFirstName" class="my-class">Your first name</label>');
$this->assertPattern('/^<label[^<>]+>Your first name<\/label>$/', $result);
$this->assertPattern('/^<label[^<>]+for="PersonFirstName"[^<>]*>/', $result);
$this->assertPattern('/^<label[^<>]+class="my-class"[^<>]*>/', $result);
$result = $this->Form->label('Person.first_name', 'Your first name', array('class' => 'my-class', 'id' => 'LabelID'));
$this->assertEqual($result, '<label for="PersonFirstName" class="my-class" id="LabelID">Your first name</label>');
@ -876,9 +878,10 @@ class FormHelperTest extends CakeTestCase {
function testTextArea() {
$this->Form->data = array('Model' => array('field' => 'some test data'));
$result = $this->Form->textarea('Model.field');
$this->assertPattern('/^<textarea[^<>]+name="data\[Model\]\[field\]"[^<>]+id="ModelField"/', $result);
$this->assertPattern('/^<textarea[^<>]+name="data\[Model\]\[field\]"[^<>]*>/', $result);
$this->assertPattern('/^<textarea[^<>]+id="ModelField"[^<>]*>/', $result);
$this->assertPattern('/^<textarea[^<>]+>some test data<\/textarea>$/', $result);
$this->assertNoPattern('/^<textarea[^<>]+value="[^<>]+>/', $result);
$this->assertNoPattern('/^<textarea[^<>]+name="[^<>]+name="[^<>]+>$/', $result);
$this->assertNoPattern('/<textarea[^<>]+[^name|id]=[^<>]*>/', $result);
@ -887,7 +890,8 @@ class FormHelperTest extends CakeTestCase {
$this->Form->data = array('Model' => array('field' => 'some <strong>test</strong> data with <a href="#">HTML</a> chars'));
$result = $this->Form->textarea('Model.field');
$this->assertPattern('/^<textarea[^<>]+name="data\[Model\]\[field\]"[^<>]+id="ModelField"/', $result);
$this->assertPattern('/^<textarea[^<>]+name="data\[Model\]\[field\]"[^<>]*>/', $result);
$this->assertPattern('/^<textarea[^<>]+id="ModelField"[^<>]*>/', $result);
$this->assertPattern('/^<textarea[^<>]+>some &lt;strong&gt;test&lt;\/strong&gt; data with &lt;a href=&quot;#&quot;&gt;HTML&lt;\/a&gt; chars<\/textarea>$/', $result);
$this->assertNoPattern('/^<textarea[^<>]+value="[^<>]+>/', $result);
$this->assertNoPattern('/^<textarea[^<>]+name="[^<>]+name="[^<>]+>$/', $result);
@ -970,6 +974,13 @@ class FormHelperTest extends CakeTestCase {
$this->assertPattern('/method="post"/', $result);
$this->assertPattern('/action="\/users\/login(\/)?"/', $result);
$this->assertNoPattern('/^<form[^<>]+[^method|action]=[^<>]*>/', $result);
$this->Form->params['controller'] = 'pages';
$this->Form->params['models'] = array('User', 'Post');
$result = $this->Form->create('User', array('action' => 'signup'));
$this->assertPattern('/id="UserSignupForm"/', $result);
$this->assertPattern('/action="\/users\/signup[\/]"/', $result);
}
function testGetFormCreate() {