Skip to content

Commit

Permalink
Split large test method
Browse files Browse the repository at this point in the history
  • Loading branch information
lilHermit committed Feb 2, 2017
1 parent 2606865 commit 5482f3b
Showing 1 changed file with 51 additions and 39 deletions.
90 changes: 51 additions & 39 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -8500,12 +8500,11 @@ public function testNestedLabelInput()
/**
* Tests to make sure `labelOptions` is rendered correctly by MultiCheckboxWidget and RadioWidget
*
* Tests false, class (as string and array) also makes sure 'selected' is added to the class if checked.
* Also checks to make sure any custom attributes are rendered
* This test makes sure `false` excludes the label from the render
*
*/
public function testControlLabelManipulation()
public function testInputLabelManipulationDisableLabels()
{
// Tests removal of label around input (Radio)
$result = $this->Form->input('test', [
'type' => 'radio',
'options' => ['A', 'B'],
Expand All @@ -8523,7 +8522,43 @@ public function testControlLabelManipulation()
];
$this->assertHtml($expected, $result);

// Tests String class (Radio)
$result = $this->Form->input('checkbox1', [
'label' => 'My checkboxes',
'multiple' => 'checkbox',
'type' => 'select',
'options' => [
['text' => 'First Checkbox', 'value' => 1],
['text' => 'Second Checkbox', 'value' => 2]
],
'labelOptions' => false
]);
$expected = [
['div' => ['class' => 'input select']],
['label' => ['for' => 'checkbox1']],
'My checkboxes',
'/label',
'input' => ['type' => 'hidden', 'name' => 'checkbox1', 'value' => ''],
['div' => ['class' => 'checkbox']],
['input' => ['type' => 'checkbox', 'name' => 'checkbox1[]', 'value' => '1', 'id' => 'checkbox1-1']],
'/div',
['div' => ['class' => 'checkbox']],
['input' => ['type' => 'checkbox', 'name' => 'checkbox1[]', 'value' => '2', 'id' => 'checkbox1-2']],
'/div',
'/div'
];
$this->assertHtml($expected, $result);
}

/**
* Tests to make sure `labelOptions` is rendered correctly by RadioWidget
*
* This test checks rendering of class (as string and array) also makes sure 'selected' is
* added to the class if checked.
*
* Also checks to make sure any custom attributes are rendered correctly
*/
public function testInputLabelManipulationRadios()
{
$result = $this->Form->input('test', [
'type' => 'radio',
'options' => ['A', 'B'],
Expand All @@ -8547,7 +8582,6 @@ public function testControlLabelManipulation()
];
$this->assertHtml($expected, $result);

// Tests to make sure selected is added to class (Radio)
$result = $this->Form->input('test', [
'type' => 'radio',
'options' => ['A', 'B'],
Expand All @@ -8572,7 +8606,6 @@ public function testControlLabelManipulation()
];
$this->assertHtml($expected, $result);

// Tests class as array and adding selected (Radio)
$result = $this->Form->input('test', [
'type' => 'radio',
'options' => ['A', 'B'],
Expand All @@ -8597,7 +8630,6 @@ public function testControlLabelManipulation()
];
$this->assertHtml($expected, $result);

// Tests class as array and adding selected as well as custom attributes (Radio)
$result = $this->Form->radio('test', ['A', 'B'], [
'label' => [
'class' => ['custom-class', 'another-class'],
Expand All @@ -8623,35 +8655,18 @@ public function testControlLabelManipulation()
'/label',
];
$this->assertHtml($expected, $result);
}

// Tests removal of label around input (MultiCheckbox)
$result = $this->Form->input('checkbox1', [
'label' => 'My checkboxes',
'multiple' => 'checkbox',
'type' => 'select',
'options' => [
['text' => 'First Checkbox', 'value' => 1],
['text' => 'Second Checkbox', 'value' => 2]
],
'labelOptions' => false
]);
$expected = [
['div' => ['class' => 'input select']],
['label' => ['for' => 'checkbox1']],
'My checkboxes',
'/label',
'input' => ['type' => 'hidden', 'name' => 'checkbox1', 'value' => ''],
['div' => ['class' => 'checkbox']],
['input' => ['type' => 'checkbox', 'name' => 'checkbox1[]', 'value' => '1', 'id' => 'checkbox1-1']],
'/div',
['div' => ['class' => 'checkbox']],
['input' => ['type' => 'checkbox', 'name' => 'checkbox1[]', 'value' => '2', 'id' => 'checkbox1-2']],
'/div',
'/div'
];
$this->assertHtml($expected, $result);

// Tests class as array, adding selected to class with custom attributes (MultiCheckbox)
/**
* Tests to make sure `labelOptions` is rendered correctly by MultiCheckboxWidget
*
* This test checks rendering of class (as string and array) also makes sure 'selected' is
* added to the class if checked.
*
* Also checks to make sure any custom attributes are rendered correctly
*/
public function testInputLabelManipulationCheckboxes()
{
$result = $this->Form->input('checkbox1', [
'label' => 'My checkboxes',
'multiple' => 'checkbox',
Expand All @@ -8663,7 +8678,6 @@ public function testControlLabelManipulation()
'labelOptions' => ['class' => 'custom-class'],
'value' => ['1']
]);

$expected = [
['div' => ['class' => 'input select']],
['label' => ['for' => 'checkbox1']],
Expand Down Expand Up @@ -8703,7 +8717,6 @@ public function testControlLabelManipulation()
];
$this->assertHtml($expected, $result);

// Tests class as array, adding selected to class with custom attributes (MultiCheckbox)
$result = $this->Form->input('checkbox1', [
'label' => 'My checkboxes',
'multiple' => 'checkbox',
Expand All @@ -8716,7 +8729,6 @@ public function testControlLabelManipulation()
'value' => ['1']

]);

$expected = [
['div' => ['class' => 'input select']],
['label' => ['for' => 'checkbox1']],
Expand Down

0 comments on commit 5482f3b

Please sign in to comment.