Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tabuna committed Nov 3, 2024
1 parent 8356187 commit a91de0e
Show file tree
Hide file tree
Showing 28 changed files with 83 additions and 24 deletions.
2 changes: 1 addition & 1 deletion resources/views/fields/attach.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@component($typeForm, collect(get_defined_vars())->except(['errors'])->all())
@component($typeForm, get_defined_vars())
<div data-controller="attach"
class="attach"
data-attach-name-value="{{ $name }}"
Expand Down
2 changes: 1 addition & 1 deletion resources/views/fields/checkbox.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@component($typeForm, collect(get_defined_vars())->except(['errors'])->all())
@component($typeForm, get_defined_vars())
<div data-controller="checkbox"
data-checkbox-indeterminate="{{$indeterminate}}">
@isset($sendTrueOrFalse)
Expand Down
2 changes: 1 addition & 1 deletion resources/views/fields/code.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@component($typeForm, collect(get_defined_vars())->except(['errors'])->all())
@component($typeForm, get_defined_vars())
<div
data-controller="code"
data-code-language="{{$language}}"
Expand Down
2 changes: 1 addition & 1 deletion resources/views/fields/cropper.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@component($typeForm, collect(get_defined_vars())->except(['errors'])->all())
@component($typeForm, get_defined_vars())
<div data-controller="cropper"
data-cropper-value="{{ $attributes['value'] }}"
data-cropper-storage="{{ $storage ?? config('platform.attachment.disk', 'public') }}"
Expand Down
2 changes: 1 addition & 1 deletion resources/views/fields/dataRange.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@component($typeForm, collect(get_defined_vars())->except(['errors'])->all())
@component($typeForm, get_defined_vars())
<div class="row" data-controller="datetime"
data-datetime-allow-input="true"
data-datetime-range="#end_{{ $attributes['id'] }}"
Expand Down
2 changes: 1 addition & 1 deletion resources/views/fields/datetime.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@component($typeForm, collect(get_defined_vars())->except(['errors'])->all())
@component($typeForm, get_defined_vars())
<div
data-controller="datetime"
class="input-group"
Expand Down
2 changes: 1 addition & 1 deletion resources/views/fields/input.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@component($typeForm, collect(get_defined_vars())->except(['errors'])->all())
@component($typeForm, get_defined_vars())
<div data-controller="input"
data-input-mask="{{$mask ?? ''}}"
>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/fields/label.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@component($typeForm, collect(get_defined_vars())->except(['errors'])->all())
@component($typeForm, get_defined_vars())
@if(strlen($value) > 0)
<p {{ $attributes }}>
{{ $value }}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/fields/map.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@component($typeForm, collect(get_defined_vars())->except(['errors'])->all())
@component($typeForm, get_defined_vars())
<div data-controller="map"
data-map-id="{{$id}}"
data-map-zoom="{{$zoom}}"
Expand Down
2 changes: 1 addition & 1 deletion resources/views/fields/matrix.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@component($typeForm, collect(get_defined_vars())->except(['errors'])->all())
@component($typeForm, get_defined_vars())
<table class="matrix table table-bordered border-right-0 overflow-y-auto"
data-controller="matrix"
data-matrix-index="{{ $index }}"
Expand Down
2 changes: 1 addition & 1 deletion resources/views/fields/numberRange.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@component($typeForm, collect(get_defined_vars())->except(['errors'])->all())
@component($typeForm, get_defined_vars())
<div class="row">
<div class="col-md-6 pe-1">
<div class="form-group">
Expand Down
2 changes: 1 addition & 1 deletion resources/views/fields/password.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@component($typeForm, collect(get_defined_vars())->except(['errors'])->all())
@component($typeForm, get_defined_vars())

<div data-controller="password"
class="input-icon"
Expand Down
2 changes: 1 addition & 1 deletion resources/views/fields/picture.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@component($typeForm, collect(get_defined_vars())->except(['errors'])->all())
@component($typeForm, get_defined_vars())
<div data-controller="picture"
data-picture-value="{{ $attributes['value'] }}"
data-picture-storage="{{ $storage ?? config('platform.attachment.disk', 'public') }}"
Expand Down
2 changes: 1 addition & 1 deletion resources/views/fields/quill.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@component($typeForm, collect(get_defined_vars())->except(['errors'])->all())
@component($typeForm, get_defined_vars())
<div data-controller="quill"
data-quill-toolbar='@json($toolbar)'
data-quill-base64='@json($base64)'
Expand Down
2 changes: 1 addition & 1 deletion resources/views/fields/radio.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@component($typeForm, collect(get_defined_vars())->except(['errors'])->all())
@component($typeForm, get_defined_vars())
<div class="form-check">
<input id="{{$id}}" {{ $attributes }}>
<label class="form-check-label" for="{{$id}}">{{$placeholder ?? ''}}</label>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/fields/radiobutton.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@component($typeForm, collect(get_defined_vars())->except(['errors'])->all())
@component($typeForm, get_defined_vars())
<div data-controller="radiobutton">
<div class="btn-group btn-group-toggle p-0" data-toggle="buttons">

