PageElementTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 104
Duplicated Lines 42.31 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
dl 44
loc 104
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 6

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 8 8 1
A tearDown() 0 4 1
A testConstruction() 0 4 1
A testSave() 17 17 1
B testSaveWhenUpdating() 0 32 1
A testValidateFailsWhenInvalidValues() 18 18 1
A testDeleteReturnsTrue() 0 4 1
A testUnDeleteReturnsTrue() 0 5 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
require_once 'CMSStubs.php';
3
require_once 'Intraface/modules/cms/Element.php';
4
5
class PageElementTest extends PHPUnit_Framework_TestCase
6
{
7
    private $pagelist;
8
9 View Code Duplication
    function setUp()
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...
10
    {
11
        $kernel = new Stub_Kernel();
12
        $site = new FakeCMSSite($kernel);
13
        $page = new FakeCMSPage($site);
14
        $section = new FakeCMSSection($page);
15
        $this->pagelist = new Intraface_modules_cms_element_Pagelist($section);
16
    }
17
18
    function tearDown()
19
    {
20
        unset($this->pagelist);
21
    }
22
23
    function testConstruction()
24
    {
25
        $this->assertTrue(is_object($this->pagelist));
26
    }
27
28 View Code Duplication
    function testSave()
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...
29
    {
30
        $data = array(
31
            'elm_properties' => 'none',
32
            'elm_adjust' => 'left',
33
            'elm_width' => '100px',
34
            'headline' => 'Test',
35
            'show_type' => 'article',
36
            'keyword' => array(1),
37
            'show' => 1,
38
            'lifetime' => 20,
39
            'no_results_text' => 'none',
40
            'read_more_text' => 'none'
41
        );
42
43
        $this->assertTrue($this->pagelist->save($data) > 0);
44
    }
45
46
    function testSaveWhenUpdating()
47
    {
48
        $data = array(
49
            'elm_properties' => 'none',
50
            'elm_adjust' => 'left',
51
            'elm_width' => '100px',
52
            'headline' => 'Test',
53
            'show_type' => 'article',
54
            'keyword' => array(1),
55
            'show' => 1,
56
            'lifetime' => 20,
57
            'no_results_text' => 'none',
58
            'read_more_text' => 'none'
59
        );
60
61
        $this->assertTrue($this->pagelist->save($data) > 0);
62
63
        $data = array(
64
            'elm_properties' => 'none',
65
            'elm_adjust' => 'left',
66
            'elm_width' => '100px',
67
            'headline' => 'Test',
68
            'show_type' => 'article',
69
            'keyword' => array(1),
70
            'show' => 1,
71
            'lifetime' => 20,
72
            'no_results_text' => 'none',
73
            'read_more_text' => 'none'
74
        );
75
76
        $this->assertTrue($this->pagelist->save($data) > 0);
77
    }
78
79 View Code Duplication
    function testValidateFailsWhenInvalidValues()
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...
80
    {
81
        $data = array(
82
            'elm_properties' => 'wrongvalue',
83
            'elm_adjust' => 'wrongvalue',
84
            'elm_width' => '100wrongvalue',
85
            'elm_box' => 'wrongvalue',
86
            'headline' => 'Test',
87
            'show_type' => 'article',
88
            'keyword' => array(1),
89
            'show' => 1,
90
            'lifetime' => 20,
91
            'no_results_text' => 'none',
92
            'read_more_text' => 'none'
93
        );
94
95
        $this->assertTrue($this->pagelist->save($data) == 0);
96
    }
97
98
    function testDeleteReturnsTrue()
99
    {
100
        $this->assertTrue($this->pagelist->delete());
101
    }
102
103
    function testUnDeleteReturnsTrue()
104
    {
105
        $this->assertTrue($this->pagelist->delete());
106
        $this->assertTrue($this->pagelist->undelete());
107
    }
108
}
109