-
Notifications
You must be signed in to change notification settings - Fork 388
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
1 parent
d2ad394
commit bdb8680
Showing
2 changed files
with
102 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
use Lunar\Admin\Support\Synthesizers\ListSynth; | ||
use Lunar\FieldTypes\ListField; | ||
|
||
uses(\Lunar\Tests\Admin\Unit\Livewire\TestCase::class) | ||
->group('support.synthesizers'); | ||
|
||
describe('list field synthesizer', function () { | ||
beforeEach(function () { | ||
$this->listSynth = Mockery::mock(ListSynth::class)->makePartial(); | ||
$this->listField = Mockery::mock(ListField::class)->makePartial(); | ||
}); | ||
|
||
test('sets a value in the list field', function () { | ||
$key = 'item1'; | ||
$value = 'Test Value'; | ||
|
||
$this->listSynth->set($this->listField, $key, $value); | ||
|
||
$result = $this->listField->getValue(); | ||
|
||
expect($result)->toBeObject() | ||
->and($result)->toHaveKey($key, $value); | ||
}); | ||
|
||
test('unsets a value from the list field', function () { | ||
$key = 'item1'; | ||
$value = 'Test Value'; | ||
|
||
$this->listField->setValue([$key => $value]); | ||
|
||
$this->listSynth->unset($this->listField, $key); | ||
|
||
$result = $this->listField->getValue(); | ||
|
||
expect($result)->toBeArray() | ||
->and($result)->not->toHaveKey($key); | ||
}); | ||
|
||
test('gets values from the list field', function () { | ||
$key = 'item1'; | ||
$value = 'Test Value'; | ||
$this->listField->setValue([$key => $value]); | ||
|
||
$result = $this->listSynth->get($this->listField, $key); | ||
|
||
expect($result)->toBeArray() | ||
->and($result)->toEqual((array) $this->listField->getValue()); | ||
}); | ||
|
||
test('dehydrates the list field correctly', function () { | ||
$this->listField->setValue(['item1' => 'Test Value']); | ||
|
||
$result = $this->listSynth->dehydrate($this->listField)[0]; | ||
|
||
expect($result)->toEqual($this->listField->getValue()); | ||
}); | ||
|
||
test('handles empty keys and values', function () { | ||
$key = ''; | ||
$value = ''; | ||
|
||
$this->listSynth->set($this->listField, $key, $value); | ||
|
||
$result = $this->listField->getValue(); | ||
|
||
expect($result)->toBeObject() | ||
->and($result)->toHaveKey($key, $value); | ||
|
||
$this->listSynth->unset($this->listField, $key); | ||
|
||
$result = $this->listField->getValue(); | ||
|
||
expect($result)->toBeArray() | ||
->and($result)->not->toHaveKey($key); | ||
}); | ||
|
||
test('handles keys and values with dot notation', function () { | ||
$key = 'key.with.dots'; | ||
$value = 'Dot.Notation.Value'; | ||
|
||
$this->listSynth->set($this->listField, $key, $value); | ||
|
||
$result = $this->listField->getValue(); | ||
|
||
expect($result)->toBeObject() | ||
->and($result)->toHaveKey($key, $value); | ||
|
||
$this->listSynth->unset($this->listField, $key); | ||
|
||
$result = $this->listField->getValue(); | ||
|
||
expect($result)->toBeArray() | ||
->and($result)->not->toHaveKey($key); | ||
}); | ||
}); |