From f99c8996e3f4e656829d989374b2f05f582e61e7 Mon Sep 17 00:00:00 2001 From: tclineks Date: Thu, 17 Apr 2008 20:31:49 +0000 Subject: [PATCH] added test for FormHelper::create with non-standard primaryKey. disproves and closes #3942 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6680 3807eeeb-6ff5-0310-8944-8be069107fe0 --- .../cases/libs/view/helpers/form.test.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index e3e141b14..cb0c57324 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -62,6 +62,19 @@ class Contact extends CakeTestModel { var $hasAndBelongsToMany = array('ContactTag' => array()); } + +Class ContactNonStandardPk extends Contact { + var $primaryKey = 'pk'; + var $name = 'ContactNonStandardPk'; + + function schema() { + $this->_schema = parent::schema(); + $this->_schema['pk'] = $this->_schema['id']; + unset($this->_schema['id']); + return $this->_schema; + } +} + class ContactTag extends Model { var $useTable = false; @@ -216,6 +229,7 @@ class FormHelperTest extends CakeTestCase { ClassRegistry::addObject('view', $view); ClassRegistry::addObject('Contact', new Contact()); + ClassRegistry::addObject('ContactNonStandardPk', new ContactNonStandardPk()); ClassRegistry::addObject('OpenidUrl', new OpenidUrl()); ClassRegistry::addObject('UserForm', new UserForm()); ClassRegistry::addObject('ValidateItem', new ValidateItem()); @@ -1482,6 +1496,10 @@ class FormHelperTest extends CakeTestCase { $this->assertPattern('/^]+action="\/contacts\/edit\/1"[^<>]*>/', $result); $this->assertNoPattern('/^]+[^id|method|action]=[^<>]*>/', $result); + $this->Form->data['ContactNonStandardPk']['pk'] = 1; + $result = $this->Form->create('ContactNonStandardPk'); + $this->assertPattern('/^]+id="ContactNonStandardPkEditForm"[^<>]+>/', $result); + $result = $this->Form->create('Contact', array('id' => 'TestId')); $this->assertPattern('/id="TestId"/', $result); @@ -1748,6 +1766,7 @@ class FormHelperTest extends CakeTestCase { function tearDown() { ClassRegistry::removeObject('view'); ClassRegistry::removeObject('Contact'); + ClassRegistry::removeObject('ContactNonStandardPkEditForm'); ClassRegistry::removeObject('ContactTag'); ClassRegistry::removeObject('OpenidUrl'); ClassRegistry::removeObject('UserForm');