-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathCommentsTest.php
152 lines (112 loc) · 4.3 KB
/
CommentsTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
namespace Tests\Feature\Common;
use Modules\MyBlog\Exports\Comments as Export;
use Modules\MyBlog\Jobs\CreateComment;
use Modules\MyBlog\Models\Comment;
use Modules\MyBlog\Models\Post;
use Tests\Feature\FeatureTestCase;
class CommentsTest extends FeatureTestCase
{
public function testItShouldSeeCommentListPage()
{
$this->loginAs()
->get(route('my-blog.comments.index'))
->assertStatus(200)
->assertSeeText(trans_choice('my-blog::general.comments', 2));
}
public function testItShouldSeeCommentCreatePage()
{
$this->loginAs()
->get(route('my-blog.comments.create'))
->assertStatus(200)
->assertSeeText(trans('general.title.new', ['type' => trans_choice('my-blog::general.comments', 1)]));
}
public function testItShouldCreateComment()
{
Post::factory()->enabled()->count(5)->create();
$request = $this->getRequest();
$this->loginAs()
->post(route('my-blog.comments.store'), $request)
->assertStatus(200);
$this->assertFlashLevel('success');
$this->assertDatabaseHas('my_blog_comments', $request);
}
public function testItShouldSeeCommentUpdatePage()
{
Post::factory()->enabled()->count(5)->create();
$request = $this->getRequest();
$comment = $this->dispatch(new CreateComment($request));
$this->loginAs()
->get(route('my-blog.comments.edit', $comment->id))
->assertStatus(200)
->assertSee($comment->description);
}
public function testItShouldUpdateComment()
{
Post::factory()->enabled()->count(5)->create();
$request = $this->getRequest();
$comment = $this->dispatch(new CreateComment($request));
$request['description'] = $this->faker->text(15);
$this->loginAs()
->patch(route('my-blog.comments.update', $comment->id), $request)
->assertStatus(200)
->assertSee($request['description']);
$this->assertFlashLevel('success');
$this->assertDatabaseHas('my_blog_comments', $request);
}
public function testItShouldDeleteComment()
{
Post::factory()->enabled()->count(5)->create();
$request = $this->getRequest();
$comment = $this->dispatch(new CreateComment($request));
$this->loginAs()
->delete(route('my-blog.comments.destroy', $comment->id))
->assertStatus(200);
$this->assertFlashLevel('success');
$this->assertSoftDeleted('my_blog_comments', $request);
}
public function testItShouldExportComments()
{
Post::factory()->enabled()->count(5)->create();
$count = 5;
Comment::factory()->count($count)->create();
\Excel::fake();
$this->loginAs()
->get(route('my-blog.comments.export'))
->assertStatus(200);
\Excel::matchByRegex();
\Excel::assertDownloaded(
'/' . \Str::filename(trans_choice('my-blog::general.comments', 2)) . '-\d{10}\.xlsx/',
function (Export $export) use ($count) {
// Assert that the correct export is downloaded.
return $export->collection()->count() === $count;
}
);
}
public function testItShouldExportSelectedComments()
{
Post::factory()->enabled()->count(5)->create();
$create_count = 5;
$select_count = 3;
$comments = Comment::factory()->count($create_count)->create();
\Excel::fake();
$this->loginAs()
->post(
route('bulk-actions.action', ['group' => 'my-blog', 'type' => 'comments']),
['handle' => 'export', 'selected' => $comments->take($select_count)->pluck('id')->toArray()]
)
->assertStatus(200);
\Excel::matchByRegex();
\Excel::assertDownloaded(
'/' . \Str::filename(trans_choice('my-blog::general.comments', 2)) . '-\d{10}\.xlsx/',
function (Export $export) use ($select_count) {
// Assert that the correct export is downloaded.
return $export->collection()->count() === $select_count;
}
);
}
public function getRequest()
{
return Comment::factory()->raw();
}
}