FakeThisSectionTemplate   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 4 1
1
<?php
2
require_once 'CMSStubs.php';
3
require_once 'Intraface/Kernel.php';
4
require_once 'Intraface/modules/cms/Section.php';
5
require_once 'Intraface/modules/cms/TemplateSection.php';
6
7
class FakeThisSectionTemplate
8
{
9
    public $kernel;
10
    public $cmssite;
11
12
    function __construct($kernel)
13
    {
14
        $this->kernel = $kernel;
15
    }
16
17
    function get()
18
    {
19
        return 1;
20
    }
21
}
22
23
class Testable_CMS_Section extends CMS_Section
24
{
25
26
    protected function getTemplateSection($template_section_id)
27
    {
28
        return new FakeCMSTemplateSection(null);
29
        // return CMS_TemplateSection::factory($this->kernel, 'id', $template_section_id);
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
30
    }
31
}
32
33
class SectionTest extends PHPUnit_Framework_TestCase
34
{
35
36
    private $kernel;
37
    private $page;
38
39
    function setUp()
40
    {
41
        $this->kernel = new Stub_Kernel;
42
        $this->site = new FakeCMSSite($this->kernel);
0 ignored issues
show
Bug introduced by
The property site does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
43
        $this->page = new FakeCMSPage($this->site);
44
    }
45
46
    function saveTemplateSection()
47
    {
48
        $t = new FakeThisSectionTemplate($this->kernel);
49
        $t->cmssite = $this->site;
50
        $template = new CMS_TemplateSection($t);
51
        $template->value['type_key'] = 1;
52
        $data = array('identifier' => uniqid(), 'name' => 'test', 'template_id' => $this->saveTemplate());
53
        $template->save($data);
54
        return $template->getId();
55
    }
56
57
    function saveTemplate()
58
    {
59
        $t = new CMS_Template($this->site);
60
        $data = array('name' => 'test', 'identifier' => 'name');
61
        $t->save($data);
62
        return $t->getId();
63
    }
64
65
    function testFactory()
66
    {
67
        $section = CMS_Section::factory($this->page, 'type', 'shorttext');
68
        $this->assertTrue(is_object($section));
69
    }
70
71
    function testAddParameter()
72
    {
73
        $section = CMS_Section::factory($this->page, 'type', 'shorttext');
74
        // a bit of cheating here :)
75
        $section->value['id'] = 1;
76
        $this->assertTrue($section->addParameter('test', 'test'));
77
    }
78
79
    function testSave()
80
    {
81
        $section = new Testable_CMS_Section($this->page);
82
        $section_array = array(
83
            'type_key' => 1,
84
            'template_section_id' => $this->saveTemplateSection()
85
        );
86
        $this->assertTrue($section->save($section_array) > 0);
87
    }
88
}
89