-
Notifications
You must be signed in to change notification settings - Fork 28
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
23 changed files
with
631 additions
and
559 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 was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,59 @@ | ||
<?php | ||
|
||
namespace SimpleSquid\Nova\Fields\Enum\Tests\Fields; | ||
|
||
use BenSampo\Enum\Rules\EnumValue; | ||
use SimpleSquid\Nova\Fields\Enum\Enum; | ||
use SimpleSquid\Nova\Fields\Enum\Tests\Examples\IntegerEnum; | ||
use SimpleSquid\Nova\Fields\Enum\Tests\TestCase; | ||
|
||
class FieldTest extends TestCase | ||
{ | ||
private $field; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->setUpDatabase($this->app); | ||
|
||
$this->field = Enum::make('Enum')->attach(IntegerEnum::class); | ||
} | ||
|
||
/** @test */ | ||
public function it_starts_with_no_options_and_rules() | ||
{ | ||
$field = Enum::make('Enum'); | ||
|
||
$this->assertArrayNotHasKey('options', $field->meta); | ||
|
||
$this->assertEmpty($field->rules); | ||
} | ||
|
||
/** @test */ | ||
public function it_allows_an_enum_to_be_attached() | ||
{ | ||
$this->assertArrayHasKey('options', $this->field->meta); | ||
} | ||
|
||
/** @test */ | ||
public function it_adds_correct_rules() | ||
{ | ||
$this->assertContains('required', $this->field->rules); | ||
|
||
$this->assertContainsEquals(new EnumValue(IntegerEnum::class, false), $this->field->rules); | ||
} | ||
|
||
/** @test */ | ||
public function it_displays_enum_options() | ||
{ | ||
$this->assertCount(count(IntegerEnum::getValues()), $this->field->meta['options']); | ||
|
||
foreach (IntegerEnum::getValues() as $enum) { | ||
$this->assertContains([ | ||
'label' => IntegerEnum::getDescription($enum), | ||
'value' => $enum | ||
], $this->field->meta['options']); | ||
} | ||
} | ||
} |
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,60 @@ | ||
<?php | ||
|
||
namespace SimpleSquid\Nova\Fields\Enum\Tests\Fields; | ||
|
||
use Laravel\Nova\Http\Requests\NovaRequest; | ||
use SimpleSquid\Nova\Fields\Enum\Enum; | ||
use SimpleSquid\Nova\Fields\Enum\Tests\Examples\IntegerEnum; | ||
use SimpleSquid\Nova\Fields\Enum\Tests\Examples\IntegerModel; | ||
use SimpleSquid\Nova\Fields\Enum\Tests\TestCase; | ||
|
||
class IntegerFieldTest extends TestCase | ||
{ | ||
private $field; | ||
|
||
private $model; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->setUpDatabase($this->app); | ||
|
||
$this->field = Enum::make('Enum')->attach(IntegerEnum::class); | ||
|
||
$this->model = IntegerModel::create(['enum' => IntegerEnum::Moderator]); | ||
} | ||
|
||
/** @test */ | ||
public function it_resolves_enum_value() | ||
{ | ||
$this->field->resolve($this->model); | ||
|
||
$this->assertSame(IntegerEnum::Moderator, $this->field->value); | ||
} | ||
|
||
/** @test */ | ||
public function it_displays_enum_description() | ||
{ | ||
$this->field->resolveForDisplay($this->model); | ||
|
||
$this->assertSame(IntegerEnum::Moderator()->description, $this->field->value); | ||
} | ||
|
||
/** @test */ | ||
public function it_fills_database_with_enum_value() | ||
{ | ||
$request = new NovaRequest(); | ||
$request->query->add(['enum' => IntegerEnum::Subscriber]); | ||
|
||
$this->field->fill($request, $this->model); | ||
|
||
$this->assertDatabaseHas('example_models', ['enum' => IntegerEnum::Moderator]); | ||
|
||
$this->model->save(); | ||
|
||
$this->assertDatabaseHas('example_models', ['enum' => IntegerEnum::Subscriber]); | ||
|
||
$this->assertDatabaseMissing('example_models', ['enum' => IntegerEnum::Moderator]); | ||
} | ||
} |
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,60 @@ | ||
<?php | ||
|
||
namespace SimpleSquid\Nova\Fields\Enum\Tests\Fields; | ||
|
||
use Laravel\Nova\Http\Requests\NovaRequest; | ||
use SimpleSquid\Nova\Fields\Enum\Enum; | ||
use SimpleSquid\Nova\Fields\Enum\Tests\Examples\StringEnum; | ||
use SimpleSquid\Nova\Fields\Enum\Tests\Examples\StringModel; | ||
use SimpleSquid\Nova\Fields\Enum\Tests\TestCase; | ||
|
||
class StringFieldTest extends TestCase | ||
{ | ||
private $field; | ||
|
||
private $model; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->setUpDatabase($this->app, 'string'); | ||
|
||
$this->field = Enum::make('Enum')->attach(StringEnum::class); | ||
|
||
$this->model = StringModel::create(['enum' => StringEnum::Moderator]); | ||
} | ||
|
||
/** @test */ | ||
public function it_resolves_enum_value() | ||
{ | ||
$this->field->resolve($this->model); | ||
|
||
$this->assertSame(StringEnum::Moderator, $this->field->value); | ||
} | ||
|
||
/** @test */ | ||
public function it_displays_enum_description() | ||
{ | ||
$this->field->resolveForDisplay($this->model); | ||
|
||
$this->assertSame(StringEnum::Moderator()->description, $this->field->value); | ||
} | ||
|
||
/** @test */ | ||
public function it_fills_database_with_enum_value() | ||
{ | ||
$request = new NovaRequest(); | ||
$request->query->add(['enum' => StringEnum::Subscriber]); | ||
|
||
$this->field->fill($request, $this->model); | ||
|
||
$this->assertDatabaseHas('example_models', ['enum' => StringEnum::Moderator]); | ||
|
||
$this->model->save(); | ||
|
||
$this->assertDatabaseHas('example_models', ['enum' => StringEnum::Subscriber]); | ||
|
||
$this->assertDatabaseMissing('example_models', ['enum' => StringEnum::Moderator]); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.