Skip to content

Commit

Permalink
Add tests for CheckboxList and RadioList class for validate attri…
Browse files Browse the repository at this point in the history
…butes. (#13)
  • Loading branch information
terabytesoftw committed Mar 19, 2024
1 parent 927bb64 commit efecac6
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Bug #11: Fix broken links in `docs` (@terabytesoftw)
- Enh #12: Add `CheckboxList` and `RadioList` class widgets (@terabytesoftw)
- Bug #13: Add tests for `CheckboxList` and `RadioList` class for validate attributes (@terabytesoftw)

## 0.1.2 March 15, 2024

Expand Down
2 changes: 1 addition & 1 deletion tests/FormControl/Input/CheckboxList/LabelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace UIAwesome\Html\Tests\FormControl\Input\CheckboxList;

use PHPForge\Support\Assert;
use UIAwesome\{Html\FormControl\Input\Checkbox, Html\FormControl\Input\CheckboxList};
use UIAwesome\Html\FormControl\Input\{Checkbox, CheckboxList};

/**
* @psalm-suppress PropertyNotSetInConstructor
Expand Down
39 changes: 39 additions & 0 deletions tests/FormControl/Input/CheckboxList/ValidateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace UIAwesome\Html\Tests\FormControl\Input\CheckboxList;

use PHPForge\Support\Assert;
use UIAwesome\Html\FormControl\Input\{Checkbox, CheckboxList};

/**
* @psalm-suppress PropertyNotSetInConstructor
*/
final class ValidateTest extends \PHPUnit\Framework\TestCase
{
public function testRequired(): void
{
Assert::equalsWithoutLE(
<<<HTML
<label>Select your fruits?</label>
<div>
<input id="checkboxlist-w0" name="CheckboxForm[text][]" type="checkbox" value="2" required>
<label for="checkboxlist-w0">Banana</label>
<input id="checkboxlist-w1" name="CheckboxForm[text][]" type="checkbox" value="3" required>
<label for="checkboxlist-w1">Orange</label>
</div>
HTML,
CheckboxList::widget()
->id('checkboxlist')
->items(
Checkbox::widget()->label('Banana')->value(2),
Checkbox::widget()->label('Orange')->value(3),
)
->label('Select your fruits?')
->name('CheckboxForm[text]')
->required()
->render(),
);
}
}
2 changes: 1 addition & 1 deletion tests/FormControl/Input/RadioList/CustomMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace UIAwesome\Html\Tests\FormControl\Input\RadioList;

use PHPForge\Support\Assert;
use UIAwesome\{Html\FormControl\Input\Radio, Html\FormControl\Input\RadioList};
use UIAwesome\Html\FormControl\Input\{Radio, RadioList};

/**
* @psalm-suppress PropertyNotSetInConstructor
Expand Down
2 changes: 1 addition & 1 deletion tests/FormControl/Input/RadioList/LabelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace UIAwesome\Html\Tests\FormControl\Input\RadioList;

use PHPForge\Support\Assert;
use UIAwesome\{Html\FormControl\Input\Radio, Html\FormControl\Input\RadioList};
use UIAwesome\Html\FormControl\Input\{Radio, RadioList};

/**
* @psalm-suppress PropertyNotSetInConstructor
Expand Down
36 changes: 36 additions & 0 deletions tests/FormControl/Input/RadioList/ValidateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace UIAwesome\Html\Tests\FormControl\Input\RadioList;

use PHPForge\Support\Assert;
use UIAwesome\Html\FormControl\Input\{Radio, RadioList};

final class ValidateTest extends \PHPUnit\Framework\TestCase
{
public function testRequired(): void
{
Assert::equalsWithoutLE(
<<<HTML
<label>Select your gender?</label>
<div>
<input id="radiolist-w0" name="CheckboxForm[text]" type="radio" value="1" required>
<label for="radiolist-w0">Female</label>
<input id="radiolist-w1" name="CheckboxForm[text]" type="radio" value="2" required>
<label class="value" for="radiolist-w1">Male</label>
</div>
HTML,
RadioList::widget()
->id('radiolist')
->items(
Radio::widget()->label('Female')->value(1),
Radio::widget()->label('Male')->labelClass('value')->value(2),
)
->label('Select your gender?')
->name('CheckboxForm[text]')
->required()
->render(),
);
}
}

0 comments on commit efecac6

Please sign in to comment.