-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for user can add comment and implement functionality
add blog menu add comment form add post creator
- Loading branch information
1 parent
8672c19
commit 1523cb1
Showing
14 changed files
with
130 additions
and
28 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
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
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,39 @@ | ||
<?php | ||
|
||
namespace Tests\Feature; | ||
|
||
use Tests\TestCase; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
|
||
class SubmitCommentTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
function guest_can_not_submit_comment(){ | ||
// Given a Guest | ||
$guest = factory('App\User')->create(); | ||
// And Post is exist | ||
$post = factory('App\Post')->create(); | ||
// And Giving comment object | ||
$comment = factory('App\Comment')->make(); | ||
// When the user submit comment to the post | ||
$this->post('/blog/'.$post->id.'/comment',$comment->toArray()); | ||
// expect exception thrown | ||
$this->expectException('Illuminate\Auth\AuthenticationException'); | ||
} | ||
public function test_user_can_submit_comment(){ | ||
// Given a Guest | ||
$guest = factory('App\User')->create(); | ||
// create Authenticate user | ||
$user = $this->be($guest); | ||
// And Post is exist | ||
$post = factory('App\Post')->create(); | ||
// And Giving comment object | ||
$comment = factory('App\Comment')->make(); | ||
// When the user submit comment to the post | ||
$this->post('/blog/'.$post->id.'/comment',$comment->toArray()); | ||
// Then their should see comment | ||
// $this->assertDatabaseHas('comments',['body'=>$comment->body]); | ||
$this->get('/blog/'.$post->id)->assertSee($comment->body); | ||
|
||
} | ||
} |
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.
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 Tests\Unit; | ||
|
||
use Tests\TestCase; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
|
||
class PostTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
/** | ||
* A basic test example. | ||
* | ||
* @return void | ||
*/ | ||
public function test_a_post_can_add_a_comments() | ||
{ | ||
//Giving a Post | ||
$post = factory('App\Post')->create(); | ||
// Add a comemnt | ||
$post->storeComment([ | ||
'body'=>'Testing', | ||
'user_id'=>1 | ||
]); | ||
// Then post should have comment | ||
$this->assertCount(1,$post->comment); | ||
} | ||
function test_post_has_a_creator() | ||
{ | ||
// Giving post | ||
$post = factory('App\Post')->create(); | ||
// expect found User who create post | ||
$this->assertInstanceOf('App\User', $post->creator); | ||
} | ||
} |