@@ -23,21 +23,31 @@ class ConditionalFieldsTestCase extends BackdropWebTestCase {
23
23
parent::setUp('conditional_fields_test', 'list', 'text', 'number', 'taxonomy', 'image');
24
24
25
25
// Create and log in user.
26
- $web_user = $this->backdropCreateUser(array('create conditional_fields_test content', 'edit any conditional_fields_test content'));
26
+ $web_user = $this->backdropCreateUser(array(
27
+ 'create conditional_fields_test content',
28
+ 'edit any conditional_fields_test content',
29
+ ));
27
30
$this->backdropLogin($web_user);
28
31
29
32
// Create a vocabulary and two terms to test the term reference field.
30
- $vocabulary = new stdClass();
31
- $vocabulary->name = $this->randomName();
32
- $vocabulary->machine_name = backdrop_strtolower($this->randomName());
33
- taxonomy_vocabulary_save($vocabulary);
34
- $term = new stdClass();
35
- $term->name = 'Foo';
36
- $term->vid = $vocabulary->vid;
33
+ $vocabulary = new TaxonomyVocabulary(array(
34
+ 'machine_name' => backdrop_strtolower($this->randomName()),
35
+ 'name' => $this->randomName(),
36
+ ));
37
+ $vocabulary->save();
38
+ $term = array(
39
+ 'name' => 'Foo',
40
+ 'vocabulary' => $vocabulary->machine_name,
41
+ 'parent' => array(0),
42
+ );
43
+ $term = new TaxonomyTerm($term);
37
44
taxonomy_term_save($term);
38
- $term = new stdClass();
39
- $term->name = 'Bar';
40
- $term->vid = $vocabulary->vid;
45
+ $term = array(
46
+ 'name' => 'Bar',
47
+ 'vocabulary' => $vocabulary->machine_name,
48
+ 'parent' => array(0),
49
+ );
50
+ $term = new TaxonomyTerm($term);
41
51
taxonomy_term_save($term);
42
52
43
53
// Create dependee.
@@ -47,7 +57,9 @@ class ConditionalFieldsTestCase extends BackdropWebTestCase {
47
57
'field_name' => 'dependee',
48
58
'type' => 'list_text',
49
59
'settings' => array(
50
- 'allowed_values' => array($this->dependee_on_value => t('Dependent fields are visible'), $this->dependee_off_value => t('Dependent fields are invisible')),
60
+ 'allowed_values' => array(
61
+ $this->dependee_on_value => t('Dependent fields are visible'),
62
+ $this->dependee_off_value => t('Dependent fields are invisible')),
51
63
),
52
64
);
53
65
field_create_field($dependee);
@@ -140,14 +152,28 @@ class ConditionalFieldsTestCase extends BackdropWebTestCase {
140
152
field_create_field($dependent['field']);
141
153
field_create_instance($dependent['instance']);
142
154
$dependent_instance = field_info_instance('node', $dependent['field']['field_name'], 'conditional_fields_test');
143
- conditional_fields_dependency_insert($dependee_instance['id'], $dependent_instance['id'], $dependency_options);
155
+ $dependency = array(
156
+ 'dependee' => $dependee_instance['field_name'],
157
+ 'dependent' => $dependent_instance['field_name'],
158
+ 'options' => $dependency_options,
159
+ 'entity_type' => 'node',
160
+ 'bundle' => 'conditional_fields_test',
161
+ );
162
+ conditional_fields_dependency_insert($dependency);
144
163
}
145
164
}
146
165
147
166
/**
148
167
* Tests field dependencies on a node.
149
168
*/
150
169
public function testNodeDependencies() {
170
+ // Temporarily force re-login.
171
+ $web_user = $this->backdropCreateUser(array(
172
+ 'create conditional_fields_test content',
173
+ 'edit any conditional_fields_test content',
174
+ ));
175
+ $this->backdropLogin($web_user);
176
+
151
177
// Try to submit a node with triggered dependencies.
152
178
// The submit should fail because the dependent fields are required.
153
179
$langcode = LANGUAGE_NONE;
@@ -162,14 +188,19 @@ class ConditionalFieldsTestCase extends BackdropWebTestCase {
162
188
continue;
163
189
}
164
190
// Multiple value textfields are dumb and can't find their own name.
165
- if ($dependent['field']['cardinality'] == -1 && in_array($dependent['widget_type'], array('number', 'text_textfield', 'text_textarea', 'text_textarea_with_summary'))) {
191
+ if ($dependent['field']['cardinality'] == -1 && in_array($dependent['widget_type'], array(
192
+ 'number',
193
+ 'text_textfield',
194
+ 'text_textarea',
195
+ 'text_textarea_with_summary',
196
+ ))) {
166
197
$name = '';
167
198
}
168
199
else {
169
200
$name = $dependent['widget_type'] . '_' . $dependent['field_type'] . '_label';
170
201
$name .= $dependent['field']['cardinality'] == -1 ? '_multiple' : '';
171
202
}
172
- $this->assertRaw(t('!name field is required.', array('!name' => $name)), 'Triggered ' . ($dependent['field']['cardinality'] == -1 ? 'multiple' : 'single') . ' value required ' . $dependent['field_type'] . ' dependent with widget ' . $dependent['widget_type'] . ' and no value fails validation');
203
+ $this->assertRaw(t('!name field is required.', array('!name' => $name)), 'Triggered ' . ($dependent['field']['cardinality'] == -1 ? 'multiple' : 'single') . ' value required ' . $dependent['field_type'] . ' dependent with widget ' . $dependent['widget_type'] . ' and no value fails validation (name: ' . $name . ') ');
173
204
}
174
205
175
206
// Fill the dependents with values and save the node.
@@ -207,7 +238,10 @@ class ConditionalFieldsTestCase extends BackdropWebTestCase {
207
238
}
208
239
}
209
240
$this->backdropPost('node/add/conditional-fields-test', $edit, t('Save'));
210
- $this->assertRaw(t('@type %title has been created.', array('@type' => 'Conditional Fields Test Node Type', '%title' => '')), 'Node was created with triggered dependencies.');
241
+ $this->assertRaw(t('@type %title has been created.', array(
242
+ '@type' => 'Conditional Fields Test Node Type',
243
+ '%title' => '',
244
+ )), 'Node was created with triggered dependencies.');
211
245
// Verify that the fields are visible on node view.
212
246
foreach ($this->dependents as $dependent) {
213
247
$this->assertText($dependent['instance']['label'] . ':', 'Triggered ' . ($dependent['field']['cardinality'] == -1 ? 'multiple' : 'single') . ' value ' . $dependent['field_type'] . ' dependent with widget ' . $dependent['widget_type'] . ' is visible on node view');
@@ -240,15 +274,22 @@ class ConditionalFieldsUITestCase extends backdropWebTestCase {
240
274
parent::setUp('conditional_fields_test', 'list', 'text');
241
275
242
276
// Create and log in user.
243
- $web_user = $this->backdropCreateUser(array('access administration pages', 'administer content types', 'administer dependencies'));
277
+ $web_user = $this->backdropCreateUser(array(
278
+ 'access administration pages',
279
+ 'administer content types',
280
+ 'administer dependencies',
281
+ ));
244
282
$this->backdropLogin($web_user);
245
283
246
284
// Create a field that will be used as a dependee.
247
285
$dependee = array(
248
286
'field_name' => 'dependee',
249
287
'type' => 'list_text',
250
288
'settings' => array(
251
- 'allowed_values' => array('on' => t('Dependent is visible'), 'off' => t('Dependent is invisible')),
289
+ 'allowed_values' => array(
290
+ 'on' => t('Dependent is visible'),
291
+ 'off' => t('Dependent is invisible'),
292
+ ),
252
293
),
253
294
);
254
295
field_create_field($dependee);
@@ -280,13 +321,14 @@ class ConditionalFieldsUITestCase extends backdropWebTestCase {
280
321
*/
281
322
public function testDependenciesOverview() {
282
323
$dependee = field_read_instance('node', 'dependee', 'conditional_fields_test');
324
+ $dependent = field_read_instance('node', 'dependent', 'conditional_fields_test');
283
325
$this->backdropGet('admin/structure');
284
326
$this->clickLink(t('Field dependencies'));
285
327
$this->clickLink(t('Node'));
286
328
$this->backdropGet('admin/structure/types/manage/conditional-fields-test');
287
329
$this->clickLink(t('Manage dependencies'));
288
- $this->assertFieldByName('dependee', $dependee['id '], 'The dependee selection field is in the content type dependencies page.');
289
- $this->assertFieldByName('dependent', $dependee['id'] , 'The dependent selection field is in the content type dependencies page.');
330
+ $this->assertFieldByName('dependee', $dependee['field_name '], 'The dependee selection field is in the content type dependencies page.');
331
+ $this->assertFieldByName('dependent', '' , 'The dependent selection field is in the content type dependencies page.');
290
332
}
291
333
292
334
/**
@@ -297,8 +339,8 @@ class ConditionalFieldsUITestCase extends backdropWebTestCase {
297
339
$dependee = field_read_instance('node', 'dependee', 'conditional_fields_test');
298
340
$dependent = field_read_instance('node', 'dependent', 'conditional_fields_test');
299
341
$edit = array(
300
- 'dependee' => $dependee['id '],
301
- 'dependent' => $dependent['id '],
342
+ 'dependee' => $dependee['field_name '],
343
+ 'dependent' => $dependent['field_name '],
302
344
);
303
345
$this->backdropPost('admin/structure/types/manage/conditional-fields-test/dependencies', $edit, t('Add dependency'), array(), array(), 'conditional-fields-dependency-add-form-node-conditional-fields-test');
304
346
@@ -316,8 +358,12 @@ class ConditionalFieldsUITestCase extends backdropWebTestCase {
316
358
)), 'The dependency was updated correctly.');
317
359
318
360
// Delete dependency.
319
- $this->clickLink(t('delete'));
320
- $this->backdropPost(NULL, array(), t('Delete dependency'), array('query' => array('destination' => 'admin/structure/types/manage/conditional-fields-test/dependencies')));
361
+ $this->clickLink(t('Delete'));
362
+ $this->backdropPost(NULL, array(), t('Delete dependency'), array(
363
+ 'query' => array(
364
+ 'destination' => 'admin/structure/types/manage/conditional-fields-test/dependencies',
365
+ ),
366
+ ));
321
367
$this->assertText(t('The dependency has been deleted.'));
322
368
}
323
369
}
0 commit comments