1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverLeague\LogViewer\Tests\Admin; |
4
|
|
|
|
5
|
|
|
use SilverLeague\LogViewer\Admin\LogViewerAdmin; |
6
|
|
|
use SilverLeague\LogViewer\Forms\GridField\GridFieldClearAllButton; |
7
|
|
|
use SilverStripe\Control\HTTPRequest; |
8
|
|
|
use SilverStripe\Dev\FunctionalTest; |
9
|
|
|
use SilverStripe\Forms\GridField\GridFieldAddNewButton; |
10
|
|
|
use SilverStripe\Forms\GridField\GridFieldPaginator; |
11
|
|
|
use SilverStripe\Forms\ReadonlyField; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @package silverstripe-logviewer |
15
|
|
|
* @author Robbie Averill <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class LogViewerAdminTest extends FunctionalTest |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* {@inheritDoc} |
21
|
|
|
*/ |
22
|
|
|
protected static $fixture_file = 'LogViewerAdminTest.yml'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The test subject |
26
|
|
|
* |
27
|
|
|
* @var LogViewerAdmin |
28
|
|
|
*/ |
29
|
|
|
protected $logViewerAdmin; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritDoc} |
33
|
|
|
*/ |
34
|
|
|
public function setUp() |
35
|
|
|
{ |
36
|
|
|
parent::setUp(); |
37
|
|
|
|
38
|
|
|
$request = new HTTPRequest('GET', '/'); |
39
|
|
|
$request->setSession($this->session()); |
40
|
|
|
|
41
|
|
|
$this->logViewerAdmin = new LogViewerAdmin; |
42
|
|
|
$this->logViewerAdmin->setRequest($request); |
43
|
|
|
$this->logViewerAdmin->doInit(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Test that the log entries are returned in reverse order of creation date/time |
48
|
|
|
*/ |
49
|
|
|
public function testLogsShouldBeInReverseOrder() |
50
|
|
|
{ |
51
|
|
|
$entries = $this->logViewerAdmin->getList(); |
52
|
|
|
$this->assertSame('INFO', $entries->first()->Level); |
53
|
|
|
$this->assertSame('DEBUG', $entries->last()->Level); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Test that the GridField "add new" button has been removed |
58
|
|
|
*/ |
59
|
|
|
public function testNoAddButton() |
60
|
|
|
{ |
61
|
|
|
$this->assertNull($this->getConfig()->getComponentByType(GridFieldAddNewButton::class)); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Test that there's a "clear all" button |
66
|
|
|
*/ |
67
|
|
|
public function testHasClearAllButton() |
68
|
|
|
{ |
69
|
|
|
$this->assertInstanceOf( |
70
|
|
|
GridFieldClearAllButton::class, |
71
|
|
|
$this->getConfig()->getComponentByType(GridFieldClearAllButton::class) |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Test that the GridField has a Paginator component |
77
|
|
|
*/ |
78
|
|
|
public function testHasPagination() |
79
|
|
|
{ |
80
|
|
|
$this->assertInstanceOf( |
81
|
|
|
GridFieldPaginator::class, |
82
|
|
|
$this->getConfig()->getComponentByType(GridFieldPaginator::class) |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Test that the entry and level fields are displayed in the GridField, and can be exported |
88
|
|
|
*/ |
89
|
|
|
public function testEntryAndLevelShouldBeInSummaryFields() |
90
|
|
|
{ |
91
|
|
|
$summaryFields = $this->logViewerAdmin->getExportFields(); |
92
|
|
|
$this->assertContains('Entry', $summaryFields); |
93
|
|
|
$this->assertContains('Level', $summaryFields); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Get the test GridField's config class |
98
|
|
|
* |
99
|
|
|
* @return \SilverStripe\Forms\GridField\GridFieldConfig |
100
|
|
|
*/ |
101
|
|
|
protected function getConfig() |
102
|
|
|
{ |
103
|
|
|
return $this->logViewerAdmin |
104
|
|
|
->getEditForm() |
105
|
|
|
->Fields() |
106
|
|
|
->fieldByName($this->logViewerAdmin->getGridFieldName()) |
107
|
|
|
->getConfig(); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|