forked from ezsystems/PlatformUIBundle
/
Fields.php
204 lines (186 loc) · 6.53 KB
/
Fields.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
/**
* File containing the Common Functions for context class PlatformUI.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
* @version //autogentag//
*/
namespace EzSystems\PlatformUIBundle\Features\Context\SubContext;
use EzSystems\BehatBundle\ObjectManager\FieldType;
use Behat\Mink\WebAssert;
trait Fields
{
/**
* @When I create a content of this type
*/
public function createAContentOfThisType()
{
$fieldManager = $this->getFieldTypeManager();
$fieldManager->setFieldContentState(FieldType::CONTENT_TYPE_PUBLISHED);
$type = $fieldManager->getThisContentTypeName('eng-GB');
$this->loggedAsUserPlatformUi();
$this->clickNavigationZone('Platform');
$this->waitForLoadings();
$this->clickNavigationItem('Content structure');
$this->waitForLoadings();
$this->clickActionBar('Create a content');
$this->waitForLoadings();
$this->clickContentType($type);
$this->waitForLoadings();
$this->platformStatus = self::WAITING_FOR_PUBLISHING;
}
/**
* @When I edit this content
*/
public function editThisContent()
{
$fieldManager = $this->getFieldTypeManager();
$fieldManager->setFieldContentState(FieldType::CONTENT_PUBLISHED);
$name = $fieldManager->getThisContentName('eng-GB');
$this->loggedAsUserPlatformUi();
$this->clickNavigationZone('Platform');
$this->waitForLoadings();
$this->clickNavigationItem('Content structure');
$this->waitForLoadings();
$this->openTreePath($name);
$this->waitForLoadings();
$this->clickActionBar('Edit');
$this->waitForLoadings();
$this->platformStatus = self::WAITING_FOR_PUBLISHING;
}
/**
* @When I view this Content
*/
public function viewThisContent()
{
$fieldManager = $this->getFieldTypeManager();
$fieldManager->setFieldContentState(FieldType::CONTENT_PUBLISHED);
$name = $fieldManager->getThisContentName('eng-GB');
$this->loggedAsUserPlatformUi();
$this->clickNavigationZone('Platform');
$this->waitForLoadings();
$this->clickNavigationItem('Content structure');
$this->waitForLoadings();
$this->openTreePath($name);
$this->waitForLoadings();
}
/**
* @When I set :value as the Field Value
* @And I set :value as the Field Value
*/
public function setFieldValue($value)
{
$fieldManager = $this->getFieldTypeManager();
$name = $fieldManager->getThisFieldTypeName('eng-GB');
$this->fillFieldWithValue($name, $value);
}
/**
* @When I publish the content
* @And I publish the content
*/
public function publishContent()
{
if ($this->platformStatus == self::WAITING_FOR_PUBLISHING) {
$this->clickEditActionBar('Publish');
} else {
throw new \Exception('Cannot publish content, application in wrong state');
}
}
/**
* @When I check the Field Value
* @And I check the Field Value
*/
public function checkFieldValue()
{
if ($this->platformStatus == self::WAITING_FOR_PUBLISHING) {
$fieldManager = $this->getFieldTypeManager();
$name = $fieldManager->getThisFieldTypeName('eng-GB');
$this->checkOption($name);
} else {
throw new \Exception('Cannot publish content, application in wrong state');
}
}
/**
* @When I uncheck the Field Value
* @And I uncheck the Field Value
*/
public function uncheckFieldValue()
{
if ($this->platformStatus == self::WAITING_FOR_PUBLISHING) {
$fieldManager = $this->getFieldTypeManager();
$name = $fieldManager->getThisFieldTypeName('eng-GB');
$this->uncheckOption($name);
} else {
throw new \Exception('Cannot publish content, application in wrong state');
}
}
/**
* @Then I should see an/a :type field
* @Then I should see an/a :label label related with the :type field
*/
public function seeFieldtOfType($type, $label = null)
{
$this->executeDelayedActions();
$verification = new WebAssert($this->getSession());
$internalName = $this->getFieldTypeManager()->getFieldTypeInternalIdentifier($type);
$selector = ".ez-fieldview-$internalName";
$verification->elementExists('css', $selector);
if ($label != null) {
$verification->elementTextContains('css', '.ez-fieldview-name', $label);
}
}
/**
* @Then I should see an/a field with value :value
*/
public function seeFieldtWithValue($value)
{
$this->executeDelayedActions();
$verification = new WebAssert($this->getSession());
$verification->elementTextContains('css', '.ez-fieldview-value-content', $value);
}
/**
* @Then the :label field should be marked as mandatory
*/
public function seeRequiredFieldtOfType($label)
{
if ($this->platformStatus == self::WAITING_FOR_PUBLISHING) {
$verification = new WebAssert($this->getSession());
$verification->elementTextContains('css', '.ez-fielddefinition-name', $label . '*');
} else {
throw new \Exception('Cannot publish content, application in wrong state');
}
}
/**
* @Given I set an/a empty value as the Field Value
* @And I set an/a empty value as the Field Value
*/
public function setFieldValueToNothing()
{
$this->setFieldValue('');
}
/**
* @Then Publishing fails with validation error message :messege
*
* Creates a Content with the previously defined ContentType
*/
public function failsWithMessage($message)
{
$verification = new WebAssert($this->getSession());
$verification->elementTextContains('css', '.ez-editfield-error-message', $message);
}
/**
* @Then the Content is successfully published
*/
public function contentIsPublished()
{
$page = $this->getSession()->getPage();
$errors = $page->findAll('css', '.ez-editfield-error-message');
foreach ($errors as $error) {
$errorMessage = $error->getText();
if ($errorMessage != '') {
throw new \Exception("Content could not be published with error message: $errorMessage");
}
}
}
}