Skip to content

Commit

Permalink
Add test for checkbox field default values (wintercms#1119)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjauvin authored May 6, 2024
1 parent db35768 commit 22749b0
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions modules/backend/tests/formwidgets/CheckboxTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Backend\Tests\FormWidgets;

use Backend\Widgets\Form;
use Winter\Storm\Database\Model;
use System\Tests\Bootstrap\PluginTestCase;

class CheckboxTest extends PluginTestCase
{
public $form = null;

public function setUp(): void
{
parent::setUp();

$this->form = new Form(null, [
'model' => new Model,
'arrayName' => 'array',
'fields' => [
'unchecked' => [
'type' => 'checkbox',
'label' => 'My Test Checkbox unchecked',
],
'checkedForced' => [
'type' => 'checkbox',
'label' => 'My Test Checkbox checked',
'default' => true,
],
'uncheckedForced' => [
'type' => 'checkbox',
'label' => 'My Test Checkbox unchecked',
'default' => false,
],
],
]);

$this->form->render();
}

public function testConfigDefaultValue()
{
$unchecked = $this->form->getField('unchecked');
$this->assertFalse($unchecked->isSelected());

$checkedForced = $this->form->getField('checkedForced');
$this->assertTrue($checkedForced->isSelected());

$uncheckedForced = $this->form->getField('uncheckedForced');
$this->assertFalse($uncheckedForced->isSelected());
}
}

0 comments on commit 22749b0

Please sign in to comment.