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); |
|
|
|
|
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); |
|
|
|
|
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
|
|
|
|
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.