forked from ARCANEDEV/LogViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RoutesTest.php
171 lines (138 loc) · 5.34 KB
/
RoutesTest.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php namespace Arcanedev\LogViewer\Tests;
/**
* Class RoutesTest
*
* @package Arcanedev\LogViewer\Tests
* @author ARCANEDEV <[email protected]>
*
* @todo: Find a way to test the route Classes with testbench (Find another tool if it's impossible).
*/
class RoutesTest extends TestCase
{
/* -----------------------------------------------------------------
| Tests
| -----------------------------------------------------------------
*/
/** @test */
public function it_can_see_dashboard_page()
{
$response = $this->get(route('log-viewer::dashboard'));
$response->assertSuccessful();
static::assertStringContainsString(
'<h1>Dashboard</h1>',
$response->getContent()
);
}
/** @test */
public function it_can_see_logs_page()
{
$response = $this->get(route('log-viewer::logs.list'));
$response->assertSuccessful();
static::assertStringContainsString(
'<h1>Logs</h1>',
$response->getContent()
);
// TODO: Add more assertion => list all logs
}
/** @test */
public function it_can_show_a_log_page()
{
$date = '2015-01-01';
$response = $this->get(route('log-viewer::logs.show', [$date]));
$response->assertSuccessful();
static::assertStringContainsString(
"<h1>Log [{$date}]</h1>",
$response->getContent()
);
// TODO: Add more assertion => list all log entries
}
/** @test */
public function it_can_see_a_filtered_log_entries_page()
{
$date = '2015-01-01';
$level = 'error';
$response = $this->get(route('log-viewer::logs.filter', [$date, $level]));
$response->assertSuccessful();
static::assertStringContainsString(
"<h1>Log [{$date}]</h1>",
$response->getContent()
);
// TODO: Add more assertion => log entries is filtered by a level
}
/** @test */
public function it_can_search_if_log_entries_contains_same_header_page()
{
$date = '2015-01-01';
$level = 'all';
$query = 'This is an error log.';
$response = $this->get(route('log-viewer::logs.search', compact('date', 'level', 'query')));
$response->assertSuccessful();
/** @var \Illuminate\View\View $view */
$view = $response->getOriginalContent();
static::assertArrayHasKey('entries', $view->getData());
/** @var \Illuminate\Pagination\LengthAwarePaginator $entries */
$entries = $view->getData()['entries'];
static::assertCount(1, $entries);
}
/** @test */
public function it_must_redirect_on_all_level()
{
$date = '2015-01-01';
$level = 'all';
$response = $this->get(route('log-viewer::logs.filter', [$date, $level]));
static::assertTrue($response->isRedirection());
static::assertEquals(302, $response->getStatusCode());
// TODO: Add more assertion to check the redirect url
}
/** @test */
public function it_can_download_a_log_page()
{
$date = '2015-01-01';
$response = $this->get(route('log-viewer::logs.download', [$date]));
$response->assertSuccessful();
/** @var \Symfony\Component\HttpFoundation\BinaryFileResponse $base */
$base = $response->baseResponse;
static::assertInstanceOf(
\Symfony\Component\HttpFoundation\BinaryFileResponse::class, $base
);
static::assertEquals("laravel-$date.log", $base->getFile()->getFilename());
}
/** @test */
public function it_can_delete_a_log()
{
static::createDummyLog(
$date = date('Y-m-d')
);
$response = $this->call('DELETE', route('log-viewer::logs.delete', compact('date')), [], [], [], ['HTTP_X-Requested-With' => 'XMLHttpRequest']);
$response->assertExactJson(['result' => 'success']);
}
/** @test */
public function it_must_throw_log_not_found_exception_on_show()
{
$response = $this->get(route('log-viewer::logs.show', ['0000-00-00']));
static::assertInstanceOf(
\Symfony\Component\HttpKernel\Exception\HttpException::class,
$response->exception
);
static::assertSame(404, $response->getStatusCode());
static::assertSame('Log not found in this date [0000-00-00]', $response->exception->getMessage());
}
/** @test */
public function it_must_throw_log_not_found_exception_on_delete()
{
$response = $this->call('DELETE', route('log-viewer::logs.delete', ['0000-00-00']), [], [], [], ['HTTP_X-Requested-With' => 'XMLHttpRequest']);
static::assertInstanceOf(\Arcanedev\LogViewer\Exceptions\FilesystemException::class, $response->exception);
static::assertStringStartsWith('The log(s) could not be located at : ', $response->exception->getMessage());
}
/** @test */
public function it_must_throw_method_not_allowed_on_delete()
{
$response = $this->delete(route('log-viewer::logs.delete'));
$response->assertStatus(405);
static::assertInstanceOf(
\Symfony\Component\HttpKernel\Exception\HttpException::class,
$response->exception
);
static::assertSame('Method Not Allowed', $response->exception->getMessage());
}
}