-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
97 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace Cone\Root\Tests\Fields; | ||
|
||
use App\Models\User; | ||
use Cone\Root\Fields\Boolean; | ||
use Cone\Root\Tests\TestCase; | ||
use Illuminate\Http\Request; | ||
|
||
class BooleanTest extends TestCase | ||
{ | ||
protected Boolean $field; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->field = new Boolean('Admin'); | ||
} | ||
|
||
public function test_a_boolean_field_has_checkbox_type(): void | ||
{ | ||
$this->assertSame('checkbox', $this->field->getAttribute('type')); | ||
} | ||
|
||
public function test_a_boolean_field_has_checked_attribute(): void | ||
{ | ||
$this->assertNull($this->field->getAttribute('checked')); | ||
|
||
$this->field->checked(); | ||
$this->assertTrue($this->field->getAttribute('checked')); | ||
|
||
$this->field->checked(false); | ||
$this->assertFalse($this->field->getAttribute('checked')); | ||
} | ||
|
||
public function test_a_boolean_field_has_boolean_template(): void | ||
{ | ||
$this->assertSame('root::fields.boolean', $this->field->getTemplate()); | ||
} | ||
|
||
public function test_a_boolean_field_gets_value_for_hydrate(): void | ||
{ | ||
$request = Request::createFrom($this->app['request']); | ||
|
||
$request->merge(['admin' => 0]); | ||
$this->assertFalse($this->field->getValueForHydrate($request)); | ||
|
||
$request->merge(['admin' => 1]); | ||
$this->assertTrue($this->field->getValueForHydrate($request)); | ||
} | ||
|
||
public function test_a_boolean_field_resolves_value(): void | ||
{ | ||
$request = Request::createFrom($this->app['request']); | ||
|
||
$model = new User(); | ||
$this->assertFalse($this->field->resolveValue($request, $model)); | ||
|
||
$model->forceFill(['admin' => false]); | ||
$this->assertFalse($this->field->resolveValue($request, $model)); | ||
|
||
$model->forceFill(['admin' => true]); | ||
$this->assertTrue($this->field->resolveValue($request, $model)); | ||
} | ||
|
||
public function test_a_boolean_field_resolves_format(): void | ||
{ | ||
$request = Request::createFrom($this->app['request']); | ||
|
||
$model = new User(); | ||
|
||
$model->forceFill(['admin' => false]); | ||
$this->assertSame( | ||
'<span class="status status--danger">No</span>', | ||
$this->field->resolveFormat($request, $model) | ||
); | ||
|
||
$model->forceFill(['admin' => true]); | ||
$this->assertSame( | ||
'<span class="status status--success">Yes</span>', | ||
$this->field->resolveFormat($request, $model) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters