diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 8ff98cc..49f05ab 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -1,23 +1,25 @@ -name: "Continuous Integration" +name: Continuous Integration on: push: + branches: + - master + - '*.x' pull_request: schedule: - cron: '0 0 * * *' jobs: - phpunit: - + tests: runs-on: ubuntu-latest strategy: fail-fast: true matrix: - php: [8.2, 8.3] + php: [8.2, 8.3, 8.4] stability: [prefer-stable] - name: PHP ${{ matrix.php }} - ${{ matrix.stability }} + name: PHP ${{ matrix.php }} - STABILITY ${{ matrix.stability }} steps: - name: Checkout code @@ -27,7 +29,6 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, memcached tools: composer:v2 coverage: none @@ -39,7 +40,7 @@ jobs: with: timeout_minutes: 5 max_attempts: 5 - command: COMPOSER_ROOT_VERSION=dev-master composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress + command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress - name: Execute tests run: vendor/bin/phpunit diff --git a/.github/workflows/pint.yml b/.github/workflows/pint.yml index f078347..c07577f 100644 --- a/.github/workflows/pint.yml +++ b/.github/workflows/pint.yml @@ -1,20 +1,33 @@ name: PHP Linting + on: pull_request: push: branches: - master + - '*.x' + jobs: - phplint: + pint: + name: Pint + runs-on: ubuntu-latest + + permissions: + contents: write + pull-requests: write + steps: - uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + - name: "laravel-pint" - uses: aglipanci/laravel-pint-action@2.0.0 + uses: aglipanci/laravel-pint-action@latest with: preset: laravel verboseMode: true + - uses: stefanzweifel/git-auto-commit-action@v5 with: - commit_message: "fix: pint" - + commit_message: "fix: pint :robot:" diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 8e9365d..4dccad0 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -1,21 +1,12 @@ -name: "Static Analysis" +name: Static Analysis on: push: - paths: - - .github/workflows/static-analysis.yml - - composer.* - - phpstan.neon.dist - - src/** - - tests/** + branches: + - master + - '*.x' pull_request: - paths: - - .github/workflows/static-analysis.yml - - composer.* - - phpstan.neon.dist - - src/** - - tests/** schedule: - cron: '0 0 * * *' @@ -23,32 +14,26 @@ on: jobs: static-analysis-phpstan: - name: "Static Analysis with PHPStan" + name: Source Code runs-on: ubuntu-latest - strategy: - fail-fast: true - matrix: - php: [8.2, 8.3] - stability: [prefer-stable] - steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: ${{ matrix.php }} + php-version: 8.2 tools: composer:v2 coverage: none - name: Install dependencies - uses: nick-invision/retry@v1 + uses: nick-fields/retry@v3 with: timeout_minutes: 5 max_attempts: 5 - command: COMPOSER_ROOT_VERSION=dev-master composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress + command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress - - name: "Run a static analysis with phpstan/phpstan" - run: "vendor/bin/phpstan --error-format=table" + - name: Run Static Analysis + run: vendor/bin/phpstan diff --git a/CHANGELOG.md b/CHANGELOG.md index aa08be9..04d08aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,42 +4,15 @@ ### UNRELEASED -### v11.6.0 (2024-08-31) +### v12.0.2 (2025-04-28) -- feat: add macro in editor builder #225 +- fix: use DOMContentLoaded #237 +- fix: https://github.com/yajra/laravel-datatables-html/pull/235 -### v11.5.1 (2024-08-31) +### v12.0.1 (2025-03-31) -- fix: unauthorized columns being displayed by builder #223 -- fix: #222 +- feat: select keyboard navigation and selection #236 -### v11.5.0 (2024-08-31) +### v12.0.0 (2025-02-26) -- feat: enable macro on Button builder #224 - -### v11.4.0 (2024-05-31) - -- feat: add className method to Editor Field #220 - -### v11.3.0 (2024-05-18) - -- feat: Allow passing view and livewire components to layout builder #219 - -### v11.2.1 (2024-04-29) - -- fix: multiple config option of select2 #218 - -### v11.2.0 (2024-04-24) - -- feat: load layout from view using selector #217 - -### v11.1.0 (2024-04-24) - -- feat: layout builder #216 -- https://datatables.net/reference/option/layout - -### v11.0.0 (2024-03-14) - -- Add support for Laravel 11.x -- Fix editor scope compatibility with Fluent class scope -- Rename Editor `scope` method to `formScope` +- feat: Laravel 12 support #234 diff --git a/README.md b/README.md index a8ac86c..9103975 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Laravel DataTables Html Plugin -[![Laravel 11.x](https://img.shields.io/badge/Laravel-11.x-orange.svg)](http://laravel.com) +[![Laravel 12.x](https://img.shields.io/badge/Laravel-12.x-orange.svg)](http://laravel.com) [![Latest Stable Version](https://img.shields.io/packagist/v/yajra/laravel-datatables-html.svg)](https://packagist.org/packages/yajra/laravel-datatables-html) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yajra/laravel-datatables-html/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yajra/laravel-datatables-html/?branch=master) [![Total Downloads](https://img.shields.io/packagist/dt/yajra/laravel-datatables-html.svg)](https://packagist.org/packages/yajra/laravel-datatables-html) @@ -14,7 +14,7 @@ This package is a plugin of [Laravel DataTables](https://github.com/yajra/larave ## Requirements -- [Laravel 11.x](https://github.com/laravel/framework) +- [Laravel 12.x](https://github.com/laravel/framework) - [Laravel DataTables](https://github.com/yajra/laravel-datatables) ## Documentations @@ -29,10 +29,11 @@ This package is a plugin of [Laravel DataTables](https://github.com/yajra/larave | 9.x | 9.x | | 10.x | 10.x | | 11.x | 11.x | +| 12.x | 12.x | ## Quick Installation -`composer require yajra/laravel-datatables-html:^11` +`composer require yajra/laravel-datatables-html:^12` #### Setup scripts with ViteJS diff --git a/composer.json b/composer.json index 3182b14..784ffcb 100644 --- a/composer.json +++ b/composer.json @@ -19,13 +19,13 @@ "require": { "php": "^8.2", "ext-json": "*", - "yajra/laravel-datatables-oracle": "^11.0" + "yajra/laravel-datatables-oracle": "^12.0" }, "require-dev": { - "larastan/larastan": "^2.9.1", - "orchestra/testbench": "^9", - "laravel/pint": "^1.14", - "rector/rector": "^1.0", + "larastan/larastan": "^3.1", + "orchestra/testbench": "^10", + "laravel/pint": "^1.21", + "rector/rector": "^2.0", "livewire/livewire": "^3.4" }, "suggest": { @@ -43,7 +43,7 @@ }, "extra": { "branch-alias": { - "dev-master": "11.0-dev" + "dev-master": "12.x-dev" }, "laravel": { "providers": [ diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 08605d3..23d24cc 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -10,9 +10,11 @@ parameters: ignoreErrors: - '#Unsafe usage of new static\(\).#' + - identifier: missingType.generics + - identifier: missingType.iterableValue + - identifier: binaryOp.invalid + - identifier: return.type + - identifier: argument.type excludePaths: - - checkMissingIterableValueType: false - - checkGenericClassInNonGenericObjectType: false + - ./src/Html/Fluent.php diff --git a/src/Html/Button.php b/src/Html/Button.php index 7a0c2fe..0823962 100755 --- a/src/Html/Button.php +++ b/src/Html/Button.php @@ -2,8 +2,8 @@ namespace Yajra\DataTables\Html; +use Closure; use Illuminate\Contracts\Support\Arrayable; -use Illuminate\Support\Fluent; use Illuminate\Support\Traits\Macroable; class Button extends Fluent implements Arrayable @@ -271,10 +271,12 @@ public function addClass(string $class): static { if (! isset($this->attributes['className'])) { $this->attributes['className'] = $class; - } else { - $this->attributes['className'] .= " $class"; + + return $this; } + $this->attributes['className'] = $this->attributes['className']." $class"; + return $this; } @@ -429,4 +431,32 @@ public function align(string $align = 'button-left'): static return $this; } + + /** + * Handle dynamic calls to the fluent instance or macroable methods. + * + * @param string $method + * @param array $parameters + * @return mixed + * + * @throws \BadMethodCallException + */ + public function __call($method, $parameters) + { + // Check if the method is a macro (Macroable functionality). + if (static::hasMacro($method)) { + $macro = static::$macros[$method]; + + if ($macro instanceof Closure) { + $macro = $macro->bindTo($this, static::class); + } + + return $macro(...$parameters); + } + + // Fallback to Fluent behavior if it's not a macro. + $this->attributes[$method] = count($parameters) > 0 ? reset($parameters) : true; + + return $this; + } } diff --git a/src/Html/Column.php b/src/Html/Column.php index d57a304..fcebc04 100644 --- a/src/Html/Column.php +++ b/src/Html/Column.php @@ -3,7 +3,6 @@ namespace Yajra\DataTables\Html; use Illuminate\Support\Arr; -use Illuminate\Support\Fluent; use Illuminate\Support\Str; use Yajra\DataTables\Html\Options\Plugins\SearchPanes; @@ -29,6 +28,7 @@ * @property string $contentPadding * @property string $createdCell * @property string $exportFormat + * @property callable $exportRender * * @see https://datatables.net/reference/option/#columns */ @@ -503,7 +503,7 @@ public function parseRender(mixed $value): ?string return $value($parameters); } elseif ($this->isBuiltInRenderFunction($value)) { return $value; - } elseif (strlen((string) $value) < 256 && $view->exists($value)) { + } elseif (is_string($value) && strlen($value) < 256 && $view->exists($value)) { return $view->make($value)->with($parameters)->render(); } diff --git a/src/Html/Editor/Editor.php b/src/Html/Editor/Editor.php index 15d63fc..4e9b4b8 100644 --- a/src/Html/Editor/Editor.php +++ b/src/Html/Editor/Editor.php @@ -3,10 +3,10 @@ namespace Yajra\DataTables\Html\Editor; use Illuminate\Support\Arr; -use Illuminate\Support\Fluent; use Illuminate\Support\Str; use Illuminate\Support\Traits\Macroable; use Yajra\DataTables\Html\Editor\Fields\Field; +use Yajra\DataTables\Html\Fluent; use Yajra\DataTables\Html\HasAuthorizations; use Yajra\DataTables\Utilities\Helper; diff --git a/src/Html/Editor/Fields/Field.php b/src/Html/Editor/Fields/Field.php index 56f277f..f3c737a 100644 --- a/src/Html/Editor/Fields/Field.php +++ b/src/Html/Editor/Fields/Field.php @@ -6,9 +6,9 @@ use Illuminate\Contracts\Support\Arrayable; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Query\Builder as QueryBuilder; -use Illuminate\Support\Fluent; use Illuminate\Support\Str; use Illuminate\Support\Traits\Macroable; +use Yajra\DataTables\Html\Fluent; use Yajra\DataTables\Html\HasAuthorizations; /** diff --git a/src/Html/Editor/Fields/Tags.php b/src/Html/Editor/Fields/Tags.php new file mode 100644 index 0000000..2b910be --- /dev/null +++ b/src/Html/Editor/Fields/Tags.php @@ -0,0 +1,143 @@ +attributes['ajax'] = $url; + + return $this; + } + + /** + * @see https://editor.datatables.net/reference/field/tags#display + */ + public function display(string $display): static + { + $this->attributes['display'] = $display; + + return $this; + } + + /** + * @see https://editor.datatables.net/reference/field/tags#escapeLabelHtml + */ + public function escapeLabelHtml(bool $escape): static + { + $this->attributes['escapeLabelHtml'] = $escape; + + return $this; + } + + /** + * @see https://editor.datatables.net/reference/field/tags#i18n + */ + public function i18n(array $i18n): static + { + $options = isset($this->attributes['i18n']) + ? (array) $this->attributes['i18n'] + : []; + + $this->attributes['i18n'] = array_merge($options, $i18n); + + return $this; + } + + /** + * @see https://editor.datatables.net/reference/field/tags#i18n + */ + public function addButton(string $text): static + { + return $this->i18n(['addButton' => $text]); + } + + /** + * @see https://editor.datatables.net/reference/field/tags#i18n + */ + public function inputPlaceholder(string $text): static + { + return $this->i18n(['inputPlaceholder' => $text]); + } + + /** + * @see https://editor.datatables.net/reference/field/tags#i18n + */ + public function noResults(string $text): static + { + return $this->i18n(['noResults' => $text]); + } + + /** + * @see https://editor.datatables.net/reference/field/tags#i18n + */ + public function title(string $text): static + { + return $this->i18n(['title' => $text]); + } + + /** + * @see https://editor.datatables.net/reference/field/tags#i18n + */ + public function placeholder(string $text): static + { + return $this->i18n(['placeholder' => $text]); + } + + /** + * @see https://editor.datatables.net/reference/field/tags#limit + */ + public function limit(int $limit): static + { + $this->attributes['limit'] = $limit; + + return $this; + } + + /** + * @see https://editor.datatables.net/reference/field/tags#multiple + */ + public function multiple(bool $multiple = true): static + { + $this->attributes['multiple'] = $multiple; + + return $this; + } + + /** + * @see https://editor.datatables.net/reference/field/tags#options + */ + public function options(array|Arrayable $options): static + { + return parent::options($options); + } + + /** + * @see https://editor.datatables.net/reference/field/tags#separator + */ + public function separator(string $separator = ','): static + { + return parent::separator($separator); + } + + /** + * @see https://editor.datatables.net/reference/field/tags#unique + */ + public function unique(bool $unique = true): static + { + $this->attributes['unique'] = $unique; + + return $this; + } +} diff --git a/src/Html/Editor/FormOptions.php b/src/Html/Editor/FormOptions.php index a849ff6..03c149c 100644 --- a/src/Html/Editor/FormOptions.php +++ b/src/Html/Editor/FormOptions.php @@ -2,7 +2,7 @@ namespace Yajra\DataTables\Html\Editor; -use Illuminate\Support\Fluent; +use Yajra\DataTables\Html\Fluent; /** * @see https://editor.datatables.net/reference/type/form-options diff --git a/src/Html/Fluent.php b/src/Html/Fluent.php new file mode 100644 index 0000000..2ff5837 --- /dev/null +++ b/src/Html/Fluent.php @@ -0,0 +1,235 @@ + + * @implements \ArrayAccess + */ +class Fluent implements Arrayable, ArrayAccess, Jsonable, JsonSerializable +{ + /** + * All of the attributes set on the fluent instance. + * + * @var array + */ + protected $attributes = []; + + /** + * Create a new fluent instance. + * + * @param iterable $attributes + * @return void + */ + public function __construct($attributes = []) + { + foreach ($attributes as $key => $value) { + $this->attributes[$key] = $value; + } + } + + /** + * Get an attribute from the fluent instance using "dot" notation. + * + * @template TGetDefault + * + * @param TKey $key + * @param TGetDefault|(\Closure(): TGetDefault) $default + * @return TValue|TGetDefault + */ + public function get($key, $default = null) + { + return data_get($this->attributes, $key, $default); + } + + /** + * Get an attribute from the fluent instance. + * + * @param string $key + * @param mixed $default + * @return mixed + */ + public function value($key, $default = null) + { + if (array_key_exists($key, $this->attributes)) { + return $this->attributes[$key]; + } + + return value($default); + } + + /** + * Get the value of the given key as a new Fluent instance. + * + * @param string $key + * @param mixed $default + * @return static + */ + public function scope($key, $default = null) + { + return new static( + (array) $this->get($key, $default) + ); + } + + /** + * Get the attributes from the fluent instance. + * + * @return array + */ + public function getAttributes() + { + return $this->attributes; + } + + /** + * Convert the fluent instance to an array. + * + * @return array + */ + public function toArray() + { + return $this->attributes; + } + + /** + * Convert the fluent instance to a Collection. + * + * @param string|null $key + * @return \Illuminate\Support\Collection + */ + public function collect($key = null) + { + return new Collection($this->get($key)); + } + + /** + * Convert the object into something JSON serializable. + * + * @return array + */ + public function jsonSerialize(): array + { + return $this->toArray(); + } + + /** + * Convert the fluent instance to JSON. + * + * @param int $options + * @return string + */ + public function toJson($options = 0) + { + return json_encode($this->jsonSerialize(), $options); + } + + /** + * Determine if the given offset exists. + * + * @param TKey $offset + */ + public function offsetExists($offset): bool + { + return isset($this->attributes[$offset]); + } + + /** + * Get the value for a given offset. + * + * @param TKey $offset + * @return TValue|null + */ + public function offsetGet($offset): mixed + { + return $this->value($offset); + } + + /** + * Set the value at the given offset. + * + * @param TKey $offset + * @param TValue $value + */ + public function offsetSet($offset, $value): void + { + $this->attributes[$offset] = $value; + } + + /** + * Unset the value at the given offset. + * + * @param TKey $offset + */ + public function offsetUnset($offset): void + { + unset($this->attributes[$offset]); + } + + /** + * Handle dynamic calls to the fluent instance to set attributes. + * + * @param TKey $method + * @param array{0: ?TValue} $parameters + * @return $this + */ + public function __call($method, $parameters) + { + $this->attributes[$method] = count($parameters) > 0 ? reset($parameters) : true; + + return $this; + } + + /** + * Dynamically retrieve the value of an attribute. + * + * @param TKey $key + * @return TValue|null + */ + public function __get($key) + { + return $this->value($key); + } + + /** + * Dynamically set the value of an attribute. + * + * @param TKey $key + * @param TValue $value + * @return void + */ + public function __set($key, $value) + { + $this->offsetSet($key, $value); + } + + /** + * Dynamically check if an attribute is set. + * + * @param TKey $key + * @return bool + */ + public function __isset($key) + { + return $this->offsetExists($key); + } + + /** + * Dynamically unset an attribute. + * + * @param TKey $key + * @return void + */ + public function __unset($key) + { + $this->offsetUnset($key); + } +} diff --git a/src/Html/Layout.php b/src/Html/Layout.php index ef4ca10..c3a952e 100644 --- a/src/Html/Layout.php +++ b/src/Html/Layout.php @@ -6,7 +6,6 @@ use Illuminate\Contracts\Support\Renderable; use Illuminate\Support\Facades\Blade; -use Illuminate\Support\Fluent; use Illuminate\Support\Traits\Macroable; use Illuminate\View\Component; use InvalidArgumentException; diff --git a/src/Html/Options/Plugins/Select.php b/src/Html/Options/Plugins/Select.php index 8cfc989..056d8e6 100644 --- a/src/Html/Options/Plugins/Select.php +++ b/src/Html/Options/Plugins/Select.php @@ -208,6 +208,18 @@ public function selectStyleMultiShift(): static return $this->select(['style' => Builder::SELECT_STYLE_MULTI_SHIFT]); } + /** + * Select keyboard navigation and selection. + * + * @return $this + * + * @see https://datatables.net/extensions/select/examples/initialisation/keys + */ + public function selectKeys(bool $enabled = true): static + { + return $this->select(['keys' => $enabled]); + } + public function getSelect(?string $key = null): mixed { if (is_null($key)) { diff --git a/src/Html/Parameters.php b/src/Html/Parameters.php index 7b6b0c4..4d3faee 100644 --- a/src/Html/Parameters.php +++ b/src/Html/Parameters.php @@ -2,8 +2,6 @@ namespace Yajra\DataTables\Html; -use Illuminate\Support\Fluent; - class Parameters extends Fluent { /** diff --git a/src/Html/SearchPane.php b/src/Html/SearchPane.php index 0b82a30..da90b11 100644 --- a/src/Html/SearchPane.php +++ b/src/Html/SearchPane.php @@ -5,7 +5,6 @@ use Closure; use Illuminate\Contracts\Support\Arrayable; use Illuminate\Database\Eloquent\Builder as EloquentBuilder; -use Illuminate\Support\Fluent; use Yajra\DataTables\Html\Editor\Fields\Options; class SearchPane extends Fluent diff --git a/src/resources/views/editor.blade.php b/src/resources/views/editor.blade.php index 70ab919..3f274d4 100644 --- a/src/resources/views/editor.blade.php +++ b/src/resources/views/editor.blade.php @@ -1,4 +1,4 @@ -$(function(){ +document.addEventListener("DOMContentLoaded", function(){ window.{{ config('datatables-html.namespace', 'LaravelDataTables') }} = window.{{ config('datatables-html.namespace', 'LaravelDataTables') }} || {}; $.ajaxSetup({headers: {'X-CSRF-TOKEN': '{{csrf_token()}}'}}); @foreach($editors as $editor) diff --git a/src/resources/views/script.blade.php b/src/resources/views/script.blade.php index b01ac74..4d3b205 100644 --- a/src/resources/views/script.blade.php +++ b/src/resources/views/script.blade.php @@ -1,4 +1,4 @@ -$(function(){window.{{ config('datatables-html.namespace', 'LaravelDataTables') }}=window.{{ config('datatables-html.namespace', 'LaravelDataTables') }}||{};window.{{ config('datatables-html.namespace', 'LaravelDataTables') }}["%1$s"]=$("#%1$s").DataTable(%2$s);}); +document.addEventListener("DOMContentLoaded",function(){window.{{ config('datatables-html.namespace', 'LaravelDataTables') }}=window.{{ config('datatables-html.namespace', 'LaravelDataTables') }}||{};window.{{ config('datatables-html.namespace', 'LaravelDataTables') }}["%1$s"]=$("#%1$s").DataTable(%2$s);}); @foreach ($scripts as $script) @include($script) @endforeach diff --git a/tests/BuilderOptionsLanguageTest.php b/tests/Html/Builder/BuilderOptionsLanguageTest.php similarity index 98% rename from tests/BuilderOptionsLanguageTest.php rename to tests/Html/Builder/BuilderOptionsLanguageTest.php index c65c45b..9567d16 100644 --- a/tests/BuilderOptionsLanguageTest.php +++ b/tests/Html/Builder/BuilderOptionsLanguageTest.php @@ -1,8 +1,9 @@ assertEquals($expected, $table); $script = $builder->scripts()->toHtml(); - $expected = ''; + $expected = ''; $this->assertEquals($expected, $script); - $expected = '$(function(){window.LaravelDataTables=window.LaravelDataTables||{};window.LaravelDataTables["foo-table"]=$("#foo-table").DataTable({"serverSide":true,"processing":true,"ajax":"","columns":[{"data":"foo","name":"foo","title":"Foo","orderable":true,"searchable":true},{"data":"baz","name":"baz","title":"Baz","orderable":true,"searchable":true}]});});'; + $expected = 'document.addEventListener("DOMContentLoaded",function(){window.LaravelDataTables=window.LaravelDataTables||{};window.LaravelDataTables["foo-table"]=$("#foo-table").DataTable({"serverSide":true,"processing":true,"ajax":"","columns":[{"data":"foo","name":"foo","title":"Foo","orderable":true,"searchable":true},{"data":"baz","name":"baz","title":"Baz","orderable":true,"searchable":true}]});});'; $this->assertEquals($expected, $builder->generateScripts()->toHtml()); } diff --git a/tests/LayoutTest.php b/tests/Html/Builder/LayoutTest.php similarity index 99% rename from tests/LayoutTest.php rename to tests/Html/Builder/LayoutTest.php index fb74294..3f46723 100644 --- a/tests/LayoutTest.php +++ b/tests/Html/Builder/LayoutTest.php @@ -1,6 +1,6 @@ ajax('/tags'); + + $this->assertSame('/tags', $field->toArray()['ajax']); + } + + #[Test] + public function it_can_set_tags_display(): void + { + $field = new Tags; + $field->display('display'); + + $this->assertSame('display', $field->toArray()['display']); + } + + #[Test] + public function it_can_set_tags_escape_label_html(): void + { + $field = new Tags; + $field->escapeLabelHtml(true); + + $this->assertTrue($field->toArray()['escapeLabelHtml']); + } + + #[Test] + public function it_can_set_tags_i18n_props_directly(): void + { + $field = new Tags; + $field->addButton('Add Tag'); + $this->assertSame('Add Tag', $field->toArray()['i18n']['addButton']); + } + + #[Test] + public function it_can_set_tags_i18n(): void + { + $field = new Tags; + $field->i18n([ + 'addButton' => 'Add', + 'inputPlaceholder' => 'Input', + 'noResults' => 'No Results', + 'title' => 'Title', + 'placeholder' => 'Placeholder', + ]); + + $this->assertSame('Add', $field->toArray()['i18n']['addButton']); + $this->assertSame('Input', $field->toArray()['i18n']['inputPlaceholder']); + $this->assertSame('No Results', $field->toArray()['i18n']['noResults']); + $this->assertSame('Title', $field->toArray()['i18n']['title']); + $this->assertSame('Placeholder', $field->toArray()['i18n']['placeholder']); + + $field->addButton('Add Button') + ->inputPlaceholder('Input Placeholder') + ->noResults('No Results X') + ->title('Title X') + ->placeholder('Placeholder X'); + + $this->assertSame('Add Button', $field->toArray()['i18n']['addButton']); + $this->assertSame('Input Placeholder', $field->toArray()['i18n']['inputPlaceholder']); + $this->assertSame('No Results X', $field->toArray()['i18n']['noResults']); + $this->assertSame('Title X', $field->toArray()['i18n']['title']); + $this->assertSame('Placeholder X', $field->toArray()['i18n']['placeholder']); + } + + #[Test] + public function it_can_set_tags_type(): void + { + $field = new Tags; + + $this->assertSame('tags', $field->toArray()['type']); + } + + #[Test] + public function it_can_set_tags_limit(): void + { + $field = new Tags; + $field->limit(2); + + $this->assertSame(2, $field->toArray()['limit']); + } + + #[Test] + public function it_can_set_tags_multiple(): void + { + $field = new Tags; + $field->multiple(); + + $this->assertTrue($field->toArray()['multiple']); + } + + #[Test] + public function it_can_set_tags_options(): void + { + $field = new Tags; + $field->options(['tag1', 'tag2']); + + $this->assertSame(['tag1', 'tag2'], $field->toArray()['options']); + + $field->options([ + ['value' => 'tag1', 'label' => 'Tag 1'], + ['value' => 'tag2', 'label' => 'Tag 2'], + ]); + + $this->assertSame([ + ['value' => 'tag1', 'label' => 'Tag 1'], + ['value' => 'tag2', 'label' => 'Tag 2'], + ], $field->toArray()['options']); + } + + #[Test] + public function it_can_set_tags_separator(): void + { + $field = new Tags; + $field->separator(','); + + $this->assertSame(',', $field->toArray()['separator']); + } + + #[Test] + public function it_can_set_tags_unique(): void + { + $field = new Tags; + $field->unique(); + + $this->assertTrue($field->toArray()['unique']); + } +} diff --git a/tests/SearchPaneTest.php b/tests/Html/Extensions/SearchPaneTest.php similarity index 96% rename from tests/SearchPaneTest.php rename to tests/Html/Extensions/SearchPaneTest.php index d32716a..48fd975 100644 --- a/tests/SearchPaneTest.php +++ b/tests/Html/Extensions/SearchPaneTest.php @@ -1,11 +1,12 @@