updating Helper::setEntity() and form.test

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6464 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2008-02-18 21:58:32 +00:00
parent 18dc1fd456
commit fb4244bb89
2 changed files with 32 additions and 7 deletions

View file

@ -355,10 +355,11 @@ class Helper extends Overloadable {
} }
} }
if ($parts[0] == $view->field && $view->field != $view->model) { if (!$view->association && $parts[0] == $view->field && $view->field != $view->model) {
array_unshift($parts, $model); array_unshift($parts, $model);
$hasField = true; $hasField = true;
} }
$view->field = $view->modelId = $view->fieldSuffix = $view->association = null; $view->field = $view->modelId = $view->fieldSuffix = $view->association = null;
switch (count($parts)) { switch (count($parts)) {

View file

@ -59,8 +59,22 @@ class Contact extends CakeTestModel {
); );
return $this->_schema; return $this->_schema;
} }
}
var $hasAndBelongsToMany = array('ContactTag' => array());
}
class ContactTag extends Model {
var $useTable = false;
function schema() {
$this->_schema = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'),
'name' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'),
'created' => array('type' => 'date', 'null' => true, 'default' => '', 'length' => ''),
'modified' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null)
);
return $this->_schema;
}
}
class UserForm extends CakeTestModel { class UserForm extends CakeTestModel {
var $useTable = false; var $useTable = false;
var $primaryKey = 'id'; var $primaryKey = 'id';
@ -482,31 +496,37 @@ class FormHelperTest extends CakeTestCase {
$this->assertPattern('/<legend>The Legend<\/legend>/', $result); $this->assertPattern('/<legend>The Legend<\/legend>/', $result);
$View = ClassRegistry::getObject('view'); $View = ClassRegistry::getObject('view');
$this->Form->create('Contact');
$this->Form->params['prefix'] = 'admin'; $this->Form->params['prefix'] = 'admin';
$this->Form->action = 'admin_edit'; $this->Form->action = 'admin_edit';
$result = $this->Form->inputs(); $result = $this->Form->inputs();
$this->assertPattern('/<legend>Edit Contact<\/legend>/', $result); $this->assertPattern('/<legend>Edit Contact<\/legend>/', $result);
$this->Form->create('Contact');
$result = $this->Form->inputs(false); $result = $this->Form->inputs(false);
$this->assertNoPattern('/<fieldset[^<>]*>/', $result); $this->assertNoPattern('/<fieldset[^<>]*>/', $result);
$this->assertNoPattern('/<legend>[^<>]*<\/legend>/', $result); $this->assertNoPattern('/<legend>[^<>]*<\/legend>/', $result);
$this->Form->create('Contact');
$result = $this->Form->inputs(array('fieldset' => false, 'legend' => false)); $result = $this->Form->inputs(array('fieldset' => false, 'legend' => false));
$this->assertNoPattern('/<fieldset[^<>]*>/', $result); $this->assertNoPattern('/<fieldset[^<>]*>/', $result);
$this->assertNoPattern('/<legend>[^<>]*<\/legend>/', $result); $this->assertNoPattern('/<legend>[^<>]*<\/legend>/', $result);
$this->Form->create('Contact');
$result = $this->Form->inputs(array('fieldset' => true, 'legend' => false)); $result = $this->Form->inputs(array('fieldset' => true, 'legend' => false));
$this->assertPattern('/<fieldset[^<>]*>/', $result); $this->assertPattern('/<fieldset[^<>]*>/', $result);
$this->assertNoPattern('/<legend>[^<>]*<\/legend>/', $result); $this->assertNoPattern('/<legend>[^<>]*<\/legend>/', $result);
$this->Form->create('Contact');
$result = $this->Form->inputs(array('fieldset' => false, 'legend' => 'Hello')); $result = $this->Form->inputs(array('fieldset' => false, 'legend' => 'Hello'));
$this->assertNoPattern('/<fieldset[^<>]*>/', $result); $this->assertNoPattern('/<fieldset[^<>]*>/', $result);
$this->assertNoPattern('/<legend>[^<>]*<\/legend>/', $result); $this->assertNoPattern('/<legend>[^<>]*<\/legend>/', $result);
$this->Form->create('Contact');
$result = $this->Form->inputs('Hello'); $result = $this->Form->inputs('Hello');
$this->assertPattern('/^<fieldset><legend[^<>]*>Hello<\/legend>.+<\/fieldset>$/s', $result); $this->assertPattern('/^<fieldset><legend[^<>]*>Hello<\/legend>.+<\/fieldset>$/s', $result);
$this->Form->create('Contact');
$result = $this->Form->inputs(array('legend' => 'Hello')); $result = $this->Form->inputs(array('legend' => 'Hello'));
$this->assertPattern('/^<fieldset><legend[^<>]*>Hello<\/legend>.+<\/fieldset>$/s', $result); $this->assertPattern('/^<fieldset><legend[^<>]*>Hello<\/legend>.+<\/fieldset>$/s', $result);
} }
@ -1030,8 +1050,12 @@ class FormHelperTest extends CakeTestCase {
$this->assertPattern('/name="data\[Contact\]\[published2\]\[month\]"/', $result); $this->assertPattern('/name="data\[Contact\]\[published2\]\[month\]"/', $result);
$this->assertPattern('/name="data\[Contact\]\[published2\]\[day\]"/', $result); $this->assertPattern('/name="data\[Contact\]\[published2\]\[day\]"/', $result);
$this->assertPattern('/name="data\[Contact\]\[published2\]\[year\]"/', $result); $this->assertPattern('/name="data\[Contact\]\[published2\]\[year\]"/', $result);
$result = $this->Form->input('ContactTag');
$this->assertPattern('/name="data\[ContactTag\]\[ContactTag\]\[\]"/', $result);
} }
function testMonth() { function testMonth() {
$result = $this->Form->month('Model.field'); $result = $this->Form->month('Model.field');
$this->assertPattern('/^<select[^<>]+name="data\[Model\]\[field\]\[month\]"[^<>]*>/', $result); $this->assertPattern('/^<select[^<>]+name="data\[Model\]\[field\]\[month\]"[^<>]*>/', $result);
@ -1540,12 +1564,12 @@ class FormHelperTest extends CakeTestCase {
function tearDown() { function tearDown() {
ClassRegistry::removeObject('view'); ClassRegistry::removeObject('view');
ClassRegistry::removeObject('Contact'); ClassRegistry::removeObject('Contact');
ClassRegistry::removeObject('ContactTag');
ClassRegistry::removeObject('OpenidUrl'); ClassRegistry::removeObject('OpenidUrl');
ClassRegistry::removeObject('UserForm'); ClassRegistry::removeObject('UserForm');
ClassRegistry::removeObject('ValidateItem'); ClassRegistry::removeObject('ValidateItem');
ClassRegistry::removeObject('ValidateUser'); ClassRegistry::removeObject('ValidateUser');
ClassRegistry::removeObject('ValidateProfile'); ClassRegistry::removeObject('ValidateProfile');
unset($this->Form); unset($this->Form);
} }