|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Yajra\DataTables\Html\Tests\Html\Editor\Fields; |
| 4 | + |
| 5 | +use PHPUnit\Framework\Attributes\Test; |
| 6 | +use PHPUnit\Framework\TestCase; |
| 7 | +use Yajra\DataTables\Html\Editor\Fields\Tags; |
| 8 | + |
| 9 | +class TagsTest extends TestCase |
| 10 | +{ |
| 11 | + #[Test] |
| 12 | + public function it_can_set_tags_ajax(): void |
| 13 | + { |
| 14 | + $field = new Tags; |
| 15 | + $field->ajax('/tags'); |
| 16 | + |
| 17 | + $this->assertSame('/tags', $field->toArray()['ajax']); |
| 18 | + } |
| 19 | + |
| 20 | + #[Test] |
| 21 | + public function it_can_set_tags_display(): void |
| 22 | + { |
| 23 | + $field = new Tags; |
| 24 | + $field->display('display'); |
| 25 | + |
| 26 | + $this->assertSame('display', $field->toArray()['display']); |
| 27 | + } |
| 28 | + |
| 29 | + #[Test] |
| 30 | + public function it_can_set_tags_escape_label_html(): void |
| 31 | + { |
| 32 | + $field = new Tags; |
| 33 | + $field->escapeLabelHtml(true); |
| 34 | + |
| 35 | + $this->assertTrue($field->toArray()['escapeLabelHtml']); |
| 36 | + } |
| 37 | + |
| 38 | + #[Test] |
| 39 | + public function it_can_set_tags_i18n(): void |
| 40 | + { |
| 41 | + $field = new Tags; |
| 42 | + $field->i18n([ |
| 43 | + 'addButton' => 'Add', |
| 44 | + 'inputPlaceholder' => 'Input', |
| 45 | + 'noResults' => 'No Results', |
| 46 | + 'title' => 'Title', |
| 47 | + 'placeholder' => 'Placeholder', |
| 48 | + ]); |
| 49 | + |
| 50 | + $this->assertSame('Add', $field->toArray()['i18n']['addButton']); |
| 51 | + $this->assertSame('Input', $field->toArray()['i18n']['inputPlaceholder']); |
| 52 | + $this->assertSame('No Results', $field->toArray()['i18n']['noResults']); |
| 53 | + $this->assertSame('Title', $field->toArray()['i18n']['title']); |
| 54 | + $this->assertSame('Placeholder', $field->toArray()['i18n']['placeholder']); |
| 55 | + |
| 56 | + $field->addButton('Add Button') |
| 57 | + ->inputPlaceholder('Input Placeholder') |
| 58 | + ->noResults('No Results X') |
| 59 | + ->title('Title X') |
| 60 | + ->placeholder('Placeholder X'); |
| 61 | + |
| 62 | + $this->assertSame('Add Button', $field->toArray()['i18n']['addButton']); |
| 63 | + $this->assertSame('Input Placeholder', $field->toArray()['i18n']['inputPlaceholder']); |
| 64 | + $this->assertSame('No Results X', $field->toArray()['i18n']['noResults']); |
| 65 | + $this->assertSame('Title X', $field->toArray()['i18n']['title']); |
| 66 | + $this->assertSame('Placeholder X', $field->toArray()['i18n']['placeholder']); |
| 67 | + } |
| 68 | + |
| 69 | + #[Test] |
| 70 | + public function it_can_set_tags_type(): void |
| 71 | + { |
| 72 | + $field = new Tags; |
| 73 | + |
| 74 | + $this->assertSame('tags', $field->toArray()['type']); |
| 75 | + } |
| 76 | + |
| 77 | + #[Test] |
| 78 | + public function it_can_set_tags_limit(): void |
| 79 | + { |
| 80 | + $field = new Tags; |
| 81 | + $field->limit(2); |
| 82 | + |
| 83 | + $this->assertSame(2, $field->toArray()['limit']); |
| 84 | + } |
| 85 | + |
| 86 | + #[Test] |
| 87 | + public function it_can_set_tags_multiple(): void |
| 88 | + { |
| 89 | + $field = new Tags; |
| 90 | + $field->multiple(); |
| 91 | + |
| 92 | + $this->assertTrue($field->toArray()['multiple']); |
| 93 | + } |
| 94 | + |
| 95 | + #[Test] |
| 96 | + public function it_can_set_tags_options(): void |
| 97 | + { |
| 98 | + $field = new Tags; |
| 99 | + $field->options(['tag1', 'tag2']); |
| 100 | + |
| 101 | + $this->assertSame(['tag1', 'tag2'], $field->toArray()['options']); |
| 102 | + |
| 103 | + $field->options([ |
| 104 | + ['value' => 'tag1', 'label' => 'Tag 1'], |
| 105 | + ['value' => 'tag2', 'label' => 'Tag 2'], |
| 106 | + ]); |
| 107 | + |
| 108 | + $this->assertSame([ |
| 109 | + ['value' => 'tag1', 'label' => 'Tag 1'], |
| 110 | + ['value' => 'tag2', 'label' => 'Tag 2'], |
| 111 | + ], $field->toArray()['options']); |
| 112 | + } |
| 113 | + |
| 114 | + #[Test] |
| 115 | + public function it_can_set_tags_separator(): void |
| 116 | + { |
| 117 | + $field = new Tags; |
| 118 | + $field->separator(','); |
| 119 | + |
| 120 | + $this->assertSame(',', $field->toArray()['separator']); |
| 121 | + } |
| 122 | + |
| 123 | + #[Test] |
| 124 | + public function it_can_set_tags_unique(): void |
| 125 | + { |
| 126 | + $field = new Tags; |
| 127 | + $field->unique(); |
| 128 | + |
| 129 | + $this->assertTrue($field->toArray()['unique']); |
| 130 | + } |
| 131 | +} |
0 commit comments