Expand Down
2 changes: 1 addition & 1 deletion resources/views/fields/range.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@component($typeForm, collect(get_defined_vars())->except(['errors'])->all())
@component($typeForm, get_defined_vars())
<input type="range" class="form-range" {{ $attributes }}>
@endcomponent
2 changes: 1 addition & 1 deletion resources/views/fields/relation.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@component($typeForm, collect(get_defined_vars())->except(['errors'])->all())
@component($typeForm, get_defined_vars())
<div data-controller="relation"
data-relation-id="{{$id}}"
data-relation-placeholder="{{$attributes['placeholder'] ?? ''}}"
Expand Down
2 changes: 1 addition & 1 deletion resources/views/fields/select.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@component($typeForm, collect(get_defined_vars())->except(['errors'])->all())
@component($typeForm, get_defined_vars())
<div data-controller="select"
data-select-placeholder="{{$attributes['placeholder'] ?? ''}}"
data-select-allow-empty="{{ $allowEmpty }}"
Expand Down
2 changes: 1 addition & 1 deletion resources/views/fields/simplemde.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@component($typeForm, collect(get_defined_vars())->except(['errors'])->all())
@component($typeForm, get_defined_vars())
<div class="simplemde-wrapper" data-controller="simplemde"
data-simplemde-text-value='{!! \Illuminate\Support\Js::encode($value) !!}'>
<textarea {{ $attributes }}></textarea>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/fields/switch.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@component($typeForm, collect(get_defined_vars())->except(['errors'])->all())
@component($typeForm, get_defined_vars())
@isset($sendTrueOrFalse)
<input hidden name="{{$attributes['name']}}" value="{{$attributes['novalue']}}">
<div class="form-check form-switch">
Expand Down
2 changes: 1 addition & 1 deletion resources/views/fields/textarea.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@component($typeForm, collect(get_defined_vars())->except(['errors'])->all())
@component($typeForm, get_defined_vars())
<textarea {{ $attributes }}>{{ $value ?? '' }}</textarea>
@endcomponent
2 changes: 1 addition & 1 deletion resources/views/fields/upload.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@component($typeForm, collect(get_defined_vars())->except(['errors'])->all())
@component($typeForm, get_defined_vars())
<div
data-controller="upload"
data-upload-storage="{{$storage ?? config('platform.attachment.disk', 'public')}}"
Expand Down
2 changes: 1 addition & 1 deletion resources/views/fields/utm.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@component($typeForm, collect(get_defined_vars())->except(['errors'])->all())
@component($typeForm, get_defined_vars())

<div data-controller="utm">
<div class="input-group mb-3">
Expand Down
14 changes: 14 additions & 0 deletions resources/views/partials/fields/clear.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@

{{$slot}}

@php
// Backport for consistent error handling behavior between Laravel 10 and 11.
// This implementation will be modified in a future major version.
// Retrieve all errors from the $errors object and convert them into a collection
$allErrors = collect($errors->all());
// Check if there is a 'default' error key in the collection of errors
if ($allErrors->has('default')) {
// If a 'default' error exists, assign it to the $errors variable
$errors = $allErrors->get('default');
}
@endphp

@if($errors->has($oldName))
<div class="invalid-feedback d-block">
<small>{{$errors->first($oldName)}}</small>
Expand Down
14 changes: 14 additions & 0 deletions resources/views/partials/fields/horizontal.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@
<div class="col col-md-8">
{{$slot}}

@php
// Backport for consistent error handling behavior between Laravel 10 and 11.
// This implementation will be modified in a future major version.
// Retrieve all errors from the $errors object and convert them into a collection
$allErrors = collect($errors->all());
// Check if there is a 'default' error key in the collection of errors
if ($allErrors->has('default')) {
// If a 'default' error exists, assign it to the $errors variable
$errors = $allErrors->get('default');
}
@endphp

@if($errors->has($oldName))
<div class="invalid-feedback d-block">
<small>{{$errors->first($oldName)}}</small>
Expand Down
14 changes: 14 additions & 0 deletions resources/views/partials/fields/vertical.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@

{{$slot}}

@php
// Backport for consistent error handling behavior between Laravel 10 and 11.
// This implementation will be modified in a future major version.
// Retrieve all errors from the $errors object and convert them into a collection
$allErrors = collect($errors->all());
// Check if there is a 'default' error key in the collection of errors
if ($allErrors->has('default')) {
// If a 'default' error exists, assign it to the $errors variable
$errors = $allErrors->get('default');
}
@endphp

@if($errors->has($oldName))
<div class="invalid-feedback d-block">
<small>{{$errors->first($oldName)}}</small>
Expand Down
17 changes: 17 additions & 0 deletions tests/Unit/Screen/Fields/InputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use Illuminate\Foundation\Testing\Concerns\InteractsWithSession;
use Illuminate\Session\Store;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\MessageBag;
use Orchid\Screen\Fields\Input;
use Orchid\Tests\Unit\Screen\TestFieldsUnitCase;
use Throwable;
Expand Down Expand Up @@ -162,4 +164,19 @@ public function testOverwriteAttributes(): void

$this->assertNull($input->get('title'));
}

public function testValidationMessage(): void
{
$errors = new MessageBag(['name' => ['Name is required']]);

Session::put('errors', $errors);

$input = Input::make('name');

$this->assertStringContainsString(
'Name is required',
(string) $input,
'Expected validation error message was not found in the rendered input.'
);
}
}

0 comments on commit a91de0e

Please sign in to comment.