PageControllerTemplateOverrideExtensionTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 56 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%
Metric Value
wmc 3
lcom 1
cbo 2
dl 28
loc 50
ccs 36
cts 36
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testLayoutTemplateOveride() 14 15 1
A testOuterTemplateOveride() 14 15 1
A testNoTemplateOverride() 0 13 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
class PageControllerTemplateOverrideExtensionTest extends FunctionalTest
4
{
5
    protected static $fixture_file = 'template-override/tests/pages.yml';
6
7 1 View Code Duplication
    public function testLayoutTemplateOveride()
8
    {
9 1
        $this->logInWithPermission('ADMIN');
10 1
        $page = $this->objFromFixture('Page', 'page1');
11 1
        $page->AlternativeTemplate = 'PageInnerTest';
12 1
        $page->write();
13 1
        $page->doPublish();
14 1
        $response = $this->get('/'.$page->URLSegment);
15 1
        $this->assertEquals(200, $response->getStatusCode());
16
17
        // assert the the inner layout template has been used
18 1
        $this->assertExactMatchBySelector('div.marker', array(
19 1
            'INNER LAYOUT',
20 1
        ));
21 1
    }
22
23 1 View Code Duplication
    public function testOuterTemplateOveride()
24
    {
25 1
        $this->logInWithPermission('ADMIN');
26 1
        $page = $this->objFromFixture('Page', 'page1');
27 1
        $page->AlternativeTemplate = 'PageOuterTest';
28 1
        $page->write();
29 1
        $page->doPublish();
30 1
        $response = $this->get('/'.$page->URLSegment);
31 1
        $this->assertEquals(200, $response->getStatusCode());
32
33
        // show the the outer layout template has been used
34 1
        $this->assertExactMatchBySelector('div.marker', array(
35 1
            'OUTER OF LAYOUT',
36 1
        ));
37 1
    }
38
39 1
    public function testNoTemplateOverride()
40
    {
41 1
        $this->logInWithPermission('ADMIN');
42 1
        $page = $this->objFromFixture('Page', 'page1');
43 1
        $page->AlternativeTemplate = null;
44 1
        $page->write();
45 1
        $page->doPublish();
46 1
        $response = $this->get('/'.$page->URLSegment);
47 1
        $this->assertEquals(200, $response->getStatusCode());
48 1
        $body = $response->getBody();
49 1
        $this->assertNotContains('OUTER OF LAYOUT', $body);
50 1
        $this->assertNotContains('INNER LAYOUT', $body);
51 1
    }
52
}
53