|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Yajra\DataTables\Html\Tests; |
| 4 | + |
| 5 | +use Illuminate\Foundation\Testing\DatabaseTransactions; |
| 6 | +use Illuminate\Support\Facades\DB; |
| 7 | +use Yajra\DataTables\Html\Editor\Fields\Options; |
| 8 | +use Yajra\DataTables\Html\Tests\Models\User; |
| 9 | + |
| 10 | +class FieldOptionsTest extends TestCase |
| 11 | +{ |
| 12 | + use DatabaseTransactions; |
| 13 | + |
| 14 | + /** @test */ |
| 15 | + public function it_has_true_false() |
| 16 | + { |
| 17 | + $options = Options::trueFalse(); |
| 18 | + |
| 19 | + $this->assertEquals([ |
| 20 | + ['label' => __('True'), 'value' => 1], |
| 21 | + ['label' => __('False'), 'value' => 0], |
| 22 | + ], $options->toArray()); |
| 23 | + } |
| 24 | + |
| 25 | + /** @test */ |
| 26 | + public function it_has_yes_no() |
| 27 | + { |
| 28 | + $options = Options::yesNo(); |
| 29 | + |
| 30 | + $this->assertEquals([ |
| 31 | + ['label' => __('Yes'), 'value' => 1], |
| 32 | + ['label' => __('No'), 'value' => 0], |
| 33 | + ], $options->toArray()); |
| 34 | + } |
| 35 | + |
| 36 | + /** @test */ |
| 37 | + public function it_can_append_and_prepend() |
| 38 | + { |
| 39 | + $options = Options::yesNo(); |
| 40 | + |
| 41 | + $this->assertEquals([ |
| 42 | + ['label' => __('Yes'), 'value' => 1], |
| 43 | + ['label' => __('No'), 'value' => 0], |
| 44 | + ], $options->toArray()); |
| 45 | + |
| 46 | + $options->append(__('Maybe'), 2); |
| 47 | + $this->assertEquals([ |
| 48 | + ['label' => __('Yes'), 'value' => 1], |
| 49 | + ['label' => __('No'), 'value' => 0], |
| 50 | + ['label' => __('Maybe'), 'value' => 2], |
| 51 | + ], $options->toArray()); |
| 52 | + |
| 53 | + $options->prepend(__('IDK'), 3); |
| 54 | + $this->assertEquals([ |
| 55 | + ['label' => __('IDK'), 'value' => 3], |
| 56 | + ['label' => __('Yes'), 'value' => 1], |
| 57 | + ['label' => __('No'), 'value' => 0], |
| 58 | + ['label' => __('Maybe'), 'value' => 2], |
| 59 | + ], $options->toArray()); |
| 60 | + } |
| 61 | + |
| 62 | + /** @test */ |
| 63 | + public function it_can_get_options_from_table() |
| 64 | + { |
| 65 | + $options = Options::table('users', 'name'); |
| 66 | + $this->assertCount(20, $options); |
| 67 | + } |
| 68 | + |
| 69 | + /** @test */ |
| 70 | + public function it_can_get_options_from_query() |
| 71 | + { |
| 72 | + $options = Options::table(DB::table('users')->where('id', 1), 'name'); |
| 73 | + $this->assertCount(1, $options); |
| 74 | + } |
| 75 | + |
| 76 | + /** @test */ |
| 77 | + public function it_can_get_options_from_model() |
| 78 | + { |
| 79 | + $options = Options::model(User::class, 'name'); |
| 80 | + $this->assertCount(20, $options); |
| 81 | + } |
| 82 | + |
| 83 | + /** @test */ |
| 84 | + public function it_can_get_options_from_model_builder() |
| 85 | + { |
| 86 | + $options = Options::model(User::query()->whereKey(1), 'name'); |
| 87 | + $this->assertCount(1, $options); |
| 88 | + } |
| 89 | +} |
0 commit comments