diff --git a/src/Screen/Field.php b/src/Screen/Field.php index b6ac13490..8cbb5d889 100644 --- a/src/Screen/Field.php +++ b/src/Screen/Field.php @@ -301,9 +301,11 @@ public function getOldValue() public function getOldName(): string { - return (string) Str::of($this->get('name')) + return Str::of($this->get('name')) ->replace(['][', '['], '.') - ->replace([']'], '')->rtrim('.'); + ->replace([']'], '') + ->rtrim('.') + ->toString(); } /** diff --git a/tests/Environment.php b/tests/Environment.php index 9d8ab1e36..c69e804ec 100644 --- a/tests/Environment.php +++ b/tests/Environment.php @@ -5,6 +5,7 @@ namespace Orchid\Tests; use Illuminate\Database\Eloquent\Factories\Factory; +use Orchestra\Testbench\Concerns\WithLaravelMigrations; use Orchid\Platform\Database\Seeders\OrchidDatabaseSeeder; use Orchid\Platform\Models\User; use Orchid\Platform\Providers\FoundationServiceProvider; @@ -20,6 +21,8 @@ */ trait Environment { + use WithLaravelMigrations; + /** * Setup the test environment. * Run test: php vendor/bin/phpunit --coverage-html ./logs/coverage ./tests diff --git a/tests/Feature/Platform/AuthTest.php b/tests/Feature/Platform/AuthTest.php index 8f1a82695..d8d4ad97b 100644 --- a/tests/Feature/Platform/AuthTest.php +++ b/tests/Feature/Platform/AuthTest.php @@ -18,10 +18,15 @@ public function testRouteDashboardLogin(): void public function testRouteDashboardLoginAuth(): void { - $this->actingAs($this->createAdminUser()) + $response = $this->actingAs($this->createAdminUser()) ->get(route('platform.login')) - ->assertStatus(302) - ->assertRedirect('/home'); + ->assertStatus(302); + + $this->assertTrue( + // Home for Laravel 10.x and earlier + // '/' for Laravel 11.x and later + $response->isRedirect(url('/home')) || $response->isRedirect(url('/')) + ); } public function testRouteDashboardLoginAuthSuccess(): void diff --git a/tests/Unit/FieldTest.php b/tests/Unit/FieldTest.php index c5c1ee4ab..ad33fa523 100644 --- a/tests/Unit/FieldTest.php +++ b/tests/Unit/FieldTest.php @@ -5,7 +5,7 @@ namespace Orchid\Tests\Unit; use Illuminate\Contracts\View\View; -use Illuminate\Support\Facades\Session; +use Illuminate\Session\Store; use Orchid\Screen\Field; use Orchid\Screen\Fields\CheckBox; use Orchid\Screen\Fields\Code; @@ -194,26 +194,28 @@ public function testOldNameMatchesLaravelRequestOldPrefixWithErrors() public function testOldName(): void { - Session::start(); + $session = tap(app()->make(Store::class), function ($session) { + $session->start(); + $session->put('_old_input', [ + 'name' => "The heart of Seoul's nightlife", + ]); + }); - Session::put('_old_input', [ - 'name' => "The heart of Seoul's nightlife", - ]); - - request()->setLaravelSession(session()); + request()->setLaravelSession($session); $this->assertSame("The heart of Seoul's nightlife", Input::make('name')->getOldValue()); } public function testNumericOldName(): void { - Session::start(); - - Session::put('_old_input', [ - 'numeric' => '3.141', - ]); - - request()->setLaravelSession(session()); + $session = tap(app()->make(Store::class), function ($session) { + $session->start(); + $session->put('_old_input', [ + 'numeric' => '3.141', + ]); + }); + + request()->setLaravelSession($session); $this->assertSame('3.141', Input::make('numeric')->getOldValue()); } diff --git a/tests/Unit/Screen/Fields/InputTest.php b/tests/Unit/Screen/Fields/InputTest.php index 8191dc5cb..0f08b9b2b 100644 --- a/tests/Unit/Screen/Fields/InputTest.php +++ b/tests/Unit/Screen/Fields/InputTest.php @@ -4,13 +4,16 @@ namespace Orchid\Tests\Unit\Screen\Fields; -use Illuminate\Support\Facades\Session; +use Illuminate\Foundation\Testing\Concerns\InteractsWithSession; +use Illuminate\Session\Store; use Orchid\Screen\Fields\Input; use Orchid\Tests\Unit\Screen\TestFieldsUnitCase; use Throwable; class InputTest extends TestFieldsUnitCase { + use InteractsWithSession; + /** * @throws Throwable */ @@ -121,13 +124,14 @@ public function testAddMinLengthAttribute(): void public function testLongNumericValue(): void { - Session::start(); - - Session::put('_old_input', [ - 'numeric' => '1234567890123456789012345678901234567890', - ]); + $session = tap(app()->make(Store::class), function ($session) { + $session->start(); + $session->put('_old_input', [ + 'numeric' => '1234567890123456789012345678901234567890', + ]); + }); - request()->setLaravelSession(session()); + request()->setLaravelSession($session); $input = Input::make('numeric')->getOldValue(); @@ -136,13 +140,14 @@ public function testLongNumericValue(): void public function testMediumLongNumericValue(): void { - Session::start(); - - Session::put('_old_input', [ - 'numeric' => '66666666666666666666', - ]); + $session = tap(app()->make(Store::class), function ($session) { + $session->start(); + $session->put('_old_input', [ + 'numeric' => '66666666666666666666', + ]); + }); - request()->setLaravelSession(session()); + request()->setLaravelSession($session); $input = Input::make('numeric')->getOldValue();