-
-
Notifications
You must be signed in to change notification settings - Fork 111
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
1 parent
5a9f6dd
commit 8598ac7
Showing
9 changed files
with
175 additions
and
0 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
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,33 @@ | ||
<?php | ||
|
||
namespace Tests\Unit; | ||
|
||
use Illuminate\Http\JsonResponse; | ||
use ProtoneMedia\Splade\Facades\Splade; | ||
use ProtoneMedia\Splade\SpladeCore; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Tests\TestCase; | ||
|
||
class SpladeCoreTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_generates_a_regular_redirect_on_non_splade_requests() | ||
{ | ||
$redirect = Splade::redirectAway('https://splade.dev'); | ||
|
||
$this->assertInstanceOf(RedirectResponse::class, $redirect); | ||
$this->assertEquals('https://splade.dev', $redirect->getTargetUrl()); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_generate_a_409_response_with_a_target_url() | ||
{ | ||
request()->headers->set(SpladeCore::HEADER_SPLADE, true); | ||
|
||
$redirect = Splade::redirectAway('https://splade.dev'); | ||
|
||
$this->assertInstanceOf(JsonResponse::class, $redirect); | ||
$this->assertEquals(409, $redirect->status()); | ||
$this->assertEquals('https://splade.dev', $redirect->headers->get(SpladeCore::HEADER_REDIRECT_AWAY)); | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
namespace Tests\Unit; | ||
|
||
use ProtoneMedia\Splade\Http\SpladeMiddleware; | ||
use Tests\TestCase; | ||
|
||
class SpladeMiddlewareTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_can_format_a_url_into_a_host_and_port_with_defaults() | ||
{ | ||
$this->assertEquals('splade.dev:80', SpladeMiddleware::urlToHostAndPort('http://splade.dev')); | ||
$this->assertEquals('splade.dev:443', SpladeMiddleware::urlToHostAndPort('https://splade.dev')); | ||
$this->assertEquals('splade.dev:8080', SpladeMiddleware::urlToHostAndPort('http://splade.dev:8080')); | ||
$this->assertEquals('splade.dev:8080', SpladeMiddleware::urlToHostAndPort('https://splade.dev:8080')); | ||
|
||
$this->assertEquals('splade.dev:80', SpladeMiddleware::urlToHostAndPort('http://splade.dev/path')); | ||
$this->assertEquals('splade.dev:443', SpladeMiddleware::urlToHostAndPort('https://splade.dev/path')); | ||
$this->assertEquals('splade.dev:8080', SpladeMiddleware::urlToHostAndPort('http://splade.dev:8080/path')); | ||
$this->assertEquals('splade.dev:8080', SpladeMiddleware::urlToHostAndPort('https://splade.dev:8080/path')); | ||
|
||
$this->assertEquals('splade.dev:80', SpladeMiddleware::urlToHostAndPort('splade.dev/path')); | ||
$this->assertEquals('splade.dev:80', SpladeMiddleware::urlToHostAndPort('splade.dev:80/path')); | ||
$this->assertEquals('splade.dev:443', SpladeMiddleware::urlToHostAndPort('splade.dev:443/path')); | ||
$this->assertEquals('splade.dev:8080', SpladeMiddleware::urlToHostAndPort('splade.dev:8080/path')); | ||
} | ||
} |
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