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