|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the PageTest class. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
8
|
|
|
* |
|
9
|
|
|
* @version //autogentag// |
|
10
|
|
|
*/ |
|
11
|
|
|
namespace eZ\Publish\Core\Persistence\Legacy\Tests\Content\FieldValue\Converter; |
|
12
|
|
|
|
|
13
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\PageConverter; |
|
14
|
|
|
use eZ\Publish\Core\FieldType\Page\Parts; |
|
15
|
|
|
use eZ\Publish\SPI\Persistence\Content\FieldValue; |
|
16
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue; |
|
17
|
|
|
use PHPUnit_Framework_TestCase; |
|
18
|
|
|
|
|
19
|
|
|
class PageTest extends PHPUnit_Framework_TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
const PAGE_XML_REFERENCE = <<<EOT |
|
22
|
|
|
<?xml version="1.0"?> |
|
23
|
|
|
<page> |
|
24
|
|
|
<zone id="id_6c7f907b831a819ed8562e3ddce5b264"> |
|
25
|
|
|
<block id="id_1e1e355c8da3c92e80354f243c6dd37b"> |
|
26
|
|
|
<name>Campaign</name> |
|
27
|
|
|
<type>Campaign</type> |
|
28
|
|
|
<view>default</view> |
|
29
|
|
|
<overflow_id></overflow_id> |
|
30
|
|
|
<zone_id>6c7f907b831a819ed8562e3ddce5b264</zone_id> |
|
31
|
|
|
</block> |
|
32
|
|
|
<block id="id_250bcab3ea2929edbf72ece096dcdb7a"> |
|
33
|
|
|
<name>Amazon Gallery</name> |
|
34
|
|
|
<type>Gallery</type> |
|
35
|
|
|
<view>default</view> |
|
36
|
|
|
<overflow_id></overflow_id> |
|
37
|
|
|
<zone_id>6c7f907b831a819ed8562e3ddce5b264</zone_id> |
|
38
|
|
|
<item action="add"> |
|
39
|
|
|
<object_id>62</object_id> |
|
40
|
|
|
<node_id>64</node_id> |
|
41
|
|
|
<priority>1</priority> |
|
42
|
|
|
<ts_publication>1393607060</ts_publication> |
|
43
|
|
|
<ts_visible>1393607060</ts_visible> |
|
44
|
|
|
<ts_hidden>1393607060</ts_hidden> |
|
45
|
|
|
<rotation_until>1393607060</rotation_until> |
|
46
|
|
|
<moved_to>42</moved_to> |
|
47
|
|
|
</item> |
|
48
|
|
|
<item action="add" /> |
|
49
|
|
|
</block> |
|
50
|
|
|
<zone_identifier>left</zone_identifier> |
|
51
|
|
|
</zone> |
|
52
|
|
|
<zone id="id_656b2182b4be70f18ca7b44b3fbb6dbe"> |
|
53
|
|
|
<block id="id_4d2f5e57d2a2528b276cd9e776a62e42"> |
|
54
|
|
|
<name>Featured Video</name> |
|
55
|
|
|
<type>Video</type> |
|
56
|
|
|
<view>default</view> |
|
57
|
|
|
<overflow_id></overflow_id> |
|
58
|
|
|
<zone_id>656b2182b4be70f18ca7b44b3fbb6dbe</zone_id> |
|
59
|
|
|
</block> |
|
60
|
|
|
<block id="id_f36743396b8c36f10b467aa52f133e58"> |
|
61
|
|
|
<name>Travel Information</name> |
|
62
|
|
|
<type>ContentGrid</type> |
|
63
|
|
|
<view>default</view> |
|
64
|
|
|
<overflow_id></overflow_id> |
|
65
|
|
|
<zone_id>656b2182b4be70f18ca7b44b3fbb6dbe</zone_id> |
|
66
|
|
|
</block> |
|
67
|
|
|
<zone_identifier>right</zone_identifier> |
|
68
|
|
|
</zone> |
|
69
|
|
|
<zone_layout>2ZonesLayout1</zone_layout> |
|
70
|
|
|
</page> |
|
71
|
|
|
EOT; |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @var \eZ\Publish\Core\FieldType\Page\Parts\Page |
|
75
|
|
|
*/ |
|
76
|
|
|
private $pageReference; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\PageConverter |
|
80
|
|
|
*/ |
|
81
|
|
|
private $converter; |
|
82
|
|
|
|
|
83
|
|
|
protected function setUp() |
|
84
|
|
|
{ |
|
85
|
|
|
parent::setUp(); |
|
86
|
|
|
$this->converter = new PageConverter(); |
|
87
|
|
|
|
|
88
|
|
|
$this->pageReference = new Parts\Page( |
|
89
|
|
|
array( |
|
90
|
|
|
'layout' => '2ZonesLayout1', |
|
91
|
|
|
'zones' => array( |
|
92
|
|
|
new Parts\Zone( |
|
93
|
|
|
array( |
|
94
|
|
|
'id' => '6c7f907b831a819ed8562e3ddce5b264', |
|
95
|
|
|
'identifier' => 'left', |
|
96
|
|
|
'blocks' => array( |
|
97
|
|
|
new Parts\Block( |
|
98
|
|
|
array( |
|
99
|
|
|
'id' => '1e1e355c8da3c92e80354f243c6dd37b', |
|
100
|
|
|
'name' => 'Campaign', |
|
101
|
|
|
'type' => 'Campaign', |
|
102
|
|
|
'view' => 'default', |
|
103
|
|
|
'overflowId' => '', |
|
104
|
|
|
'zoneId' => '6c7f907b831a819ed8562e3ddce5b264', |
|
105
|
|
|
'attributes' => array(), |
|
106
|
|
|
) |
|
107
|
|
|
), |
|
108
|
|
|
new Parts\Block( |
|
109
|
|
|
array( |
|
110
|
|
|
'id' => '250bcab3ea2929edbf72ece096dcdb7a', |
|
111
|
|
|
'name' => 'Amazon Gallery', |
|
112
|
|
|
'type' => 'Gallery', |
|
113
|
|
|
'view' => 'default', |
|
114
|
|
|
'overflowId' => '', |
|
115
|
|
|
'zoneId' => '6c7f907b831a819ed8562e3ddce5b264', |
|
116
|
|
|
'items' => array( |
|
117
|
|
|
new Parts\Item( |
|
118
|
|
|
array( |
|
119
|
|
|
'action' => 'add', |
|
120
|
|
|
'contentId' => '62', |
|
121
|
|
|
'locationId' => '64', |
|
122
|
|
|
'priority' => '1', |
|
123
|
|
|
'publicationDate' => '1393607060', |
|
124
|
|
|
'visibilityDate' => '1393607060', |
|
125
|
|
|
'hiddenDate' => '1393607060', |
|
126
|
|
|
'rotationUntilDate' => '1393607060', |
|
127
|
|
|
'movedTo' => '42', |
|
128
|
|
|
'attributes' => array(), |
|
129
|
|
|
) |
|
130
|
|
|
), |
|
131
|
|
|
new Parts\Item( |
|
132
|
|
|
array( |
|
133
|
|
|
'action' => 'add', |
|
134
|
|
|
'attributes' => array(), |
|
135
|
|
|
) |
|
136
|
|
|
), |
|
137
|
|
|
), |
|
138
|
|
|
'attributes' => array(), |
|
139
|
|
|
) |
|
140
|
|
|
), |
|
141
|
|
|
), |
|
142
|
|
|
) |
|
143
|
|
|
), |
|
144
|
|
|
new Parts\Zone( |
|
145
|
|
|
array( |
|
146
|
|
|
'id' => '656b2182b4be70f18ca7b44b3fbb6dbe', |
|
147
|
|
|
'identifier' => 'right', |
|
148
|
|
|
'blocks' => array( |
|
149
|
|
|
new Parts\Block( |
|
150
|
|
|
array( |
|
151
|
|
|
'id' => '4d2f5e57d2a2528b276cd9e776a62e42', |
|
152
|
|
|
'name' => 'Featured Video', |
|
153
|
|
|
'type' => 'Video', |
|
154
|
|
|
'view' => 'default', |
|
155
|
|
|
'overflowId' => '', |
|
156
|
|
|
'zoneId' => '656b2182b4be70f18ca7b44b3fbb6dbe', |
|
157
|
|
|
'attributes' => array(), |
|
158
|
|
|
) |
|
159
|
|
|
), |
|
160
|
|
|
new Parts\Block( |
|
161
|
|
|
array( |
|
162
|
|
|
'id' => 'f36743396b8c36f10b467aa52f133e58', |
|
163
|
|
|
'name' => 'Travel Information', |
|
164
|
|
|
'type' => 'ContentGrid', |
|
165
|
|
|
'view' => 'default', |
|
166
|
|
|
'overflowId' => '', |
|
167
|
|
|
'zoneId' => '656b2182b4be70f18ca7b44b3fbb6dbe', |
|
168
|
|
|
'attributes' => array(), |
|
169
|
|
|
) |
|
170
|
|
|
), |
|
171
|
|
|
), |
|
172
|
|
|
) |
|
173
|
|
|
), |
|
174
|
|
|
), |
|
175
|
|
|
'attributes' => array(), |
|
176
|
|
|
) |
|
177
|
|
|
); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* Test converting XML to Parts\Page. |
|
182
|
|
|
*/ |
|
183
|
|
|
public function testToFieldValue() |
|
184
|
|
|
{ |
|
185
|
|
|
$storageFieldValue = new StorageFieldValue(array('dataText' => self::PAGE_XML_REFERENCE)); |
|
186
|
|
|
$fieldValue = new FieldValue(); |
|
187
|
|
|
$this->converter->toFieldValue($storageFieldValue, $fieldValue); |
|
188
|
|
|
$this->assertInstanceOf('eZ\\Publish\\Core\\FieldType\\Page\\Parts\\Page', $fieldValue->data); |
|
189
|
|
|
$this->assertEquals($this->pageReference, $fieldValue->data); |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* Test converting Parts\Page to XML. |
|
194
|
|
|
*/ |
|
195
|
|
|
public function testToStorageValue() |
|
196
|
|
|
{ |
|
197
|
|
|
$storageFieldValue = new StorageFieldValue(); |
|
198
|
|
|
$fieldValue = new FieldValue(array('data' => $this->pageReference)); |
|
199
|
|
|
$this->converter->toStorageValue($fieldValue, $storageFieldValue); |
|
200
|
|
|
$this->assertXmlStringEqualsXmlString(self::PAGE_XML_REFERENCE, $storageFieldValue->dataText); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* Test converting from XML to storage and back. |
|
205
|
|
|
*/ |
|
206
|
|
|
public function testFromStorageAndBack() |
|
207
|
|
|
{ |
|
208
|
|
|
$xml = <<<EOF |
|
209
|
|
|
<?xml version="1.0"?> |
|
210
|
|
|
<page> |
|
211
|
|
|
<zone id="id_ee94402090bb170600a8dab9e1bd1c5a"> |
|
212
|
|
|
<block id="id_ef9fee870c65c676b2f7136431b73f37"> |
|
213
|
|
|
<name>My Block</name> |
|
214
|
|
|
<type>my_block_type</type> |
|
215
|
|
|
<view>default</view> |
|
216
|
|
|
<overflow_id></overflow_id> |
|
217
|
|
|
<custom_attributes> |
|
218
|
|
|
<copytext></copytext> |
|
219
|
|
|
</custom_attributes> |
|
220
|
|
|
<rotation> |
|
221
|
|
|
<interval>0</interval> |
|
222
|
|
|
<type>0</type> |
|
223
|
|
|
<value></value> |
|
224
|
|
|
<unit></unit> |
|
225
|
|
|
</rotation> |
|
226
|
|
|
<zone_id>ee94402090bb170600a8dab9e1bd1c5a</zone_id> |
|
227
|
|
|
</block> |
|
228
|
|
|
<zone_identifier>zone_1</zone_identifier> |
|
229
|
|
|
</zone> |
|
230
|
|
|
<zone_layout>my_zone_layout</zone_layout> |
|
231
|
|
|
</page> |
|
232
|
|
|
|
|
233
|
|
|
EOF; |
|
234
|
|
|
|
|
235
|
|
|
$page = $this->converter->restoreValueFromXmlString($xml); |
|
236
|
|
|
$newXml = $this->converter->generateXmlString($page); |
|
237
|
|
|
$this->assertEquals($xml, $newXml); |
|
238
|
|
|
} |
|
239
|
|
|
} |
|
240
|
|
|
|