From 953c778f5fb7884a7e84e3a376bcb09135275ff0 Mon Sep 17 00:00:00 2001 From: "mariano.iglesias" Date: Fri, 18 Apr 2008 00:58:47 +0000 Subject: [PATCH] Adding tests to FormHelper including generating custom names for checkbox elements, closes #4479 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6688 3807eeeb-6ff5-0310-8944-8be069107fe0 --- .../cases/libs/view/helpers/form.test.php | 51 ++++++++++++++++--- 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index e126fd6d7..b130c0aea 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -681,12 +681,31 @@ class FormHelperTest extends CakeTestCase { $this->assertPattern('/^]+ \/>\s*(]+>\]+>\s*]*>\w+<\/label><\/div>\s*){3}$/', $result); $this->assertNoPattern('/]*>[^(first|second)]<\/label>/', $result); - /*$this->assertPattern('/^]+name="data\[Model\]\[multi_field\]\[\]+value="0"[^<>]+checked="checked">/', $result); - $this->assertPattern('/]+name="data\[Model\]\[multi_field\]\[\]+value="1"[^<>]+checked="checked">/', $result); - $this->assertPattern('/]+name="data\[Model\]\[multi_field\]\[\]+value="2">third/', $result); - $this->assertNoPattern('/]+name="data\[Model\]\[multi_field\]\[\]+value="[^012]"[^<>\/]*>$/', $result);*/ - $this->assertNoPattern('/]*>/', $result); - $this->assertNoPattern('/<\/select>/', $result); + $this->assertPattern('/^]+type="hidden"[^<>]+\/>/', $result); + $this->assertPattern('/^]+name="data\[Model\]\[multi_field\]"[^<>]+\/>/', $result); + $this->assertPattern('/^]+value=""[^<>]+\/>/', $result); + + $this->assertPattern('/]+type="checkbox"[^<>]+\/>]+>first<\/label>/', $result); + $this->assertPattern('/]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/>]+>first<\/label>/', $result); + $this->assertPattern('/]+checked="checked"[^<>]+\/>]+>first<\/label>/', $result); + $this->assertPattern('/]+value="0"[^<>]+\/>]+>first<\/label>/', $result); + $this->assertPattern('/]+id="ModelMultiField0"[^<>]+\/>]+>first<\/label>/', $result); + $this->assertPattern('/]+\/>]+for="ModelMultiField0"[^<>]*>first<\/label>/', $result); + $this->assertPattern('/]+\/>]+class="selected"[^<>]*>first<\/label>/', $result); + + $this->assertPattern('/]+type="checkbox"[^<>]+\/>]+>second<\/label>/', $result); + $this->assertPattern('/]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/>]+>second<\/label>/', $result); + $this->assertPattern('/]+checked="checked"[^<>]+\/>]+>second<\/label>/', $result); + $this->assertPattern('/]+value="1"[^<>]+\/>]+>second<\/label>/', $result); + $this->assertPattern('/]+id="ModelMultiField1"[^<>]+\/>]+>second<\/label>/', $result); + $this->assertPattern('/]+\/>]+for="ModelMultiField1"[^<>]*>second<\/label>/', $result); + $this->assertPattern('/]+\/>]+class="selected"[^<>]*>second<\/label>/', $result); + + $this->assertPattern('/]+type="checkbox"[^<>]+\/>]+>third<\/label>/', $result); + $this->assertPattern('/]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/>]+>third<\/label>/', $result); + $this->assertPattern('/]+value="2"[^<>]+\/>]+>third<\/label>/', $result); + $this->assertPattern('/]+id="ModelMultiField2"[^<>]+\/>]+>third<\/label>/', $result); + $this->assertPattern('/]+\/>]+for="ModelMultiField2"[^<>]*>third<\/label>/', $result); } function testLabel() { @@ -1162,6 +1181,26 @@ class FormHelperTest extends CakeTestCase { $this->assertPattern('/^]+\/>]+id="theID"[^<>]+\/>$/', $result); $this->assertPattern('/^]+\/>]+value="1"[^<>]+\/>$/', $result); $this->assertNoPattern('/^]+\/>]+checked="checked"[^<>]+\/>$/', $result); + + $result = $this->Form->checkbox('Model.CustomField.1.value'); + + $this->assertPattern('/^]+type="hidden"[^<>]+\/>]+type="checkbox"[^<>]+\/>$/', $result); + $this->assertPattern('/^]+name="' . preg_quote('data[Model][CustomField][1][value]') . '"[^<>]+\/>]+\/>$/', $result); + $this->assertPattern('/^]+value="0"[^<>]+\/>]+\/>$/', $result); + $this->assertPattern('/^]+id="ModelCustomField1Value_"[^<>]+\/>]+\/>$/', $result); + $this->assertPattern('/^]+\/>]+name="' . preg_quote('data[Model][CustomField][1][value]') . '"[^<>]+\/>$/', $result); + $this->assertPattern('/^]+\/>]+value="1"[^<>]+\/>$/', $result); + $this->assertPattern('/^]+\/>]+id="ModelCustomField1Value"[^<>]+\/>$/', $result); + + $result = $this->Form->checkbox('CustomField.1.value'); + + $this->assertPattern('/^]+type="hidden"[^<>]+\/>]+type="checkbox"[^<>]+\/>$/', $result); + $this->assertPattern('/^]+name="' . preg_quote('data[CustomField][1][value]') . '"[^<>]+\/>]+\/>$/', $result); + $this->assertPattern('/^]+value="0"[^<>]+\/>]+\/>$/', $result); + $this->assertPattern('/^]+id="CustomField1Value_"[^<>]+\/>]+\/>$/', $result); + $this->assertPattern('/^]+\/>]+name="' . preg_quote('data[CustomField][1][value]') . '"[^<>]+\/>$/', $result); + $this->assertPattern('/^]+\/>]+value="1"[^<>]+\/>$/', $result); + $this->assertPattern('/^]+\/>]+id="CustomField1Value"[^<>]+\/>$/', $result); } function testDateTime() {