Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add templateVars tests for button, checkbox, file and label widgets.
Add tests to ensure the templateVars option is wired up.
  • Loading branch information
markstory committed Jun 29, 2015
1 parent 146d7c8 commit 5b98a4c
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/TestCase/View/Widget/ButtonWidgetTest.php
Expand Up @@ -128,4 +128,32 @@ public function testRenderAttributes()
];
$this->assertHtml($expected, $result);
}

/**
* Ensure templateVars option is hooked up.
*
* @return void
*/
public function testRenderTemplateVars()
{
$this->templates->add([
'button' => '<button {{attrs}} custom="{{custom}}">{{text}}</button>',
]);

$button = new ButtonWidget($this->templates);
$data = [
'templateVars' => ['custom' => 'value'],
'text' => 'Go',
];
$result = $button->render($data, $this->context);
$expected = [
'button' => [
'type' => 'submit',
'custom' => 'value'
],
'Go',
'/button'
];
$this->assertHtml($expected, $result);
}
}
29 changes: 29 additions & 0 deletions tests/TestCase/View/Widget/CheckboxWidgetTest.php
Expand Up @@ -233,4 +233,33 @@ public function testRenderUnCheckedValue($checked)
];
$this->assertHtml($expected, $result);
}

/**
* Ensure templateVars option is hooked up.
*
* @return void
*/
public function testRenderTemplateVars()
{
$this->templates->add([
'checkbox' => '<input type="checkbox" custom="{{custom}}" name="{{name}}" value="{{value}}"{{attrs}}>',
]);

$checkbox = new CheckboxWidget($this->templates);
$data = [
'templateVars' => ['custom' => 'value'],
'name' => 'Comment[spam]',
'value' => 1,
];
$result = $checkbox->render($data, $this->context);
$expected = [
'input' => [
'type' => 'checkbox',
'custom' => 'value',
'name' => 'Comment[spam]',
'value' => 1,
]
];
$this->assertHtml($expected, $result);
}
}
27 changes: 27 additions & 0 deletions tests/TestCase/View/Widget/FileWidgetTest.php
Expand Up @@ -69,4 +69,31 @@ public function testRenderAttributes()
];
$this->assertHtml($expected, $result);
}

/**
* Ensure templateVars option is hooked up.
*
* @return void
*/
public function testRenderTemplateVars()
{
$this->templates->add([
'file' => '<input custom="{{custom}}" type="file" name="{{name}}"{{attrs}}>',
]);

$input = new FileWidget($this->templates);
$data = [
'templateVars' => ['custom' => 'value'],
'name' => 'files',
];
$result = $input->render($data, $this->context);
$expected = [
'input' => [
'type' => 'file',
'name' => 'files',
'custom' => 'value'
],
];
$this->assertHtml($expected, $result);
}
}
25 changes: 25 additions & 0 deletions tests/TestCase/View/Widget/LabelWidgetTest.php
Expand Up @@ -103,4 +103,29 @@ public function testRenderAttributes()
];
$this->assertHtml($expected, $result);
}

/**
* Ensure templateVars option is hooked up.
*
* @return void
*/
public function testRenderTemplateVars()
{
$this->templates->add([
'label' => '<label custom="{{custom}}" {{attrs}}>{{text}}</label>',
]);

$label = new LabelWidget($this->templates);
$data = [
'templateVars' => ['custom' => 'value'],
'text' => 'Label Text',
];
$result = $label->render($data, $this->context);
$expected = [
'label' => ['custom' => 'value'],
'Label Text',
'/label'
];
$this->assertHtml($expected, $result);
}
}

0 comments on commit 5b98a4c

Please sign in to comment.