Completed
Push — master ( e8c087...caf2b3 )
by Robbie
23s
created

LogViewerAdminTest::testNoAddButton()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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\GridField\GridFieldPaginator;
10
use SilverStripe\Forms\ReadonlyField;
11
12
/**
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 GridField has a Paginator component
72
     */
73
    public function testHasPagination()
74
    {
75
        $this->assertInstanceOf(
76
            GridFieldPaginator::class,
77
            $this->getConfig()->getComponentByType(GridFieldPaginator::class)
78
        );
79
    }
80
81
    /**
82
     * Test that the entry and level fields are displayed in the GridField, and can be exported
83
     */
84
    public function testEntryAndLevelShouldBeInSummaryFields()
85
    {
86
        $summaryFields = $this->logViewerAdmin->getExportFields();
87
        $this->assertContains('Entry', $summaryFields);
88
        $this->assertContains('Level', $summaryFields);
89
    }
90
91
    /**
92
     * Get the test GridField's config class
93
     *
94
     * @return \SilverStripe\Forms\GridField\GridFieldConfig
95
     */
96
    protected function getConfig()
97
    {
98
        return $this->logViewerAdmin
99
            ->getEditForm()
100
            ->Fields()
101
            ->fieldByName($this->logViewerAdmin->getGridFieldName())
102
            ->getConfig();
103
    }
104
}
105