Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tabuna committed Apr 20, 2024
1 parent 159d631 commit 232c4c8
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 32 deletions.
6 changes: 4 additions & 2 deletions src/Screen/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,6 +21,8 @@
*/
trait Environment
{
use WithLaravelMigrations;

/**
* Setup the test environment.
* Run test: php vendor/bin/phpunit --coverage-html ./logs/coverage ./tests
Expand Down
11 changes: 8 additions & 3 deletions tests/Feature/Platform/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 16 additions & 14 deletions tests/Unit/FieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down
31 changes: 18 additions & 13 deletions tests/Unit/Screen/Fields/InputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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();

Expand All @@ -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();

Expand Down

0 comments on commit 232c4c8

Please sign in to comment.