Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Dec 31, 2023
1 parent f7c3f00 commit e58e472
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/Fields/Radio.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ class Radio extends Checkbox
*/
public function newOption(mixed $value, string $label): Option
{
$option = parent::newOption($value, $label);

$option->setAttributes([
'type' => 'radio',
'class' => 'form-check__control',
'name' => $this->getModelAttribute(),
]);

return $option;
return parent::newOption($value, $label)
->class('form-check__control')
->setAttributes([
'type' => 'radio',
'name' => $this->getModelAttribute(),
]);
}
}
27 changes: 27 additions & 0 deletions tests/Fields/RadioTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Cone\Root\Tests\Fields;

use Cone\Root\Fields\Radio;
use Cone\Root\Tests\TestCase;

class RadioTest extends TestCase
{
protected Radio $field;

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

$this->field = new Radio('Role');
}

public function test_a_checkbox_field_makes_new_option(): void
{
$option = $this->field->newOption('test', 'Test');

$this->assertEmpty(
array_diff(['value' => 'test'], $option->jsonSerialize())
);
}
}
23 changes: 23 additions & 0 deletions tests/Fields/RangeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Cone\Root\Tests\Fields;

use Cone\Root\Fields\Range;
use Cone\Root\Tests\TestCase;

class RangeTest extends TestCase
{
protected Range $field;

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

$this->field = new Range('Age');
}

public function test_a_range_field_has_range_type(): void
{
$this->assertSame('range', $this->field->getAttribute('type'));
}
}
50 changes: 50 additions & 0 deletions tests/Fields/TextTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Cone\Root\Tests\Fields;

use Cone\Root\Fields\Text;
use Cone\Root\Tests\TestCase;

class TextTest extends TestCase
{
protected Text $field;

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

$this->field = new Text('Name');
}

public function test_a_text_field_has_text_type(): void
{
$this->assertSame('text', $this->field->getAttribute('type'));
}

public function test_a_text_field_has_size_attribute(): void
{
$this->assertNull($this->field->getAttribute('size'));

$this->field->size(10);

$this->assertSame(10, $this->field->getAttribute('size'));
}

public function test_a_text_field_has_minlength_attribute(): void
{
$this->assertNull($this->field->getAttribute('minlength'));

$this->field->minlength(10);

$this->assertSame(10, $this->field->getAttribute('minlength'));
}

public function test_a_text_field_has_maxlength_attribute(): void
{
$this->assertNull($this->field->getAttribute('maxlength'));

$this->field->maxlength(10);

$this->assertSame(10, $this->field->getAttribute('maxlength'));
}
}
41 changes: 41 additions & 0 deletions tests/Fields/TextareaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Cone\Root\Tests\Fields;

use Cone\Root\Fields\Textarea;
use Cone\Root\Tests\TestCase;

class TextareaTest extends TestCase
{
protected Textarea $field;

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

$this->field = new Textarea('Content');
}

public function test_a_textarea_field_has_textarea_template(): void
{
$this->assertSame('root::fields.textarea', $this->field->getTemplate());
}

public function test_a_textarea_field_has_rows_attribute(): void
{
$this->assertNull($this->field->getAttribute('rows'));

$this->field->rows(10);

$this->assertSame(10, $this->field->getAttribute('rows'));
}

public function test_a_textarea_field_has_cols_attribute(): void
{
$this->assertNull($this->field->getAttribute('cols'));

$this->field->cols(10);

$this->assertSame(10, $this->field->getAttribute('cols'));
}
}

0 comments on commit e58e472

Please sign in to comment.