Skip to content

Commit

Permalink
Moved tests from FormHelperTest to respective Widget TestCases
Browse files Browse the repository at this point in the history
  • Loading branch information
lilHermit committed Feb 9, 2017
1 parent 59a02e7 commit 3d84bde
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 82 deletions.
82 changes: 0 additions & 82 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -8496,86 +8496,4 @@ public function testNestedLabelInput()
];
$this->assertHtml($expected, $result);
}

/**
* testRadioAttributes method
*
* Test generation of radio widget with additional attributes.
*
* @return void
*/
public function testRadioAttributes()
{
$result = $this->Form->radio('Model.field', ['option A'], ['class' => 'my-class', 'data-ref' => 'custom-attr']);
$expected = [
'input' => ['type' => 'hidden', 'name' => 'Model[field]', 'value' => ''],
'label' => ['for' => 'model-field-0'],
['input' => [
'type' => 'radio', 'name' => 'Model[field]',
'value' => '0', 'id' => 'model-field-0',
'class' => 'my-class', 'data-ref' => 'custom-attr'
]],
'option A',
'/label'
];
$this->assertHtml($expected, $result);
}

/**
* testCheckboxAttributes method
*
* Test generation of checkbox widget with additional attributes.
*
* @return void
*/
public function testCheckboxAttributes()
{
$result = $this->Form->checkbox('Model.field', ['class' => 'my-class', 'data-ref' => 'custom-attr']);
$expected = [
'input' => ['type' => 'hidden', 'name' => 'Model[field]', 'value' => '0'],
['input' => [
'type' => 'checkbox', 'name' => 'Model[field]',
'value' => '1', 'class' => 'my-class',
'data-ref' => 'custom-attr'
]]
];
$this->assertHtml($expected, $result);
}

/**
* testMultiCheckboxAttributes method
*
* Test generation of multiple checkboxes with additional attributes
*
* @return void
*/
public function testMultiCheckboxAttributes()
{
$result = $this->Form->multiCheckbox('category', ['1', '2'], ['class' => 'my-class', 'data-ref' => 'custom-attr']);

$expected = [
'input' => ['type' => 'hidden', 'name' => 'category', 'value' => ''],
['div' => ['class' => 'checkbox']],
['label' => ['for' => 'category-0']],
['input' => [
'type' => 'checkbox', 'name' => 'category[]',
'value' => '0', 'id' => 'category-0',
'class' => 'my-class', 'data-ref' => 'custom-attr'
]],
'1',
'/label',
'/div',
['div' => ['class' => 'checkbox']],
['label' => ['for' => 'category-1']],
['input' => [
'type' => 'checkbox', 'name' => 'category[]',
'value' => '1', 'id' => 'category-1',
'class' => 'my-class', 'data-ref' => 'custom-attr'
]],
'2',
'/label',
'/div'
];
$this->assertHtml($expected, $result);
}
}
31 changes: 31 additions & 0 deletions tests/TestCase/View/Widget/CheckboxWidgetTest.php
Expand Up @@ -262,4 +262,35 @@ public function testRenderTemplateVars()
];
$this->assertHtml($expected, $result);
}

/**
* testRenderCustomAttributes method
*
* Test render with custom attributes.
*
* @return void
*/
public function testRenderCustomAttributes()
{
$checkbox = new CheckboxWidget($this->templates);

$result = $checkbox->render([
'name' => 'Model[field]',
'class' => 'my-class',
'data-ref' => 'custom-attr',
'value' => 1

], $this->context);

$expected = [
'input' => [
'type' => 'checkbox',
'name' => 'Model[field]',
'value' => '1',
'class' => 'my-class',
'data-ref' => 'custom-attr'
]
];
$this->assertHtml($expected, $result);
}
}
53 changes: 53 additions & 0 deletions tests/TestCase/View/Widget/MultiCheckboxWidgetTest.php
Expand Up @@ -486,4 +486,57 @@ public function testRenderPartialGrouped()
];
$this->assertHtml($expected, $result);
}

/**
* testRenderCustomAttributes method
*
* Test render with custom attributes
*
* @return void
*/
public function testRenderCustomAttributes()
{
$label = new LabelWidget($this->templates);
$input = new MultiCheckboxWidget($this->templates, $label);
$result = $input->render([
'name' => 'category',
'options' => ['1', '2'],
'class' => 'my-class',
'data-ref' => 'custom-attr',
], $this->context);
$expected = [
['div' => ['class' => 'checkbox']],
[
'input' => [
'type' => 'checkbox',
'name' => 'category[]',
'value' => '0',
'id' => 'category-0',
'class' => 'my-class',
'data-ref' => 'custom-attr'
]
],
['label' => ['for' => 'category-0']],
'1',
'/label',
'/div',

['div' => ['class' => 'checkbox']],
[
'input' => [
'type' => 'checkbox',
'name' => 'category[]',
'value' => '1',
'id' => 'category-1',
'class' => 'my-class',
'data-ref' => 'custom-attr'
]
],
['label' => ['for' => 'category-1']],
'2',
'/label',
'/div'
];
$this->assertHtml($expected, $result);
}
}
49 changes: 49 additions & 0 deletions tests/TestCase/View/Widget/RadioWidgetTest.php
Expand Up @@ -688,4 +688,53 @@ public function testRenderTemplateVars()
$this->assertContains('one x l-var wrap-var</label>', $result);
$this->assertContains('two wrap-var</label>', $result);
}

/**
* testRenderCustomAttributes method
*
* Test render with custom attributes.
*
* @return void
*/
public function testRenderCustomAttributes()
{
$label = new NestingLabelWidget($this->templates);
$radio = new RadioWidget($this->templates, $label);
$result = $radio->render([
'name' => 'Model[field]',
'label' => null,
'options' => ['option A', 'option B'],
'class' => 'my-class',
'data-ref' => 'custom-attr'
], $this->context);
$expected = [
['label' => ['for' => 'model-field-0']],
[
'input' => [
'type' => 'radio',
'name' => 'Model[field]',
'value' => '0',
'id' => 'model-field-0',
'class' => 'my-class',
'data-ref' => 'custom-attr'
]
],
'option A',
'/label',
['label' => ['for' => 'model-field-1']],
[
'input' => [
'type' => 'radio',
'name' => 'Model[field]',
'value' => '1',
'id' => 'model-field-1',
'class' => 'my-class',
'data-ref' => 'custom-attr'
]
],
'option B',
'/label'
];
$this->assertHtml($expected, $result);
}
}

0 comments on commit 3d84bde

Please sign in to comment.