FakeCMSPageSite::get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
require_once 'CMSStubs.php';
3
require_once 'Intraface/modules/cms/Navigation.php';
4
5
class FakeCMSPageSite
6
{
7
    public $kernel;
8
9
    function __construct($kernel)
10
    {
11
        $this->kernel = $kernel;
12
    }
13
14
    function get()
15
    {
16
        return 1;
17
    }
18
}
19
20
class PageTest extends PHPUnit_Framework_TestCase
21
{
22
    protected $db;
23
    private $page;
24
25
    function setUp()
26
    {
27
        $this->db = MDB2::singleton(DB_DSN);
28
        $this->page = new CMS_Page($this->createSite());
29
    }
30
31
    function tearDown()
32
    {
33
        $this->db->query('TRUNCATE cms_template');
34
        $this->db->query('TRUNCATE cms_page');
35
    }
36
37
    function createKernel()
38
    {
39
        $this->kernel = new Stub_Kernel;
0 ignored issues
show
Bug introduced by
The property kernel 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...
40
        $this->kernel->setting->set('intranet', 'cms.stylesheet.default', 'some.css');
41
42
        return $this->kernel;
43
    }
44
45
    function createSite()
46
    {
47
        return new FakeCMSPageSite($this->createKernel());
48
    }
49
50
    function createTemplate()
51
    {
52
        $site = new FakeCMSSite($this->createKernel());
53
        $template = new CMS_Template($site);
54
55
        $template->save(array('name' => 'test', 'identifier' => 'test', 'for_page_type' => array(1, 2, 4)));
56
57
        $this->assertEquals('', $template->error->view());
58
        // $template->getKeywords();
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% 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...
59
60
        // here we should add som keywords to the template.
61
62
        return $template->get('id');
63
    }
64
65
66
67
    function testConstruction()
68
    {
69
        $this->assertTrue(is_object($this->page));
70
    }
71
72 View Code Duplication
    function testSaveSucceedsWithValidValues()
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...
73
    {
74
        $site = new CMS_Site($this->kernel);
75
        $site_array = array(
76
            'name' => 'Tester',
77
            'url' => 'http://localhost/',
78
            'cc_license' => '1'
79
        );
80
        $site->save($site_array);
81
        $this->assertEquals($site_array['name'], $site->get('name'));
82
        $this->assertEquals($site_array['url'], $site->get('url'));
83
        $this->assertEquals($site_array['cc_license'], $site->get('cc_license'));
84
    }
85
86
    function testSaveWithSuccessWithTemplateWithKeywords()
87
    {
88
89
        $template_id = $this->createTemplate();
90
91
        $input = array(
92
            'allow_comments' => 1,
93
            'hidden' => 1,
94
            'page_type' => 'page',
95
            'identifier' => 'test',
96
            'navigation_name' => 'test',
97
            'title' => 'test',
98
            'keywords' => 'search, words',
99
            'description' => 'test page',
100
            'template_id' => $template_id);
101
102
        $this->assertTrue($this->page->save($input) > 0);
103
    }
104
105
    function testDeleteReturnsTrue()
106
    {
107
        $this->assertTrue($this->page->isActive());
108
        $this->assertTrue($this->page->delete());
109
        $this->assertFalse($this->page->isActive());
110
    }
111
112
    function testPublishReturnsTrue()
113
    {
114
        $this->assertFalse($this->page->isPublished());
115
        $this->assertTrue($this->page->publish());
116
        $this->assertTrue($this->page->isPublished());
117
    }
118
119
    function testUnPublishReturnsTrue()
120
    {
121
        $this->assertFalse($this->page->isPublished());
122
        $this->assertTrue($this->page->publish());
123
        $this->assertTrue($this->page->isPublished());
124
        $this->assertTrue($this->page->unpublish());
125
        $this->assertFalse($this->page->isPublished());
126
    }
127
128
    function testGetStatus()
129
    {
130
        $this->assertEquals('draft', $this->page->getStatus());
131
        $this->assertTrue($this->page->setStatus('published'));
132
        $this->assertEquals('published', $this->page->getStatus());
133
    }
134
}
135