Skip to content

Commit 7d4ab40

Browse files
committed
Improved CheckboxInput unit tests.
1 parent f7e19e4 commit 7d4ab40

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Widgets/CheckboxInput.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ public function getContext(string $name, $value, array $attrs = null)
2020

2121
public function valueFromData($data, $files, string $name)
2222
{
23-
return array_key_exists($name, $data) ? bool($data[$name]) : false;
23+
return array_key_exists($name, $data) ? (bool) $data[$name] : false;
2424
}
2525
}

tests/unit/Widgets/CheckboxInputTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,16 @@ public function testRenderNullValue()
3737
$expected = '<input type="checkbox" id="id_name" name="name"/>';
3838
$this->assertXmlStringEqualsXmlString($expected, $render);
3939
}
40+
41+
public function testValueFromData()
42+
{
43+
$result = $this->widget->ValueFromData(["name" => "true"], [], "name");
44+
$this->assertTrue($result);
45+
}
46+
47+
public function testValueFromDataNotExistent()
48+
{
49+
$result = $this->widget->ValueFromData(["name2" => "true"], [], "name");
50+
$this->assertFalse($result);
51+
}
4052
}

0 commit comments

Comments
 (0)