-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
495 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
parameters: | ||
ignoreErrors: | ||
- | ||
message: "#^Call to an undefined method Illuminate\\\\Database\\\\Eloquent\\\\Builder\\:\\:ordered\\(\\)\\.$#" | ||
count: 1 | ||
path: src/Filament/RedirectResource.php |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
103 changes: 103 additions & 0 deletions
103
tests/Feature/Filament/RedirectResource/Pages/ManageRedirectsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
|
||
use Codedor\FilamentRedirects\Filament\RedirectResource\Pages\ManageRedirects; | ||
use Codedor\FilamentRedirects\Models\Redirect; | ||
use Filament\Notifications\Notification; | ||
use Illuminate\Support\Facades\Queue; | ||
use Illuminate\Support\Facades\Storage; | ||
use Illuminate\Support\Str; | ||
use Mockery\MockInterface; | ||
|
||
use function Pest\Livewire\livewire; | ||
|
||
beforeEach(function () { | ||
$this->redirects = Redirect::factory()->createMany([ | ||
[ | ||
'from' => '/one', | ||
'to' => '/two', | ||
], | ||
[ | ||
'from' => '/foo', | ||
'to' => '/bar', | ||
], | ||
]); | ||
|
||
$this->actingAs(\Codedor\FilamentRedirects\Tests\Fixtures\Models\User::factory()->create()); | ||
}); | ||
|
||
it('can list redirects', function () { | ||
livewire(ManageRedirects::class) | ||
->assertSuccessful() | ||
->assertCanSeeTableRecords($this->redirects); | ||
}); | ||
|
||
it('has an edit action', function () { | ||
livewire(ManageRedirects::class) | ||
->assertTableActionExists('edit'); | ||
}); | ||
|
||
it('has a delete action', function () { | ||
livewire(ManageRedirects::class) | ||
->assertTableActionExists('delete') | ||
->assertTableBulkActionExists('delete'); | ||
}); | ||
|
||
it('has an import action that can throw an error', function () { | ||
livewire(ManageRedirects::class) | ||
->assertActionExists('import') | ||
->callAction('import'); | ||
|
||
Notification::assertNotified('Something went wrong during the import'); | ||
}); | ||
|
||
it('has an import action that can truncate the table', function () { | ||
Storage::disk('local')->put( | ||
'import_redirects.xlsx', | ||
file_get_contents(__DIR__ . '/../../../../Fixtures/import_redirects.xlsx', 'import_redirects.xlsx') | ||
); | ||
|
||
livewire(ManageRedirects::class) | ||
->assertActionExists('import') | ||
->callAction('import', ['file' => ['file' => 'import_redirects.xlsx'], | ||
]); | ||
|
||
Notification::assertNotified( | ||
Notification::make() | ||
->success() | ||
->title('Import was successful') | ||
); | ||
|
||
$this->assertDatabaseCount(Redirect::class, 3); | ||
$this->assertDatabaseHas(Redirect::class, [ | ||
'from' => '/from', | ||
'to' => '/to', | ||
'status' => 301, | ||
]); | ||
}); | ||
|
||
it('can create a redirect with validation errors', function () { | ||
livewire(ManageRedirects::class) | ||
->assertActionExists('create') | ||
->callAction('create', [ | ||
'from' => '/from', | ||
]) | ||
->assertHasActionErrors(['to' => 'required']); | ||
}); | ||
|
||
it('can create a redirect', function () { | ||
livewire(ManageRedirects::class) | ||
->assertActionExists('create') | ||
->callAction('create', [ | ||
'from' => '/from', | ||
'to' => '/to', | ||
'status' => 410 | ||
]) | ||
->assertHasNoActionErrors(); | ||
|
||
$this->assertDatabaseCount(Redirect::class, 3); | ||
$this->assertDatabaseHas(Redirect::class, [ | ||
'from' => '/from', | ||
'to' => '/to', | ||
'status' => 410, | ||
]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
use Codedor\FilamentRedirects\Filament\RedirectResource; | ||
use Codedor\FilamentRedirects\Models\Redirect; | ||
use Codedor\FilamentRedirects\Tests\Fixtures\Models\User; | ||
|
||
beforeEach(function () { | ||
Redirect::factory()->create(); | ||
|
||
$this->actingAs(User::factory()->create()); | ||
}); | ||
|
||
it('has an index page', function () { | ||
$this->get(RedirectResource::getUrl('index'))->assertSuccessful(); | ||
}); | ||
|
||
it('has only an index and edit action', function () { | ||
expect(RedirectResource::getPages()) | ||
->toHaveCount(1) | ||
->toHaveKeys(['index']); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<?php | ||
|
||
|
||
use Codedor\FilamentRedirects\Models\Redirect; | ||
use Symfony\Component\HttpKernel\Exception\HttpException; | ||
|
||
it('will skip if it is a post request', function () { | ||
$response = createResponse('/from', 'POST'); | ||
|
||
$this->assertEquals($response, null); | ||
}); | ||
|
||
it('will not skip if it is a get request', function () { | ||
Redirect::factory()->create([ | ||
'sort_order' => 1, | ||
'from' => '/from', | ||
'to' => '/to', | ||
'status' => 302, | ||
'pass_query_string' => false, | ||
'online' => true, | ||
]); | ||
|
||
$response = createResponse('/from'); | ||
|
||
$this->assertEquals($response->getStatusCode(), 302); | ||
$this->assertEquals($response->getTargetUrl(), 'http://localhost/to'); | ||
}); | ||
|
||
it('will only redirect for an online url map', function () { | ||
Redirect::factory()->create([ | ||
'sort_order' => 1, | ||
'from' => '/from', | ||
'to' => '/to', | ||
'status' => 302, | ||
'pass_query_string' => false, | ||
'online' => false, | ||
]); | ||
|
||
$response = createResponse('/from'); | ||
|
||
$this->assertEquals($response, null); | ||
}); | ||
|
||
it('will keep sort order in account', function () { | ||
Redirect::factory()->createQuietly([ | ||
'sort_order' => 2, | ||
'from' => '/from', | ||
'to' => '/to', | ||
'status' => 302, | ||
'pass_query_string' => false, | ||
'online' => true, | ||
]); | ||
Redirect::factory()->createQuietly([ | ||
'sort_order' => 1, | ||
'from' => '/from', | ||
'to' => '/to-2', | ||
'status' => 301, | ||
'pass_query_string' => false, | ||
'online' => true, | ||
]); | ||
|
||
$response = createResponse('/from'); | ||
|
||
$this->assertEquals($response->getStatusCode(), 301); | ||
$this->assertEquals($response->getTargetUrl(), 'http://localhost/to-2'); | ||
}); | ||
|
||
it('will not redirect if no url map matches', function () { | ||
Redirect::factory()->create([ | ||
'sort_order' => 1, | ||
'from' => '/from', | ||
'to' => '/to', | ||
'status' => 302, | ||
'pass_query_string' => false, | ||
'online' => true, | ||
]); | ||
|
||
$response = createResponse('/to'); | ||
|
||
$this->assertEquals($response, null); | ||
}); | ||
|
||
it('will redirect with query string', function () { | ||
Redirect::factory()->create([ | ||
'sort_order' => 1, | ||
'from' => '/from?query=string', | ||
'to' => '/to', | ||
'status' => 302, | ||
'pass_query_string' => true, | ||
'online' => true, | ||
]); | ||
|
||
$response = createResponse('/from?query=string'); | ||
|
||
$this->assertEquals($response->getStatusCode(), 302); | ||
$this->assertEquals($response->getTargetUrl(), 'http://localhost/to?query=string'); | ||
}); | ||
|
||
it('will abort if status is 410', function () { | ||
Redirect::factory()->create([ | ||
'sort_order' => 1, | ||
'from' => '/from', | ||
'to' => null, | ||
'status' => 410, | ||
'pass_query_string' => true, | ||
'online' => true, | ||
]); | ||
|
||
$this->expectException(HttpException::class); | ||
|
||
createResponse('/from'); | ||
}); | ||
|
||
it('will redirect with a wildcard', function () { | ||
Redirect::factory()->create([ | ||
'sort_order' => 1, | ||
'from' => '/from/*', | ||
'to' => '/to', | ||
'status' => 302, | ||
'pass_query_string' => false, | ||
'online' => true, | ||
]); | ||
|
||
|
||
$response = createResponse('/from'); | ||
|
||
$this->assertEquals($response, null); | ||
|
||
$response2 = createResponse('/from/wildcard'); | ||
|
||
$this->assertEquals($response2->getStatusCode(), 302); | ||
$this->assertEquals($response2->getTargetUrl(), 'http://localhost/to'); | ||
}); |
Oops, something went wrong.