Permalink
Browse files

Reformatting tests, and fixing trailing whitespace.

Adding doc comments for new form helper tests.
  • Loading branch information...
markstory committed Oct 22, 2009
1 parent 6123ed4 commit dac26d92bc2c80bc108eb21e2bee99b09f0de9e0
Showing with 75 additions and 67 deletions.
  1. +59 −61 cake/tests/cases/libs/view/helper.test.php
  2. +16 −6 cake/tests/cases/libs/view/helpers/form.test.php
@@ -438,7 +438,7 @@ function testAssetTimestamp() {
Configure::write('debug', 0);
$result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css');
$this->assertPattern('/' . preg_quote(CSS_URL . 'cake.generic.css?', '/') . '[0-9]+/', $result);
-
+
$result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css?someparam');
$this->assertEqual($result, CSS_URL . 'cake.generic.css?someparam');
@@ -592,65 +592,63 @@ function testClean() {
$result = $this->Helper->clean('<script>alert(document.cookie)</script>');
$this->assertEqual($result, '<script>alert(document.cookie)</script>');
}
-
- /**
- * testMultiDimensionalField method
- *
- * @access public
- * @return void
- */
- function testMultiDimensionalField() {
- // PHP4 reference hack
- ClassRegistry::removeObject('view');
- ClassRegistry::addObject('view', $this->View);
-
- $this->Helper->setEntity('HelperTestPost', true);
-
- $this->Helper->setEntity('HelperTestPost.2.HelperTestComment.1.title');
- $this->assertEqual($this->View->model, 'HelperTestPost');
- $this->assertEqual($this->View->association, 'HelperTestComment');
- $this->assertEqual($this->View->modelId,2);
- $this->assertEqual($this->View->field, 'title');
-
- $this->Helper->setEntity('HelperTestPost.1.HelperTestComment.1.HelperTestTag.1.created');
- $this->assertEqual($this->View->field,'created');
- $this->assertEqual($this->View->association,'HelperTestTag');
- $this->assertEqual($this->View->modelId,1);
-
-
- $this->Helper->setEntity('HelperTestPost.0.HelperTestComment.1.HelperTestTag.1.fake');
- $this->assertEqual($this->View->model,'HelperTestPost');
- $this->assertEqual($this->View->association,'HelperTestTag');
- $this->assertEqual($this->View->field,null);
-
- $this->Helper->setEntity('1.HelperTestComment.1.HelperTestTag.created.year');
- $this->assertEqual($this->View->model,'HelperTestPost');
- $this->assertEqual($this->View->association,'HelperTestTag');
- $this->assertEqual($this->View->field,'created');
- $this->assertEqual($this->View->modelId,1);
- $this->assertEqual($this->View->fieldSuffix,'year');
-
- $this->Helper->data['HelperTestPost'][2]['HelperTestComment'][1]['title'] = 'My Title';
- $result = $this->Helper->value('HelperTestPost.2.HelperTestComment.1.title');
- $this->assertEqual($result,'My Title');
-
- $this->Helper->data['HelperTestPost'][2]['HelperTestComment'][1]['created']['year'] = 2008;
- $result = $this->Helper->value('HelperTestPost.2.HelperTestComment.1.created.year');
- $this->assertEqual($result,2008);
-
- $this->Helper->data[2]['HelperTestComment'][1]['created']['year'] = 2008;
- $result = $this->Helper->value('HelperTestPost.2.HelperTestComment.1.created.year');
- $this->assertEqual($result,2008);
-
- $this->Helper->data['HelperTestPost']['title'] = 'My Title';
- $result = $this->Helper->value('title');
- $this->assertEqual($result,'My Title');
-
- $this->Helper->data['My']['title'] = 'My Title';
- $result = $this->Helper->value('My.title');
- $this->assertEqual($result,'My Title');
- }
-
-
+
+/**
+ * testMultiDimensionalField method
+ *
+ * @access public
+ * @return void
+ */
+ function testMultiDimensionalField() {
+ // PHP4 reference hack
+ ClassRegistry::removeObject('view');
+ ClassRegistry::addObject('view', $this->View);
+
+ $this->Helper->setEntity('HelperTestPost', true);
+
+ $this->Helper->setEntity('HelperTestPost.2.HelperTestComment.1.title');
+ $this->assertEqual($this->View->model, 'HelperTestPost');
+ $this->assertEqual($this->View->association, 'HelperTestComment');
+ $this->assertEqual($this->View->modelId,2);
+ $this->assertEqual($this->View->field, 'title');
+
+ $this->Helper->setEntity('HelperTestPost.1.HelperTestComment.1.HelperTestTag.1.created');
+ $this->assertEqual($this->View->field,'created');
+ $this->assertEqual($this->View->association,'HelperTestTag');
+ $this->assertEqual($this->View->modelId,1);
+
+ $this->Helper->setEntity('HelperTestPost.0.HelperTestComment.1.HelperTestTag.1.fake');
+ $this->assertEqual($this->View->model,'HelperTestPost');
+ $this->assertEqual($this->View->association,'HelperTestTag');
+ $this->assertEqual($this->View->field,null);
+
+ $this->Helper->setEntity('1.HelperTestComment.1.HelperTestTag.created.year');
+ $this->assertEqual($this->View->model,'HelperTestPost');
+ $this->assertEqual($this->View->association,'HelperTestTag');
+ $this->assertEqual($this->View->field,'created');
+ $this->assertEqual($this->View->modelId,1);
+ $this->assertEqual($this->View->fieldSuffix,'year');
+
+ $this->Helper->data['HelperTestPost'][2]['HelperTestComment'][1]['title'] = 'My Title';
+ $result = $this->Helper->value('HelperTestPost.2.HelperTestComment.1.title');
+ $this->assertEqual($result,'My Title');
+
+ $this->Helper->data['HelperTestPost'][2]['HelperTestComment'][1]['created']['year'] = 2008;
+ $result = $this->Helper->value('HelperTestPost.2.HelperTestComment.1.created.year');
+ $this->assertEqual($result,2008);
+
+ $this->Helper->data[2]['HelperTestComment'][1]['created']['year'] = 2008;
+ $result = $this->Helper->value('HelperTestPost.2.HelperTestComment.1.created.year');
+ $this->assertEqual($result,2008);
+
+ $this->Helper->data['HelperTestPost']['title'] = 'My Title';
+ $result = $this->Helper->value('title');
+ $this->assertEqual($result,'My Title');
+
+ $this->Helper->data['My']['title'] = 'My Title';
+ $result = $this->Helper->value('My.title');
+ $this->assertEqual($result,'My Title');
+ }
+
}
?>
@@ -709,7 +709,7 @@ function tearDown() {
unset($this->Form->Html, $this->Form, $this->Controller, $this->View);
Configure::write('Security.salt', $this->oldSalt);
}
-
+
/**
@@ -5478,6 +5478,11 @@ function testBrokenness() {
$this->assertTags($result, $expected);
}
+/**
+ * Test the generation of fields for a multi record form.
+ *
+ * @return void
+ */
function testMultiRecordForm() {
$this->Form->create('ValidateProfile');
$this->Form->data['ValidateProfile'][1]['ValidateItem'][2]['name'] = 'Value';
@@ -5498,7 +5503,7 @@ function testMultiRecordForm() {
'/div'
);
$this->assertTags($result, $expected);
-
+
$result = $this->Form->input('ValidateProfile.1.ValidateItem.2.created',array('empty' => true));
$expected = array(
'div' => array('class' => 'input date'),
@@ -5532,7 +5537,7 @@ function testMultiRecordForm() {
'/div'
);
$this->assertTags($result, $expected);
-
+
$this->Form->validationErrors['ValidateProfile'][1]['ValidateItem'][2]['profile_id'] = 'Error';
$this->Form->data['ValidateProfile'][1]['ValidateItem'][2]['profile_id'] = '1';
$result = $this->Form->input('ValidateProfile.1.ValidateItem.2.profile_id');
@@ -5555,17 +5560,22 @@ function testMultiRecordForm() {
);
$this->assertTags($result, $expected,true);
}
-
+
+/**
+ * test the correct display of multi-record form validation errors.
+ *
+ * @return void
+ */
function testMultiRecordFormValidationErrors() {
$this->Form->create('ValidateProfile');
$this->Form->validationErrors['ValidateProfile'][2]['ValidateItem'][1]['name'] = 'Error in field name';
$result = $this->Form->error('ValidateProfile.2.ValidateItem.1.name');
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field name', '/div'));
-
+
$this->Form->validationErrors['ValidateProfile'][2]['city'] = 'Error in field city';
$result = $this->Form->error('ValidateProfile.2.city');
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
-
+
$result = $this->Form->error('2.city');
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
}

0 comments on commit dac26d9

Please sign in to comment.