Skip to content

Commit

Permalink
Improved testing
Browse files Browse the repository at this point in the history
  • Loading branch information
IsraelOrtuno committed Oct 3, 2018
1 parent 1f57cda commit c7fbff0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
25 changes: 21 additions & 4 deletions tests/PermalinkCreationTest.php
Expand Up @@ -3,6 +3,7 @@
namespace Devio\Permalink\Tests;

use Devio\Permalink\Permalink;
use Devio\Permalink\Tests\Dummy\DummyController;
use Devio\Permalink\Tests\Dummy\DummyUser;
use Devio\Permalink\Tests\Dummy\DummyUserWithMutators;
use Devio\Permalink\Tests\Dummy\DummyUserWithoutPermalinkManager;
Expand Down Expand Up @@ -54,6 +55,14 @@ public function permalink_relation_is_autoatically_loaded_when_automatically_cre
$this->assertTrue($user->relationLoaded('permalink'));
}

/** @test */
public function permalink_route_is_automatically_loaded_to_the_route_collection()
{
Permalink::create(['slug' => 'foo', 'action' => DummyController::class . '@index']);

$this->assertEquals('http://localhost/foo', route('dummy.index'));
}

/** @test */
public function permalinkable_entity_supports_morph_map()
{
Expand Down Expand Up @@ -110,7 +119,7 @@ public function permalink_attributes_can_be_set_when_creating_resource()
/** @test */
public function provided_permalink_slug_will_always_be_unique()
{
Permalink::create(['slug' => 'foo', 'action' => 'bar']);
Permalink::create(['slug' => 'foo', 'action' => DummyController::class . '@index']);
$user = factory(DummyUser::class)->create(['permalink' => ['slug' => 'foo']]);

$this->assertEquals('foo-1', $user->permalink->slug);
Expand All @@ -120,7 +129,7 @@ public function provided_permalink_slug_will_always_be_unique()
/** @test */
public function permalink_is_automatically_nested_if_default_parent_is_set()
{
$parent = Permalink::create(['slug' => 'foo', 'parent_for' => DummyUser::class, 'action' => 'bar']);
$parent = Permalink::create(['slug' => 'foo', 'parent_for' => DummyUser::class, 'action' => DummyController::class . '@index']);
$user = factory(DummyUser::class)->create(['permalink' => ['slug' => 'foo']]);

$this->assertEquals($parent->id, $user->permalink->parent_id);
Expand All @@ -130,7 +139,7 @@ public function permalink_is_automatically_nested_if_default_parent_is_set()
public function permalink_is_nested_with_morphed_model_name()
{
Relation::morphMap(['user' => DummyUser::class]);
$parent = Permalink::create(['slug' => 'foo', 'parent_for' => 'user', 'action' => 'bar']);
$parent = Permalink::create(['slug' => 'foo', 'parent_for' => 'user', 'action' => DummyController::class . '@index']);
$user = factory(DummyUser::class)->create(['permalink' => ['slug' => 'foo']]);

$this->assertEquals($parent->id, $user->permalink->parent_id);
Expand All @@ -140,7 +149,7 @@ public function permalink_is_nested_with_morphed_model_name()
public function permalink_is_nested_with_morphed_model_name_with_full_class_name()
{
Relation::morphMap(['user' => DummyUser::class]);
$parent = Permalink::create(['slug' => 'foo', 'parent_for' => DummyUser::class, 'action' => 'bar']);
$parent = Permalink::create(['slug' => 'foo', 'parent_for' => DummyUser::class, 'action' => DummyController::class . '@index']);
$user = factory(DummyUser::class)->create(['permalink' => ['slug' => 'foo']]);

$this->assertEquals($parent->id, $user->permalink->parent_id);
Expand Down Expand Up @@ -179,4 +188,12 @@ public function fallback_function_will_be_skiped_if_value_is_given()

$this->assertEquals('custom', $user->permalink->seo['meta']['title']);
}

/** @test */
public function permalink_creation_throws_exception_if_action_does_not_exist()
{
$this->expectException(\UnexpectedValueException::class);

Permalink::create(['slug' => 'foo', 'action' => 'bar']);
}
}
9 changes: 0 additions & 9 deletions tests/RouteLoadingTest.php
Expand Up @@ -13,8 +13,6 @@ public function routes_can_be_resolved_from_resource()
{
$user = factory(DummyUser::class)->create(['permalink' => ['slug' => 'foo']]);

$this->reloadRoutes();

$this->assertStringEndsWith('foo', $user->route);
}

Expand All @@ -23,8 +21,6 @@ public function permalink_with_models_will_get_a_default_route_name()
{
factory(DummyUser::class)->create(['permalink' => ['slug' => 'foo']]);

$this->reloadRoutes();

$this->assertStringEndsWith('foo', route('permalink.1'));
}

Expand All @@ -33,8 +29,6 @@ public function permalink_without_model_route_name_is_generated_by_route_and_act
{
Permalink::create(['slug' => 'foo', 'action' => DummyController::class . '@index']);

$this->reloadRoutes();

$this->assertStringEndsWith('foo', route('dummy.index'));
}

Expand All @@ -44,8 +38,6 @@ public function route_name_will_be_same_as_action_map_if_provided()
Permalink::actionMap(['foo.index' => DummyController::class . '@index']);
Permalink::create(['slug' => 'foo', 'action' => 'foo.index']);

$this->reloadRoutes();

$this->assertStringEndsWith('foo', route('foo.index'));
}

Expand All @@ -65,7 +57,6 @@ public function nested_routes_are_correctly_formed()
public function permalink_model_is_bound_to_the_route_instance()
{
$root = Permalink::create(['slug' => 'foo', 'action' => DummyController::class . '@foo']);
$this->reloadRoutes();

$route = $this->app['router']->getRoutes()->getIterator()->current();
$this->assertNotNull($route->permalink);
Expand Down

0 comments on commit c7fbff0

Please sign in to comment.