-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
9 changed files
with
182 additions
and
32 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
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,43 @@ | ||
<?php | ||
namespace Pelmered\FilamentMoneyField\Tests\Components; | ||
|
||
|
||
use Filament\Forms\Concerns\InteractsWithForms; | ||
use Filament\Forms\Contracts\HasForms; | ||
use Filament\Infolists\Concerns\InteractsWithInfolists; | ||
use Filament\Infolists\Contracts\HasInfolists; | ||
use Filament\Infolists\Infolist; | ||
use Livewire\Component; | ||
use Filament\Forms\Form; | ||
use Pelmered\FilamentMoneyField\Forms\Components\MoneyInput; | ||
use Pelmered\FilamentMoneyField\Infolists\Components\MoneyEntry; | ||
|
||
class InfolistTestComponent extends Component implements HasForms, HasInfolists | ||
{ | ||
use InteractsWithForms; | ||
use InteractsWithInfolists; | ||
|
||
public static function make(): static | ||
{ | ||
return new static(); | ||
} | ||
|
||
public function infolist(Infolist $infolist): Infolist | ||
{ | ||
return $infolist | ||
->state([]) | ||
->schema([ | ||
MoneyEntry::make('amount') | ||
->currency('SEK') | ||
->locale('sv_SE') | ||
->label('Amount'), | ||
]); | ||
} | ||
|
||
/* | ||
public function render(): View | ||
{ | ||
return view('infolists.fixtures.actions'); | ||
} | ||
*/ | ||
} |
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,24 @@ | ||
<?php | ||
namespace Pelmered\FilamentMoneyField\Tests\Database\Factories; | ||
|
||
use Pelmered\FilamentMoneyField\Tests\Models\Post; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
class PostFactory extends Factory | ||
{ | ||
protected $model = Post::class; | ||
|
||
public function definition(): array | ||
{ | ||
return [ | ||
'author_id' => random_int(1, 10), | ||
'content' => $this->faker->paragraph(), | ||
'is_published' => $this->faker->boolean(), | ||
'tags' => $this->faker->words(), | ||
'title' => $this->faker->sentence(), | ||
'rating' => $this->faker->numberBetween(1, 10), | ||
'price' => $this->faker->numberBetween(100, 10000), | ||
]; | ||
} | ||
} | ||
|
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,33 @@ | ||
<?php | ||
namespace Pelmered\FilamentMoneyField\Tests\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
use Illuminate\Database\Eloquent\SoftDeletes; | ||
use Pelmered\FilamentMoneyField\Tests\Database\Factories\PostFactory; | ||
|
||
class Post extends Model | ||
{ | ||
use HasFactory; | ||
use SoftDeletes; | ||
|
||
protected $casts = [ | ||
'is_published' => 'boolean', | ||
'tags' => 'array', | ||
]; | ||
|
||
protected $guarded = []; | ||
|
||
/* | ||
public function author(): BelongsTo | ||
{ | ||
return $this->belongsTo(User::class, 'author_id'); | ||
} | ||
*/ | ||
|
||
protected static function newFactory() | ||
{ | ||
return PostFactory::new(); | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
namespace Pelmered\FilamentMoneyField\Tests; | ||
|
||
use Filament\Forms\Components\Field; | ||
use Mockery\MockInterface; | ||
use Pelmered\FilamentMoneyField\Forms\Components\MoneyInput; | ||
use Filament\Forms\ComponentContainer; | ||
use Illuminate\Support\Str; | ||
use Pelmered\FilamentMoneyField\Forms\Rules\MaxValueRule; | ||
use Pelmered\FilamentMoneyField\Forms\Rules\MaxValueRule2; | ||
use Pelmered\FilamentMoneyField\Forms\Rules\MinValueRule; | ||
use Pelmered\FilamentMoneyField\Tests\Components\FormTestComponent; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\MockObject\Exception; | ||
use Livewire\Livewire; | ||
use Illuminate\Validation\ValidationException; | ||
|
||
#[CoversClass(MoneyInput::class)] | ||
class ValidationRulesTest extends TestCase | ||
{ | ||
public function testMinValueRule() | ||
{ | ||
$rule = new MinValueRule(10000, new MoneyInput('totalAmount')); | ||
|
||
$rule->validate('totalAmount', 16, function ($message) { | ||
$this->assertEquals('The Total Amount must be at least 100.00.', $message); | ||
}); | ||
} | ||
} |