Completed
Pull Request — master (#15)
by Simon
02:03
created

LogEntryTest::testAllowEditing()   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\Model;
4
5
use SilverLeague\LogViewer\Model\LogEntry;
6
use SilverStripe\Dev\SapphireTest;
7
use SilverStripe\Security\Security;
8
9
/**
10
 * @package silverstripe-logviewer
11
 * @author  Robbie Averill <[email protected]>
12
 */
13
class LogEntryTest extends SapphireTest
14
{
15
    /**
16
     * Create a default admin, so we can test permissions
17
     */
18
    public function setUp()
19
    {
20
        parent::setUp();
21
        Security::setDefaultAdmin('admin', 'PassWord!');
22
    }
23
24
    /**
25
     * Test that LogEntry classes can not be edited
26
     */
27
    public function testDoNotAllowEditing()
28
    {
29
        $this->assertFalse(LogEntry::create()->canEdit());
30
    }
31
32
    /**
33
     * There's no reason to manually create, so don't allow manual creation
34
     */
35 View Code Duplication
    public function testAllowCreate()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37
        $createFalse = LogEntry::create()->canCreate(null);
38
        $this->assertFalse($createFalse);
39
        $this->logInWithPermission('ADMIN');
40
        $createFalse = LogEntry::create()->canCreate();
41
        $this->assertFalse($createFalse);
42
43
    }
0 ignored issues
show
Coding Style introduced by
Function closing brace must go on the next line following the body; found 1 blank lines before brace
Loading history...
44
45
    public function testProvidePermissions()
46
    {
47
        $permissions = LogEntry::create()->providePermissions();
48
        $this->assertTrue(is_array($permissions));
49
    }
50
51
    /**
52
     * Test that LogEntry classes can not be edited
53
     */
54
    public function testAllowEditing()
55
    {
56
        $this->assertFalse(LogEntry::create()->canEdit());
57
    }
58
59
    /**
60
     * We can view if we're logged in as admin. Otherwise, no.
61
     */
62 View Code Duplication
    public function testAllowView()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
    {
64
        $viewFalse = LogEntry::create()->canView(null);
65
        $this->assertFalse($viewFalse);
66
        $this->logInWithPermission('ADMIN');
67
        $viewTrue = LogEntry::create()->canView();
68
        $this->assertTrue($viewTrue);
69
    }
70
71
    /**
72
     * We can Delete if we're logged in as admin. Otherwise, no.
73
     */
74 View Code Duplication
    public function testAllowDelete()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
    {
76
        $deleteFalse = LogEntry::create()->canDelete(null);
77
        $this->assertFalse($deleteFalse);
78
        $this->logInWithPermission('ADMIN');
79
        $deleteTrue = LogEntry::create()->canDelete();
80
        $this->assertTrue($deleteTrue);
81
    }
82
83
}
84