LogViewerAdminTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 91
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testNoAddButton() 0 3 1
A getConfig() 0 7 1
A testLogsShouldBeInReverseOrder() 0 5 1
A testHasClearAllButton() 0 5 1
A setUp() 0 10 1
A testHasPagination() 0 5 1
A testEntryAndLevelShouldBeInSummaryFields() 0 5 1
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