Completed
Push — master ( caf2b3...e6bed0 )
by Robbie
25s
created

LogEntryTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 43.1 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 2
dl 25
loc 58
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testProvidePermissions() 0 7 1
A testAllowCreate() 8 8 1
A testAllowEditing() 0 4 1
A testAllowView() 8 8 1
A testAllowDelete() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
     * Test if the Permissions are an array and contain the view and delete permissions
17
     */
18
    public function testProvidePermissions()
19
    {
20
        $permissions = LogEntry::create()->providePermissions();
21
        $this->assertTrue(is_array($permissions));
22
        $this->assertTrue(array_key_exists('DELETE_ENTRY', $permissions));
23
        $this->assertTrue(array_key_exists('VIEW_ENTRY', $permissions));
24
    }
25
26
    /**
27
     * There's no reason to manually create, so don't allow manual creation
28
     */
29 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...
30
    {
31
        $createFalse = LogEntry::create()->canCreate(null);
32
        $this->assertFalse($createFalse);
33
        $this->logInWithPermission('ADMIN');
34
        $createFalse = LogEntry::create()->canCreate();
35
        $this->assertFalse($createFalse);
36
    }
37
38
    /**
39
     * Test that LogEntry classes can not be edited
40
     */
41
    public function testAllowEditing()
42
    {
43
        $this->assertFalse(LogEntry::create()->canEdit());
44
    }
45
46
    /**
47
     * We can view if we're logged in as admin. Otherwise, no.
48
     */
49 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...
50
    {
51
        $viewFalse = LogEntry::create()->canView(null);
52
        $this->assertFalse($viewFalse);
53
        $this->logInWithPermission('ADMIN');
54
        $viewTrue = LogEntry::create()->canView();
55
        $this->assertTrue($viewTrue);
56
    }
57
58
    /**
59
     * We can Delete if we're logged in as admin. Otherwise, no.
60
     */
61 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...
62
    {
63
        $deleteFalse = LogEntry::create()->canDelete(null);
64
        $this->assertFalse($deleteFalse);
65
        $this->logInWithPermission('ADMIN');
66
        $deleteTrue = LogEntry::create()->canDelete();
67
        $this->assertTrue($deleteTrue);
68
    }
69
70
}
71