Skip to content

Commit

Permalink
Toggle fieldtype should augment to a boolean even when null.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga committed Dec 15, 2020
1 parent 05601e4 commit 1f11c9c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Fieldtypes/Toggle.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ public function process($data)
{
return (bool) $data;
}

public function augment($data)
{
return (bool) $data;
}
}
20 changes: 20 additions & 0 deletions tests/Fieldtypes/ToggleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Tests\Fieldtypes;

use Statamic\Fields\Field;
use Statamic\Fieldtypes\Toggle;
use Tests\TestCase;

class ToggleTest extends TestCase
{
/** @test */
public function it_augments_to_a_boolean()
{
$field = (new Toggle)->setField(new Field('test', ['type' => 'toggle']));

$this->assertFalse($field->augment(false));
$this->assertFalse($field->augment(null));
$this->assertTrue($field->augment(true));
}
}

0 comments on commit 1f11c9c

Please sign in to comment.