|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* ConfigurablePageTest contains test cases for the module classes |
|
5
|
|
|
* |
|
6
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
|
7
|
|
|
* @package configurablepage |
|
8
|
|
|
*/ |
|
9
|
|
|
class ConfigurablePageTest extends FunctionalTest |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
|
|
protected static $fixture_file = 'ConfigurablePageTest.yml'; |
|
12
|
|
|
|
|
13
|
|
|
public function testGetCMSFields() |
|
14
|
|
|
{ |
|
15
|
|
|
$this->logInWithPermission('EDITOR'); |
|
16
|
|
|
|
|
17
|
|
|
$page = $this->objFromFixture('ConfigurablePage', 'page-1'); |
|
18
|
|
|
$fields = $page->getCMSFields(); |
|
19
|
|
|
|
|
20
|
|
|
$this->assertTrue($fields->dataFieldByName('textfield1') !== null); |
|
|
|
|
|
|
21
|
|
|
$this->assertTrue($page->getCMSValidator()->fieldIsRequired('textfield1')); |
|
|
|
|
|
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function testWriteToField() |
|
25
|
|
|
{ |
|
26
|
|
|
$this->logInWithPermission('EDITOR'); |
|
27
|
|
|
|
|
28
|
|
|
$value = 'Value for text field 1'; |
|
29
|
|
|
$page = $this->objFromFixture('ConfigurablePage', 'page-1'); |
|
30
|
|
|
$page->textfield1 = $value; |
|
31
|
|
|
$page->Content = 'Page content $textfield1'; |
|
32
|
|
|
$page->write(); |
|
33
|
|
|
|
|
34
|
|
|
$page2 = $this->objFromFixture('ConfigurablePage', 'page-1'); |
|
35
|
|
|
$this->assertContains($value, $page2->Content()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testFieldsRendering() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->logInWithPermission('EDITOR'); |
|
41
|
|
|
|
|
42
|
|
|
$page3 = Page::get_by_link('page3'); |
|
43
|
|
|
$memberId = Member::currentUserID(); |
|
44
|
|
|
$values = [ |
|
45
|
|
|
'checkboxgroup' => '2,0', |
|
46
|
|
|
'countryfield' => 'NZ', |
|
47
|
|
|
'dobfield' => '2014-1-1', |
|
48
|
|
|
'memberfield1' => (string)$memberId, |
|
49
|
|
|
'pagetypefield2' => (string)$page3->ID |
|
50
|
|
|
]; |
|
51
|
|
|
|
|
52
|
|
|
$page = $this->objFromFixture('ConfigurablePage', 'page-2'); |
|
53
|
|
|
$page->Content = 'Page content ----->'; |
|
54
|
|
|
foreach ($values as $name => $value) { |
|
55
|
|
|
$page->setField($name, $value); |
|
56
|
|
|
$page->$name = $value; |
|
57
|
|
|
$page->Content .= ' $' . $name; |
|
58
|
|
|
} |
|
59
|
|
|
$page->write(); |
|
60
|
|
|
|
|
61
|
|
|
$content = $page->Content(); |
|
62
|
|
|
|
|
63
|
|
|
$editableFields = $page->getEditableFields(); |
|
64
|
|
|
foreach ($editableFields as $editableField) { |
|
65
|
|
|
$field = $editableField->getFormField(); |
|
66
|
|
|
if (!$field instanceof DatalessField) { |
|
67
|
|
|
$field->value = $page->{$editableField->Name}; |
|
68
|
|
|
$this->assertContains($editableField->getValueAsString(), $content); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.