Skip to content

Commit 6d3445a

Browse files
committed
checkbox now return '0' or '1'
select tag update
1 parent d6f36eb commit 6d3445a

7 files changed

Lines changed: 28 additions & 23 deletions

File tree

src/Ease/Html/CheckboxTag.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ public function setValue($value = true): void
7070
}
7171

7272
/**
73-
* Obtains curent checkbox state.
73+
* Obtains current checkbox state.
7474
*
75-
* @return bool $value
75+
* @return string $value '0' or '1'
7676
*/
77-
public function getValue()
77+
public function getValue(): ?string
7878
{
79-
return $this->getTagProperty('checked') === 'true';
79+
return $this->getTagProperty('checked') ? '1' : '0';
8080
}
8181
}

src/Ease/Html/Input.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ public function setValue(string $value);
3232
*
3333
* @return string $value
3434
*/
35-
public function getValue();
35+
public function getValue(): ?string;
3636
}

src/Ease/Html/InputTag.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ public function setValue($value): void
6060
/**
6161
* Returns the value of an input field.
6262
*
63-
* @return string $value
63+
* @return null|string $value
6464
*/
65-
public function getValue()
65+
public function getValue(): ?string
6666
{
6767
return $this->getTagProperty('value');
6868
}

src/Ease/Html/SelectTag.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ class SelectTag extends PairTag implements Input
4040
/**
4141
* Html select box.
4242
*
43-
* @param string $name name
44-
* @param array $items items
45-
* @param string $defaultValue default item id
46-
* @param array $properties select tag properties
43+
* @param string $name name
44+
* @param array<string, string> $items items
45+
* @param string $defaultValue default item id
46+
* @param array<string, string> $properties select tag properties
4747
*/
4848
public function __construct(string $name, array $items = [], string $defaultValue = '', array $properties = [])
4949
{
5050
parent::__construct('select', $properties);
5151
$this->defaultValue = $defaultValue;
5252
$this->setTagName($name);
5353

54-
if (\is_array($items)) {
54+
if ($items) {
5555
$this->addItems($items);
5656
}
5757
}
@@ -68,7 +68,7 @@ public function addItems(array $items): array
6868
foreach ($items as $itemName => $itemValue) {
6969
$added[$itemName] = $this->addItem(new OptionTag((string) $itemValue, (string) $itemName));
7070

71-
if ($this->defaultValue === $itemName) {
71+
if ($this->defaultValue === (string) $itemName) {
7272
$this->lastItem()->setDefault();
7373
}
7474
}
@@ -160,14 +160,18 @@ public function disableItem($itemID): void
160160
* Get value of selected item.
161161
*/
162162
#[\Override]
163-
public function getValue(): string
163+
public function getValue(): ?string
164164
{
165+
$value = null;
166+
165167
foreach ($this->pageParts as $option) {
166168
$pos = array_search('selected', $option->tagProperties, true);
167169

168170
if (($pos !== false) && is_numeric($pos)) {
169-
return $option->getValue();
171+
$value = $option->getValue();
170172
}
171173
}
174+
175+
return $value;
172176
}
173177
}

tests/src/Ease/Html/BodyTagTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class BodyTagTest extends PairTagTest
2222
{
2323
public string $rendered = '<body></body>';
2424
public string $renderedEmpty = '<body></body>';
25-
public string $renderedWithJS = '<body>
25+
public string $renderedWithJS = <<<'EOD'
26+
<body>
2627
2728
<script>
2829
// <![CDATA[
@@ -36,8 +37,8 @@ class BodyTagTest extends PairTagTest
3637
$(document).ready(function () { alert("hallo"); });
3738
// ]]>
3839
</script>
39-
</body>';
40-
40+
</body>
41+
EOD;
4142
protected $object;
4243

4344
/**

tests/src/Ease/Html/CheckboxTagTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ protected function tearDown(): void
4646
public function testSetValue(): void
4747
{
4848
$this->object->setValue(true);
49-
$this->assertTrue($this->object->getValue());
49+
$this->assertEquals('1', $this->object->getValue());
5050
$this->object->setValue(false);
51-
$this->assertFalse($this->object->getValue());
51+
$this->assertEquals('0', $this->object->getValue());
5252
}
5353

5454
/**
@@ -57,9 +57,9 @@ public function testSetValue(): void
5757
public function testGetValue(): void
5858
{
5959
$this->object->setValue(true);
60-
$this->assertTrue($this->object->getValue());
60+
$this->assertEquals('1', $this->object->getValue());
6161
$this->object->setValue(false);
62-
$this->assertFalse($this->object->getValue());
62+
$this->assertEquals('0', $this->object->getValue());
6363
}
6464

6565
/**

tests/src/Ease/Html/SubmitButtonTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected function setUp(): void
3939
protected function tearDown(): void
4040
{
4141
}
42-
42+
4343
/**
4444
* @covers \Ease\Html\SubmitButton::__construct
4545
*/

0 commit comments

Comments
 (0)