|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
4
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
5
|
|
|
* @version //autogentag// |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace eZ\Bundle\EzPublishCoreBundle\Features\Context; |
|
8
|
|
|
|
|
9
|
|
|
use Behat\Behat\Context\Context; |
|
10
|
|
|
use EzSystems\PlatformBehatBundle\Context\RepositoryContext; |
|
11
|
|
|
use eZ\Publish\API\Repository\ContentTypeService; |
|
12
|
|
|
use eZ\Publish\API\Repository\ContentService; |
|
13
|
|
|
use eZ\Publish\API\Repository\Repository; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Sentences for simple Contents creation. |
|
17
|
|
|
*/ |
|
18
|
|
|
class BasicContentContext implements Context |
|
19
|
|
|
{ |
|
20
|
|
|
use RepositoryContext; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Default language. |
|
24
|
|
|
*/ |
|
25
|
|
|
const DEFAULT_LANGUAGE = 'eng-GB'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Content path mapping. |
|
29
|
|
|
*/ |
|
30
|
|
|
private $contentPaths = array(); |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var eZ\Publish\API\Repository\ContentTypeService |
|
34
|
|
|
*/ |
|
35
|
|
|
private $contentTypeService; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var eZ\Publish\API\Repository\ContentService |
|
39
|
|
|
*/ |
|
40
|
|
|
private $contentService; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @injectService $repository @ezpublish.api.repository |
|
44
|
|
|
* @injectService $contentTypeService @ezpublish.api.service.content_type |
|
45
|
|
|
* @injectService $contentService @ezpublish.api.service.content |
|
46
|
|
|
*/ |
|
47
|
|
|
public function __construct( |
|
48
|
|
|
Repository $repository, |
|
49
|
|
|
ContentTypeService $contentTypeService, |
|
50
|
|
|
ContentService $contentService |
|
51
|
|
|
) { |
|
52
|
|
|
$this->setRepository($repository); |
|
53
|
|
|
$this->contentTypeService = $contentTypeService; |
|
|
|
|
|
|
54
|
|
|
$this->contentService = $contentService; |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Creates and publishes a Content. |
|
59
|
|
|
* |
|
60
|
|
|
* @param string $contentType |
|
61
|
|
|
* @param array $fields |
|
62
|
|
|
* @param mixed $parentLocationId |
|
63
|
|
|
* |
|
64
|
|
|
* @return mixed The content's main location id |
|
65
|
|
|
*/ |
|
66
|
|
|
public function createContent($contentType, $fields, $parentLocationId) |
|
67
|
|
|
{ |
|
68
|
|
|
$repository = $this->getRepository(); |
|
|
|
|
|
|
69
|
|
|
$languageCode = self::DEFAULT_LANGUAGE; |
|
70
|
|
|
$content = $this->createContentDraft($parentLocationId, $contentType, $fields, $languageCode); |
|
71
|
|
|
$content = $this->contentService->publishVersion($content->versionInfo); |
|
72
|
|
|
|
|
73
|
|
|
return $content->contentInfo->mainLocationId; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Publishes a content draft. |
|
78
|
|
|
* |
|
79
|
|
|
* @param eZ\Publish\API\Repository\Values\Content\Content $content |
|
80
|
|
|
*/ |
|
81
|
|
|
public function publishDraft(Content $content) |
|
82
|
|
|
{ |
|
83
|
|
|
$this->contentService->publishVersion($content->versionInfo->id); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Creates a content draft. |
|
88
|
|
|
* |
|
89
|
|
|
* @param eZ\Publish\API\Repository\Values\Content\Location $parentLocationId |
|
90
|
|
|
* @param string $contentTypeIdentifier |
|
91
|
|
|
* @param string $languageCode |
|
92
|
|
|
* @param array $fields Fields, as primitives understood by setField |
|
93
|
|
|
* |
|
94
|
|
|
* @return eZ\Publish\API\Repository\Values\Content\Content an unpublished Content draft |
|
95
|
|
|
*/ |
|
96
|
|
|
public function createContentDraft($parentLocationId, $contentTypeIdentifier, $fields, $languageCode = null) |
|
97
|
|
|
{ |
|
98
|
|
|
$languageCode = $languageCode ?: self::DEFAULT_LANGUAGE; |
|
99
|
|
|
$repository = $this->getRepository(); |
|
100
|
|
|
$locationCreateStruct = $repository->getLocationService()->newLocationCreateStruct($parentLocationId); |
|
101
|
|
|
$contentTypeIdentifier = $this->contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier); |
|
102
|
|
|
$contentCreateStruct = $this->contentService->newContentCreateStruct($contentTypeIdentifier, $languageCode); |
|
103
|
|
|
foreach (array_keys($fields) as $key) { |
|
104
|
|
|
$contentCreateStruct->setField($key, $fields[$key]); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
return $this->contentService->createContent($contentCreateStruct, array($locationCreateStruct)); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Creates and publishes a content at a given path. |
|
112
|
|
|
* Non-existing path items are created as folders named after the path element. |
|
113
|
|
|
* |
|
114
|
|
|
* @param string $path The content path |
|
115
|
|
|
* @param array $fields |
|
116
|
|
|
* @param mixed $contentType The content type identifier |
|
117
|
|
|
* |
|
118
|
|
|
* @return mixed location id of the created content |
|
119
|
|
|
*/ |
|
120
|
|
|
public function createContentWithPath($path, $fields, $contentType) |
|
121
|
|
|
{ |
|
122
|
|
|
$contentsName = explode('/', $path); |
|
123
|
|
|
$currentPath = ''; |
|
124
|
|
|
$location = '2'; |
|
125
|
|
|
foreach ($contentsName as $name) { |
|
126
|
|
|
if ($name != end($contentsName)) { |
|
127
|
|
|
$location = $this->createContent('folder', ['name' => $name], $location); |
|
128
|
|
|
} |
|
129
|
|
|
if ($currentPath != '') { |
|
130
|
|
|
$currentPath .= '/'; |
|
131
|
|
|
} |
|
132
|
|
|
$currentPath .= $name; |
|
133
|
|
|
$this->mapContentPath($currentPath); |
|
134
|
|
|
} |
|
135
|
|
|
$location = $this->createContent($contentType, $fields, $location); |
|
136
|
|
|
|
|
137
|
|
|
return $location; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Getter for contentPaths. |
|
142
|
|
|
*/ |
|
143
|
|
|
public function getContentPath($name) |
|
144
|
|
|
{ |
|
145
|
|
|
return $this->contentPaths[$name]; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Maps the path of the content to it's name for later use. |
|
150
|
|
|
*/ |
|
151
|
|
|
private function mapContentPath($path) |
|
152
|
|
|
{ |
|
153
|
|
|
$contentNames = explode('/', $path); |
|
154
|
|
|
$this->contentPaths[end($contentNames)] = $path; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @Given a/an :path folder exists |
|
159
|
|
|
*/ |
|
160
|
|
|
public function createBasicFolder($path) |
|
161
|
|
|
{ |
|
162
|
|
|
$fields = array('name' => $this->getTitleFromPath($path)); |
|
163
|
|
|
|
|
164
|
|
|
return $this->createContentwithPath($path, $fields, 'folder'); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* @Given a/an :path article exists |
|
169
|
|
|
*/ |
|
170
|
|
View Code Duplication |
public function createBasicArticle($path) |
|
171
|
|
|
{ |
|
172
|
|
|
$fields = array( |
|
173
|
|
|
'title' => $this->getTitleFromPath($path), |
|
174
|
|
|
'intro' => $this->getDummyXmlText(), |
|
175
|
|
|
); |
|
176
|
|
|
|
|
177
|
|
|
return $this->createContentwithPath($path, $fields, 'article'); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* @Given a/an :path article draft exists |
|
182
|
|
|
*/ |
|
183
|
|
View Code Duplication |
public function createArticleDraft($path) |
|
184
|
|
|
{ |
|
185
|
|
|
$fields = array( |
|
186
|
|
|
'title' => $this->getTitleFromPath($path), |
|
187
|
|
|
'intro' => $this->getDummyXmlText(), |
|
188
|
|
|
); |
|
189
|
|
|
|
|
190
|
|
|
return $this->createContentDraft(2, 'article', $fields); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
private function getTitleFromPath($path) |
|
194
|
|
|
{ |
|
195
|
|
|
$parts = explode('/', rtrim($path, '/')); |
|
196
|
|
|
|
|
197
|
|
|
return end($parts); |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* @return string |
|
202
|
|
|
*/ |
|
203
|
|
|
private function getDummyXmlText() |
|
204
|
|
|
{ |
|
205
|
|
|
return '<?xml version="1.0" encoding="UTF-8"?><section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ezxhtml="http://ez.no/xmlns/ezpublish/docbook/xhtml" xmlns:ezcustom="http://ez.no/xmlns/ezpublish/docbook/custom" version="5.0-variant ezpublish-1.0"><para>This is a paragraph.</para></section>'; |
|
206
|
|
|
} |
|
207
|
|
|
} |
|
208
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..