Skip to content

Commit e625fa8

Browse files
committed
Issue backdrop-contrib#29: Get tests working.
WIP
1 parent 17386cf commit e625fa8

5 files changed

+120
-75
lines changed

tests/.install

-28
This file was deleted.

tests/conditional_fields.test

+70-24
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,31 @@ class ConditionalFieldsTestCase extends BackdropWebTestCase {
2323
parent::setUp('conditional_fields_test', 'list', 'text', 'number', 'taxonomy', 'image');
2424

2525
// 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+
));
2730
$this->backdropLogin($web_user);
2831

2932
// 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);
3744
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);
4151
taxonomy_term_save($term);
4252

4353
// Create dependee.
@@ -47,7 +57,9 @@ class ConditionalFieldsTestCase extends BackdropWebTestCase {
4757
'field_name' => 'dependee',
4858
'type' => 'list_text',
4959
'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')),
5163
),
5264
);
5365
field_create_field($dependee);
@@ -140,14 +152,28 @@ class ConditionalFieldsTestCase extends BackdropWebTestCase {
140152
field_create_field($dependent['field']);
141153
field_create_instance($dependent['instance']);
142154
$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);
144163
}
145164
}
146165

147166
/**
148167
* Tests field dependencies on a node.
149168
*/
150169
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+
151177
// Try to submit a node with triggered dependencies.
152178
// The submit should fail because the dependent fields are required.
153179
$langcode = LANGUAGE_NONE;
@@ -162,14 +188,19 @@ class ConditionalFieldsTestCase extends BackdropWebTestCase {
162188
continue;
163189
}
164190
// 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+
))) {
166197
$name = '';
167198
}
168199
else {
169200
$name = $dependent['widget_type'] . '_' . $dependent['field_type'] . '_label';
170201
$name .= $dependent['field']['cardinality'] == -1 ? '_multiple' : '';
171202
}
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 . ')');
173204
}
174205

175206
// Fill the dependents with values and save the node.
@@ -207,7 +238,10 @@ class ConditionalFieldsTestCase extends BackdropWebTestCase {
207238
}
208239
}
209240
$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.');
211245
// Verify that the fields are visible on node view.
212246
foreach ($this->dependents as $dependent) {
213247
$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 {
240274
parent::setUp('conditional_fields_test', 'list', 'text');
241275

242276
// 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+
));
244282
$this->backdropLogin($web_user);
245283

246284
// Create a field that will be used as a dependee.
247285
$dependee = array(
248286
'field_name' => 'dependee',
249287
'type' => 'list_text',
250288
'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+
),
252293
),
253294
);
254295
field_create_field($dependee);
@@ -280,13 +321,14 @@ class ConditionalFieldsUITestCase extends backdropWebTestCase {
280321
*/
281322
public function testDependenciesOverview() {
282323
$dependee = field_read_instance('node', 'dependee', 'conditional_fields_test');
324+
$dependent = field_read_instance('node', 'dependent', 'conditional_fields_test');
283325
$this->backdropGet('admin/structure');
284326
$this->clickLink(t('Field dependencies'));
285327
$this->clickLink(t('Node'));
286328
$this->backdropGet('admin/structure/types/manage/conditional-fields-test');
287329
$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.');
290332
}
291333

292334
/**
@@ -297,8 +339,8 @@ class ConditionalFieldsUITestCase extends backdropWebTestCase {
297339
$dependee = field_read_instance('node', 'dependee', 'conditional_fields_test');
298340
$dependent = field_read_instance('node', 'dependent', 'conditional_fields_test');
299341
$edit = array(
300-
'dependee' => $dependee['id'],
301-
'dependent' => $dependent['id'],
342+
'dependee' => $dependee['field_name'],
343+
'dependent' => $dependent['field_name'],
302344
);
303345
$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');
304346

@@ -316,8 +358,12 @@ class ConditionalFieldsUITestCase extends backdropWebTestCase {
316358
)), 'The dependency was updated correctly.');
317359

318360
// 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+
));
321367
$this->assertText(t('The dependency has been deleted.'));
322368
}
323369
}

tests/conditional_fields_test.module

-20
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,3 @@
44
* Test Conditional Fields functionality.
55
*/
66

7-
/**
8-
* Implements hook_node_info().
9-
*/
10-
function conditional_fields_test_node_info() {
11-
return array(
12-
'conditional_fields_test' => array(
13-
'name' => t('Conditional Fields Test Node Type'),
14-
'module' => 'conditional_fields_test',
15-
'base' => 'conditional_fields_test',
16-
),
17-
);
18-
}
19-
20-
/**
21-
* Implements hook_autoload_info().
22-
*/
23-
function conditional_fields_test_autoload_info() {
24-
return array(
25-
);
26-
}

tests/config/conditional_fields_test.settings.json

-3
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"_config_name": "node.type.conditional_fields_test",
3+
"type": "conditional_fields_test",
4+
"name": "Conditional Fields Test Node Type",
5+
"base": "node_content",
6+
"module": "node",
7+
"node_preview": "1",
8+
"description": "",
9+
"help": "",
10+
"modified": true,
11+
"disabled": false,
12+
"has_title": true,
13+
"title_label": "Title",
14+
"settings": {
15+
"comment_enabled": false,
16+
"comment_default": "1",
17+
"comment_per_page": "50",
18+
"comment_mode": 1,
19+
"comment_anonymous": 0,
20+
"comment_title_options": "auto",
21+
"comment_user_picture": true,
22+
"comment_form_location": 1,
23+
"comment_preview": "1",
24+
"comment_close_enabled": 0,
25+
"comment_close_days": "14",
26+
"menu_default": 0,
27+
"menu_options": {
28+
"user-menu": 0,
29+
"management": 0,
30+
"main-menu": 0
31+
},
32+
"menu_parent": "main-menu:0",
33+
"status_default": 1,
34+
"scheduling_enabled": 1,
35+
"promote_enabled": 1,
36+
"promote_default": 0,
37+
"sticky_enabled": 1,
38+
"sticky_default": 0,
39+
"revision_enabled": 1,
40+
"revision_default": 0,
41+
"node_preview": "1",
42+
"node_submitted": 1,
43+
"node_submitted_format": "[node:created:medium] by [node:author]",
44+
"node_user_picture": true,
45+
"hidden_path": 0,
46+
"language": 0,
47+
"node_permissions": true
48+
},
49+
"orig_type": "conditional_fields_test"
50+
}

0 commit comments

Comments
 (0)