-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from knash94/feature-unit-testing
Feature unit testing
- Loading branch information
Showing
13 changed files
with
4,037 additions
and
5 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 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,35 @@ | ||
<?php | ||
|
||
namespace Knash94\Seo\Tests\Unit\Exception; | ||
|
||
use Exception; | ||
use Illuminate\Http\RedirectResponse; | ||
use Knash94\Seo\Traits\LogsMissingPages; | ||
|
||
class Handler extends \Orchestra\Testbench\Exceptions\Handler | ||
{ | ||
/** | ||
* This class is made to emulate an applications handler.php for testing purposed only. | ||
*/ | ||
|
||
use LogsMissingPages; | ||
|
||
/** | ||
* Render an exception into an HTTP response. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Exception $e | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function render($request, Exception $e) | ||
{ | ||
$redirect = $this->reportNotFound($e); | ||
|
||
if ($redirect && $redirect instanceof RedirectResponse) { | ||
return $redirect; | ||
} | ||
|
||
return parent::render($request, $e); | ||
} | ||
} |
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,37 @@ | ||
<?php | ||
|
||
namespace Knash94\Seo\Tests\Unit\Exception; | ||
|
||
|
||
use Knash94\Seo\Store\Eloquent\Models\HttpError; | ||
use Knash94\Seo\Store\Eloquent\Models\HttpRedirect; | ||
use Knash94\Seo\Tests\Unit\TestCase; | ||
|
||
class HandlerTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_logs_404_pages() | ||
{ | ||
$request = $this->get('/test'); | ||
|
||
|
||
$request->assertResponseStatus(404); | ||
|
||
$this->assertTrue(HttpError::where('path', 'test')->exists()); | ||
} | ||
|
||
/** @test */ | ||
public function it_redirects_404() | ||
{ | ||
factory(HttpRedirect::class)->create([ | ||
'path' => 'test', | ||
'redirect_url' => 'https://www.google.com', | ||
'status_code' => 302 | ||
]); | ||
|
||
$request = $this->get('/test'); | ||
|
||
$request->assertResponseStatus(302); | ||
$request->assertRedirectedTo('https://www.google.com'); | ||
} | ||
} |
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,57 @@ | ||
<?php | ||
namespace Knash94\Seo\Tests\Unit\Http\Controllers; | ||
|
||
use Knash94\Seo\Store\Eloquent\Models\HttpError; | ||
use Knash94\Seo\Tests\Unit\TestCase; | ||
|
||
class ErrorsControllerTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_returns_404_if_id_does_not_exist() | ||
{ | ||
$request = $this->get(route('seo-tools.error.view', 1)); | ||
|
||
$request->assertResponseStatus(404); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_error_view_when_pass_id() | ||
{ | ||
$error = factory(HttpError::class)->create(); | ||
|
||
$request = $this->get(route('seo-tools.error.view', $error->id)); | ||
|
||
$request->assertResponseStatus(200); | ||
$request->assertViewHas('template'); | ||
$request->seeText('User Agent'); | ||
} | ||
|
||
/** @test */ | ||
public function it_shows_edit_page() | ||
{ | ||
$error = factory(HttpError::class)->create(); | ||
|
||
$request = $this->get(route('seo-tools.error.edit', $error->id)); | ||
|
||
$request->assertResponseStatus(200); | ||
$request->assertViewHas('template'); | ||
$request->seeText('Managing'); | ||
} | ||
|
||
/** @test */ | ||
public function it_updates_errors() | ||
{ | ||
$error = factory(HttpError::class)->create(); | ||
|
||
$request = $this->post( | ||
route('seo-tools.error.update', $error->id), | ||
[ | ||
'redirect_url' => 'https://www.google.com', | ||
'status_code' => 302 | ||
] | ||
); | ||
|
||
$request->assertResponseStatus(302); | ||
$this->assertEquals($error->redirect->redirect_url, 'https://www.google.com'); | ||
} | ||
} |
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,91 @@ | ||
<?php | ||
namespace Knash94\Seo\Tests\Unit\Http\Controllers; | ||
|
||
use Knash94\Seo\Store\Eloquent\Models\HttpRedirect; | ||
use Knash94\Seo\Tests\Unit\TestCase; | ||
|
||
class RedirectControllerTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_returns_404_if_id_does_not_exist() | ||
{ | ||
$request = $this->get(route('seo-tools.redirect.edit', 1)); | ||
|
||
$request->assertResponseStatus(404); | ||
} | ||
|
||
/** @test */ | ||
public function it_shows_edit_page() | ||
{ | ||
$redirect = factory(HttpRedirect::class)->create(); | ||
|
||
$request = $this->get(route('seo-tools.redirect.edit', $redirect->id)); | ||
|
||
$request->assertResponseStatus(200); | ||
$request->assertViewHas('template'); | ||
$request->seeText('Manage redirect'); | ||
} | ||
|
||
/** @test */ | ||
public function it_updates_redirect() | ||
{ | ||
$redirect = factory(HttpRedirect::class)->create(); | ||
|
||
$request = $this->post( | ||
route('seo-tools.redirect.update', $redirect->id), | ||
[ | ||
'redirect_url' => 'https://www.google.com', | ||
'path' => '/test', | ||
'status_code' => 302 | ||
] | ||
); | ||
$redirect = $redirect->fresh(); | ||
|
||
$request->assertResponseStatus(302); | ||
$request->assertSessionHas('seo-tools.message'); | ||
$this->assertEquals($redirect->redirect_url, 'https://www.google.com'); | ||
} | ||
|
||
/** @test */ | ||
public function it_creates_a_redirect() | ||
{ | ||
$initialCount = HttpRedirect::count(); | ||
|
||
$request = $this->post( | ||
route('seo-tools.redirect.store'), | ||
[ | ||
'redirect_url' => 'https://www.google.com', | ||
'path' => '/test', | ||
'status_code' => 302 | ||
] | ||
); | ||
|
||
$request->assertResponseStatus(302); | ||
$request->assertSessionHas('seo-tools.message'); | ||
$this->assertNotEquals($initialCount, HttpRedirect::count()); | ||
} | ||
|
||
/** @test */ | ||
public function it_shows_delete_screen() | ||
{ | ||
$redirect = factory(HttpRedirect::class)->create(); | ||
|
||
$request = $this->get(route('seo-tools.redirect.remove', $redirect->id)); | ||
|
||
$request->assertResponseStatus(200); | ||
$request->assertViewHas('template'); | ||
$request->seeText('Delete redirect'); | ||
} | ||
|
||
/** @test */ | ||
public function it_destroys_a_redirect() | ||
{ | ||
$redirect = factory(HttpRedirect::class)->create(); | ||
|
||
$request = $this->get(route('seo-tools.redirect.destroy', $redirect->id)); | ||
|
||
$request->assertResponseStatus(302); | ||
$request->assertSessionHas('seo-tools.message'); | ||
$this->assertEmpty(HttpRedirect::count()); | ||
} | ||
} |
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,17 @@ | ||
<?php | ||
namespace Knash94\Seo\Tests\Unit\Http\Controllers; | ||
|
||
use Knash94\Seo\Store\Eloquent\Models\HttpError; | ||
use Knash94\Seo\Tests\Unit\TestCase; | ||
|
||
class SeoRedirectControllerTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_returns_404_if_id_does_not_exist() | ||
{ | ||
$request = $this->get(route('seo-tools.index')); | ||
|
||
$request->assertResponseStatus(200); | ||
$request->seeText('Redirect Manager'); | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
return [ | ||
'routing' => [ | ||
'prefix' => 'admin/seo-tools', | ||
'namespace' => 'Knash94\Seo\Http\Controllers', | ||
'middleware' => ['web', 'auth'] | ||
], | ||
|
||
'views' => [ | ||
'template' => 'seo-tools::templates.default', | ||
'section' => 'content', | ||
'index' => 'seo-tools::bootstrap3.index', | ||
|
||
'errors' => [ | ||
'edit' => 'seo-tools::bootstrap3.errors.edit', | ||
'view' => 'seo-tools::bootstrap3.errors.view' | ||
], | ||
|
||
'redirects' => [ | ||
'edit' => 'seo-tools::bootstrap3.redirects.edit', | ||
'delete' => 'seo-tools::bootstrap3.redirects.delete' | ||
] | ||
], | ||
|
||
// Filters what URLs to not record using regex | ||
'filters' => [ | ||
'/(\.png)|(\.jpg)|(\.gif)/', | ||
'/wp\-login\.php/' | ||
] | ||
]; |