-
-
Notifications
You must be signed in to change notification settings - Fork 463
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
4 changed files
with
59 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
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,14 @@ | ||
<?php namespace Cviebrock\EloquentSluggable\Tests\Models; | ||
|
||
|
||
/** | ||
* Class PostWithEagerRelations | ||
* | ||
* @package Cviebrock\EloquentSluggable\Tests\Models | ||
*/ | ||
class PostWithEagerRelation extends PostWithRelation | ||
{ | ||
|
||
protected $with = ['author']; | ||
|
||
} |
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,38 @@ | ||
<?php namespace Cviebrock\EloquentSluggable\Tests; | ||
|
||
use Cviebrock\EloquentSluggable\Tests\Models\Author; | ||
use Cviebrock\EloquentSluggable\Tests\Models\PostWithEagerRelation; | ||
|
||
/** | ||
* Class RelationTests | ||
* | ||
* @package Tests | ||
*/ | ||
class RelationTests extends TestCase | ||
{ | ||
|
||
/** | ||
* Test basic slugging functionality. | ||
*/ | ||
public function testEagerLoading(): void | ||
{ | ||
$author = Author::create([ | ||
'name' => 'Arthur Conan Doyle' | ||
]); | ||
$post = new PostWithEagerRelation([ | ||
'title' => 'My First Post' | ||
]); | ||
$post->author()->associate($author); | ||
$post->save(); | ||
|
||
self::assertEquals('arthur-conan-doyle-my-first-post', $post->slug); | ||
|
||
$post2 = new PostWithEagerRelation([ | ||
'title' => 'My second post', | ||
]); | ||
$post2->author()->associate($author); | ||
$post2->save(); | ||
self::assertEquals('arthur-conan-doyle-my-second-post', $post2->slug); | ||
} | ||
|
||
} |