|
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; |
|
|
|
|
|
|
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(); |
|
|
|
|
|
|
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() |
|
|
|
|
|
|
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
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: