Projet

Général

Profil

Paste
Télécharger (22,8 ko) Statistiques
| Branche: | Révision:

root / drupal7 / modules / field / modules / options / options.test @ 01dfd3b5

1
<?php
2

    
3
/**
4
 * @file
5
 * Tests for options.module.
6
 */
7

    
8
class OptionsWidgetsTestCase extends FieldTestCase {
9
  public static function getInfo() {
10
    return array(
11
      'name'  => 'Options widgets',
12
      'description'  => "Test the Options widgets.",
13
      'group' => 'Field types'
14
    );
15
  }
16

    
17
  function setUp() {
18
    parent::setUp('field_test', 'list_test');
19

    
20
    // Field with cardinality 1.
21
    $this->card_1 = array(
22
      'field_name' => 'card_1',
23
      'type' => 'list_integer',
24
      'cardinality' => 1,
25
      'settings' => array(
26
        'allowed_values' => array(
27
          // Make sure that 0 works as an option.
28
          0 => 'Zero',
29
          1 => 'One',
30
          // Make sure that option text is properly sanitized.
31
          2 => 'Some <script>dangerous</script> & unescaped <strong>markup</strong>',
32
          // Make sure that HTML entities in option text are not double-encoded.
33
          3 => 'Some HTML encoded markup with &lt; &amp; &gt;',
34
        ),
35
      ),
36
    );
37
    $this->card_1 = field_create_field($this->card_1);
38

    
39
    // Field with cardinality 2.
40
    $this->card_2 = array(
41
      'field_name' => 'card_2',
42
      'type' => 'list_integer',
43
      'cardinality' => 2,
44
      'settings' => array(
45
        'allowed_values' => array(
46
          // Make sure that 0 works as an option.
47
          0 => 'Zero',
48
          1 => 'One',
49
          // Make sure that option text is properly sanitized.
50
          2 => 'Some <script>dangerous</script> & unescaped <strong>markup</strong>',
51
        ),
52
      ),
53
    );
54
    $this->card_2 = field_create_field($this->card_2);
55

    
56
    // Boolean field.
57
    $this->bool = array(
58
      'field_name' => 'bool',
59
      'type' => 'list_boolean',
60
      'cardinality' => 1,
61
      'settings' => array(
62
        'allowed_values' => array(
63
          // Make sure that 1 works as a 'on' value'.
64
          1 => 'Zero',
65
          // Make sure that option text is properly sanitized.
66
          0 => 'Some <script>dangerous</script> & unescaped <strong>markup</strong>',
67
        ),
68
      ),
69
    );
70
    $this->bool = field_create_field($this->bool);
71

    
72
    // Create a web user.
73
    $this->web_user = $this->drupalCreateUser(array('access field_test content', 'administer field_test content', 'administer fields'));
74
    $this->drupalLogin($this->web_user);
75
  }
76

    
77
  /**
78
   * Tests the 'options_buttons' widget (single select).
79
   */
80
  function testRadioButtons() {
81
    // Create an instance of the 'single value' field.
82
    $instance = array(
83
      'field_name' => $this->card_1['field_name'],
84
      'entity_type' => 'test_entity',
85
      'bundle' => 'test_bundle',
86
      'widget' => array(
87
        'type' => 'options_buttons',
88
      ),
89
    );
90
    $instance = field_create_instance($instance);
91
    $langcode = LANGUAGE_NONE;
92

    
93
    // Create an entity.
94
    $entity_init = field_test_create_stub_entity();
95
    $entity = clone $entity_init;
96
    $entity->is_new = TRUE;
97
    field_test_entity_save($entity);
98

    
99
    // With no field data, no buttons are checked.
100
    $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
101
    $this->assertNoFieldChecked("edit-card-1-$langcode-0");
102
    $this->assertNoFieldChecked("edit-card-1-$langcode-1");
103
    $this->assertNoFieldChecked("edit-card-1-$langcode-2");
104
    $this->assertRaw('Some dangerous &amp; unescaped <strong>markup</strong>', 'Option text was properly filtered.');
105

    
106
    // Select first option.
107
    $edit = array("card_1[$langcode]" => 0);
108
    $this->drupalPost(NULL, $edit, t('Save'));
109
    $this->assertFieldValues($entity_init, 'card_1', $langcode, array(0));
110

    
111
    // Check that the selected button is checked.
112
    $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
113
    $this->assertFieldChecked("edit-card-1-$langcode-0");
114
    $this->assertNoFieldChecked("edit-card-1-$langcode-1");
115
    $this->assertNoFieldChecked("edit-card-1-$langcode-2");
116

    
117
    // Unselect option.
118
    $edit = array("card_1[$langcode]" => '_none');
119
    $this->drupalPost(NULL, $edit, t('Save'));
120
    $this->assertFieldValues($entity_init, 'card_1', $langcode, array());
121

    
122
    // Check that required radios with one option is auto-selected.
123
    $this->card_1['settings']['allowed_values'] = array(99 => 'Only allowed value');
124
    field_update_field($this->card_1);
125
    $instance['required'] = TRUE;
126
    field_update_instance($instance);
127
    $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
128
    $this->assertFieldChecked("edit-card-1-$langcode-99");
129
  }
130

    
131
  /**
132
   * Tests the 'options_buttons' widget (multiple select).
133
   */
134
  function testCheckBoxes() {
135
    // Create an instance of the 'multiple values' field.
136
    $instance = array(
137
      'field_name' => $this->card_2['field_name'],
138
      'entity_type' => 'test_entity',
139
      'bundle' => 'test_bundle',
140
      'widget' => array(
141
        'type' => 'options_buttons',
142
      ),
143
    );
144
    $instance = field_create_instance($instance);
145
    $langcode = LANGUAGE_NONE;
146

    
147
    // Create an entity.
148
    $entity_init = field_test_create_stub_entity();
149
    $entity = clone $entity_init;
150
    $entity->is_new = TRUE;
151
    field_test_entity_save($entity);
152

    
153
    // Display form: with no field data, nothing is checked.
154
    $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
155
    $this->assertNoFieldChecked("edit-card-2-$langcode-0");
156
    $this->assertNoFieldChecked("edit-card-2-$langcode-1");
157
    $this->assertNoFieldChecked("edit-card-2-$langcode-2");
158
    $this->assertRaw('Some dangerous &amp; unescaped <strong>markup</strong>', 'Option text was properly filtered.');
159

    
160
    // Submit form: select first and third options.
161
    $edit = array(
162
      "card_2[$langcode][0]" => TRUE,
163
      "card_2[$langcode][1]" => FALSE,
164
      "card_2[$langcode][2]" => TRUE,
165
    );
166
    $this->drupalPost(NULL, $edit, t('Save'));
167
    $this->assertFieldValues($entity_init, 'card_2', $langcode, array(0, 2));
168

    
169
    // Display form: check that the right options are selected.
170
    $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
171
    $this->assertFieldChecked("edit-card-2-$langcode-0");
172
    $this->assertNoFieldChecked("edit-card-2-$langcode-1");
173
    $this->assertFieldChecked("edit-card-2-$langcode-2");
174

    
175
    // Submit form: select only first option.
176
    $edit = array(
177
      "card_2[$langcode][0]" => TRUE,
178
      "card_2[$langcode][1]" => FALSE,
179
      "card_2[$langcode][2]" => FALSE,
180
    );
181
    $this->drupalPost(NULL, $edit, t('Save'));
182
    $this->assertFieldValues($entity_init, 'card_2', $langcode, array(0));
183

    
184
    // Display form: check that the right options are selected.
185
    $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
186
    $this->assertFieldChecked("edit-card-2-$langcode-0");
187
    $this->assertNoFieldChecked("edit-card-2-$langcode-1");
188
    $this->assertNoFieldChecked("edit-card-2-$langcode-2");
189

    
190
    // Submit form: select the three options while the field accepts only 2.
191
    $edit = array(
192
      "card_2[$langcode][0]" => TRUE,
193
      "card_2[$langcode][1]" => TRUE,
194
      "card_2[$langcode][2]" => TRUE,
195
    );
196
    $this->drupalPost(NULL, $edit, t('Save'));
197
    $this->assertText('this field cannot hold more than 2 values', 'Validation error was displayed.');
198

    
199
    // Submit form: uncheck all options.
200
    $edit = array(
201
      "card_2[$langcode][0]" => FALSE,
202
      "card_2[$langcode][1]" => FALSE,
203
      "card_2[$langcode][2]" => FALSE,
204
    );
205
    $this->drupalPost(NULL, $edit, t('Save'));
206
    // Check that the value was saved.
207
    $this->assertFieldValues($entity_init, 'card_2', $langcode, array());
208

    
209
    // Required checkbox with one option is auto-selected.
210
    $this->card_2['settings']['allowed_values'] = array(99 => 'Only allowed value');
211
    field_update_field($this->card_2);
212
    $instance['required'] = TRUE;
213
    field_update_instance($instance);
214
    $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
215
    $this->assertFieldChecked("edit-card-2-$langcode-99");
216
  }
217

    
218
  /**
219
   * Tests the 'options_select' widget (single select).
220
   */
221
  function testSelectListSingle() {
222
    // Create an instance of the 'single value' field.
223
    $instance = array(
224
      'field_name' => $this->card_1['field_name'],
225
      'entity_type' => 'test_entity',
226
      'bundle' => 'test_bundle',
227
      'required' => TRUE,
228
      'widget' => array(
229
        'type' => 'options_select',
230
      ),
231
    );
232
    $instance = field_create_instance($instance);
233
    $langcode = LANGUAGE_NONE;
234

    
235
    // Create an entity.
236
    $entity_init = field_test_create_stub_entity();
237
    $entity = clone $entity_init;
238
    $entity->is_new = TRUE;
239
    field_test_entity_save($entity);
240

    
241
    // Display form.
242
    $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
243
    // A required field without any value has a "none" option.
244
    $this->assertTrue($this->xpath('//select[@id=:id]//option[@value="_none" and text()=:label]', array(':id' => 'edit-card-1-' . $langcode, ':label' => t('- Select a value -'))), 'A required select list has a "Select a value" choice.');
245

    
246
    // With no field data, nothing is selected.
247
    $this->assertNoOptionSelected("edit-card-1-$langcode", '_none');
248
    $this->assertNoOptionSelected("edit-card-1-$langcode", 0);
249
    $this->assertNoOptionSelected("edit-card-1-$langcode", 1);
250
    $this->assertNoOptionSelected("edit-card-1-$langcode", 2);
251
    $this->assertRaw('Some dangerous &amp; unescaped markup', 'Option text was properly filtered.');
252
    $this->assertRaw('Some HTML encoded markup with &lt; &amp; &gt;', 'HTML entities in option text were properly handled and not double-encoded');
253

    
254
    // Submit form: select invalid 'none' option.
255
    $edit = array("card_1[$langcode]" => '_none');
256
    $this->drupalPost(NULL, $edit, t('Save'));
257
    $this->assertRaw(t('!title field is required.', array('!title' => $instance['field_name'])), 'Cannot save a required field when selecting "none" from the select list.');
258

    
259
    // Submit form: select first option.
260
    $edit = array("card_1[$langcode]" => 0);
261
    $this->drupalPost(NULL, $edit, t('Save'));
262
    $this->assertFieldValues($entity_init, 'card_1', $langcode, array(0));
263

    
264
    // Display form: check that the right options are selected.
265
    $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
266
    // A required field with a value has no 'none' option.
267
    $this->assertFalse($this->xpath('//select[@id=:id]//option[@value="_none"]', array(':id' => 'edit-card-1-' . $langcode)), 'A required select list with an actual value has no "none" choice.');
268
    $this->assertOptionSelected("edit-card-1-$langcode", 0);
269
    $this->assertNoOptionSelected("edit-card-1-$langcode", 1);
270
    $this->assertNoOptionSelected("edit-card-1-$langcode", 2);
271

    
272
    // Make the field non required.
273
    $instance['required'] = FALSE;
274
    field_update_instance($instance);
275

    
276
    // Display form.
277
    $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
278
    // A non-required field has a 'none' option.
279
    $this->assertTrue($this->xpath('//select[@id=:id]//option[@value="_none" and text()=:label]', array(':id' => 'edit-card-1-' . $langcode, ':label' => t('- None -'))), 'A non-required select list has a "None" choice.');
280
    // Submit form: Unselect the option.
281
    $edit = array("card_1[$langcode]" => '_none');
282
    $this->drupalPost('test-entity/manage/' . $entity->ftid . '/edit', $edit, t('Save'));
283
    $this->assertFieldValues($entity_init, 'card_1', $langcode, array());
284

    
285
    // Test optgroups.
286

    
287
    $this->card_1['settings']['allowed_values'] = array();
288
    $this->card_1['settings']['allowed_values_function'] = 'list_test_allowed_values_callback';
289
    field_update_field($this->card_1);
290

    
291
    // Display form: with no field data, nothing is selected
292
    $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
293
    $this->assertNoOptionSelected("edit-card-1-$langcode", 0);
294
    $this->assertNoOptionSelected("edit-card-1-$langcode", 1);
295
    $this->assertNoOptionSelected("edit-card-1-$langcode", 2);
296
    $this->assertRaw('Some dangerous &amp; unescaped markup', 'Option text was properly filtered.');
297
    $this->assertRaw('Group 1', 'Option groups are displayed.');
298

    
299
    // Submit form: select first option.
300
    $edit = array("card_1[$langcode]" => 0);
301
    $this->drupalPost(NULL, $edit, t('Save'));
302
    $this->assertFieldValues($entity_init, 'card_1', $langcode, array(0));
303

    
304
    // Display form: check that the right options are selected.
305
    $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
306
    $this->assertOptionSelected("edit-card-1-$langcode", 0);
307
    $this->assertNoOptionSelected("edit-card-1-$langcode", 1);
308
    $this->assertNoOptionSelected("edit-card-1-$langcode", 2);
309

    
310
    // Submit form: Unselect the option.
311
    $edit = array("card_1[$langcode]" => '_none');
312
    $this->drupalPost('test-entity/manage/' . $entity->ftid . '/edit', $edit, t('Save'));
313
    $this->assertFieldValues($entity_init, 'card_1', $langcode, array());
314
  }
315

    
316
  /**
317
   * Tests the 'options_select' widget (multiple select).
318
   */
319
  function testSelectListMultiple() {
320
    // Create an instance of the 'multiple values' field.
321
    $instance = array(
322
      'field_name' => $this->card_2['field_name'],
323
      'entity_type' => 'test_entity',
324
      'bundle' => 'test_bundle',
325
      'widget' => array(
326
        'type' => 'options_select',
327
      ),
328
    );
329
    $instance = field_create_instance($instance);
330
    $langcode = LANGUAGE_NONE;
331

    
332
    // Create an entity.
333
    $entity_init = field_test_create_stub_entity();
334
    $entity = clone $entity_init;
335
    $entity->is_new = TRUE;
336
    field_test_entity_save($entity);
337

    
338
    // Display form: with no field data, nothing is selected.
339
    $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
340
    $this->assertNoOptionSelected("edit-card-2-$langcode", 0);
341
    $this->assertNoOptionSelected("edit-card-2-$langcode", 1);
342
    $this->assertNoOptionSelected("edit-card-2-$langcode", 2);
343
    $this->assertRaw('Some dangerous &amp; unescaped markup', 'Option text was properly filtered.');
344

    
345
    // Submit form: select first and third options.
346
    $edit = array("card_2[$langcode][]" => array(0 => 0, 2 => 2));
347
    $this->drupalPost(NULL, $edit, t('Save'));
348
    $this->assertFieldValues($entity_init, 'card_2', $langcode, array(0, 2));
349

    
350
    // Display form: check that the right options are selected.
351
    $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
352
    $this->assertOptionSelected("edit-card-2-$langcode", 0);
353
    $this->assertNoOptionSelected("edit-card-2-$langcode", 1);
354
    $this->assertOptionSelected("edit-card-2-$langcode", 2);
355

    
356
    // Submit form: select only first option.
357
    $edit = array("card_2[$langcode][]" => array(0 => 0));
358
    $this->drupalPost(NULL, $edit, t('Save'));
359
    $this->assertFieldValues($entity_init, 'card_2', $langcode, array(0));
360

    
361
    // Display form: check that the right options are selected.
362
    $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
363
    $this->assertOptionSelected("edit-card-2-$langcode", 0);
364
    $this->assertNoOptionSelected("edit-card-2-$langcode", 1);
365
    $this->assertNoOptionSelected("edit-card-2-$langcode", 2);
366

    
367
    // Submit form: select the three options while the field accepts only 2.
368
    $edit = array("card_2[$langcode][]" => array(0 => 0, 1 => 1, 2 => 2));
369
    $this->drupalPost(NULL, $edit, t('Save'));
370
    $this->assertText('this field cannot hold more than 2 values', 'Validation error was displayed.');
371

    
372
    // Submit form: uncheck all options.
373
    $edit = array("card_2[$langcode][]" => array());
374
    $this->drupalPost(NULL, $edit, t('Save'));
375
    $this->assertFieldValues($entity_init, 'card_2', $langcode, array());
376

    
377
    // Test the 'None' option.
378

    
379
    // Check that the 'none' option has no effect if actual options are selected
380
    // as well.
381
    $edit = array("card_2[$langcode][]" => array('_none' => '_none', 0 => 0));
382
    $this->drupalPost('test-entity/manage/' . $entity->ftid . '/edit', $edit, t('Save'));
383
    $this->assertFieldValues($entity_init, 'card_2', $langcode, array(0));
384

    
385
    // Check that selecting the 'none' option empties the field.
386
    $edit = array("card_2[$langcode][]" => array('_none' => '_none'));
387
    $this->drupalPost('test-entity/manage/' . $entity->ftid . '/edit', $edit, t('Save'));
388
    $this->assertFieldValues($entity_init, 'card_2', $langcode, array());
389

    
390
    // A required select list does not have an empty key.
391
    $instance['required'] = TRUE;
392
    field_update_instance($instance);
393
    $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
394
    $this->assertFalse($this->xpath('//select[@id=:id]//option[@value=""]', array(':id' => 'edit-card-2-' . $langcode)), 'A required select list does not have an empty key.');
395

    
396
    // We do not have to test that a required select list with one option is
397
    // auto-selected because the browser does it for us.
398

    
399
    // Test optgroups.
400

    
401
    // Use a callback function defining optgroups.
402
    $this->card_2['settings']['allowed_values'] = array();
403
    $this->card_2['settings']['allowed_values_function'] = 'list_test_allowed_values_callback';
404
    field_update_field($this->card_2);
405
    $instance['required'] = FALSE;
406
    field_update_instance($instance);
407

    
408
    // Display form: with no field data, nothing is selected.
409
    $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
410
    $this->assertNoOptionSelected("edit-card-2-$langcode", 0);
411
    $this->assertNoOptionSelected("edit-card-2-$langcode", 1);
412
    $this->assertNoOptionSelected("edit-card-2-$langcode", 2);
413
    $this->assertRaw('Some dangerous &amp; unescaped markup', 'Option text was properly filtered.');
414
    $this->assertRaw('Group 1', 'Option groups are displayed.');
415

    
416
    // Submit form: select first option.
417
    $edit = array("card_2[$langcode][]" => array(0 => 0));
418
    $this->drupalPost(NULL, $edit, t('Save'));
419
    $this->assertFieldValues($entity_init, 'card_2', $langcode, array(0));
420

    
421
    // Display form: check that the right options are selected.
422
    $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
423
    $this->assertOptionSelected("edit-card-2-$langcode", 0);
424
    $this->assertNoOptionSelected("edit-card-2-$langcode", 1);
425
    $this->assertNoOptionSelected("edit-card-2-$langcode", 2);
426

    
427
    // Submit form: Unselect the option.
428
    $edit = array("card_2[$langcode][]" => array('_none' => '_none'));
429
    $this->drupalPost('test-entity/manage/' . $entity->ftid . '/edit', $edit, t('Save'));
430
    $this->assertFieldValues($entity_init, 'card_2', $langcode, array());
431
  }
432

    
433
  /**
434
   * Tests the 'options_onoff' widget.
435
   */
436
  function testOnOffCheckbox() {
437
    // Create an instance of the 'boolean' field.
438
    $instance = array(
439
      'field_name' => $this->bool['field_name'],
440
      'entity_type' => 'test_entity',
441
      'bundle' => 'test_bundle',
442
      'widget' => array(
443
        'type' => 'options_onoff',
444
      ),
445
    );
446
    $instance = field_create_instance($instance);
447
    $langcode = LANGUAGE_NONE;
448

    
449
    // Create an entity.
450
    $entity_init = field_test_create_stub_entity();
451
    $entity = clone $entity_init;
452
    $entity->is_new = TRUE;
453
    field_test_entity_save($entity);
454

    
455
    // Display form: with no field data, option is unchecked.
456
    $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
457
    $this->assertNoFieldChecked("edit-bool-$langcode");
458
    $this->assertRaw('Some dangerous &amp; unescaped <strong>markup</strong>', 'Option text was properly filtered.');
459

    
460
    // Submit form: check the option.
461
    $edit = array("bool[$langcode]" => TRUE);
462
    $this->drupalPost(NULL, $edit, t('Save'));
463
    $this->assertFieldValues($entity_init, 'bool', $langcode, array(0));
464

    
465
    // Display form: check that the right options are selected.
466
    $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
467
    $this->assertFieldChecked("edit-bool-$langcode");
468

    
469
    // Submit form: uncheck the option.
470
    $edit = array("bool[$langcode]" => FALSE);
471
    $this->drupalPost(NULL, $edit, t('Save'));
472
    $this->assertFieldValues($entity_init, 'bool', $langcode, array(1));
473

    
474
    // Display form: with 'off' value, option is unchecked.
475
    $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
476
    $this->assertNoFieldChecked("edit-bool-$langcode");
477

    
478
    // Create admin user.
479
    $admin_user = $this->drupalCreateUser(array('access content', 'administer content types', 'administer taxonomy', 'administer fields'));
480
    $this->drupalLogin($admin_user);
481

    
482
    // Create a test field instance.
483
    $fieldUpdate = $this->bool;
484
    $fieldUpdate['settings']['allowed_values'] = array(0 => 0, 1 => 'MyOnValue');
485
    field_update_field($fieldUpdate);
486
    $instance = array(
487
      'field_name' => $this->bool['field_name'],
488
      'entity_type' => 'node',
489
      'bundle' => 'page',
490
      'widget' => array(
491
            'type' => 'options_onoff',
492
            'module' => 'options',
493
        ),
494
    );
495
    field_create_instance($instance);
496

    
497
    // Go to the edit page and check if the default settings works as expected
498
    $fieldEditUrl = 'admin/structure/types/manage/page/fields/bool';
499
    $this->drupalGet($fieldEditUrl);
500

    
501
    $this->assertText(
502
      'Use field label instead of the "On value" as label ',
503
      'Display setting checkbox available.'
504
    );
505

    
506
    $this->assertFieldByXPath(
507
      '*//label[@for="edit-' . $this->bool['field_name'] . '-und" and text()="MyOnValue "]',
508
      TRUE,
509
      'Default case shows "On value"'
510
    );
511

    
512
    // Enable setting
513
    $edit = array('instance[widget][settings][display_label]' => 1);
514
    // Save the new Settings
515
    $this->drupalPost($fieldEditUrl, $edit, t('Save settings'));
516

    
517
    // Go again to the edit page and check if the setting
518
    // is stored and has the expected effect
519
    $this->drupalGet($fieldEditUrl);
520
    $this->assertText(
521
      'Use field label instead of the "On value" as label ',
522
      'Display setting checkbox is available'
523
    );
524
    $this->assertFieldChecked(
525
      'edit-instance-widget-settings-display-label',
526
      'Display settings checkbox checked'
527
    );
528
    $this->assertFieldByXPath(
529
      '*//label[@for="edit-' . $this->bool['field_name'] . '-und" and text()="' . $this->bool['field_name'] . ' "]',
530
      TRUE,
531
      'Display label changes label of the checkbox'
532
    );
533
  }
534
}
535

    
536
/**
537
 * Test an options select on a list field with a dynamic allowed values function.
538
 */
539
class OptionsSelectDynamicValuesTestCase extends ListDynamicValuesTestCase {
540
  public static function getInfo() {
541
    return array(
542
      'name' => 'Options select dynamic values',
543
      'description' => 'Test an options select on a list field with a dynamic allowed values function.',
544
      'group' => 'Field types',
545
    );
546
  }
547

    
548
  /**
549
   * Tests the 'options_select' widget (single select).
550
   */
551
  function testSelectListDynamic() {
552
    // Create an entity.
553
    $this->entity->is_new = TRUE;
554
    field_test_entity_save($this->entity);
555
    // Create a web user.
556
    $web_user = $this->drupalCreateUser(array('access field_test content', 'administer field_test content'));
557
    $this->drupalLogin($web_user);
558

    
559
    // Display form.
560
    $this->drupalGet('test-entity/manage/' . $this->entity->ftid . '/edit');
561
    $options = $this->xpath('//select[@id="edit-test-list-und"]/option');
562
    $this->assertEqual(count($options), count($this->test) + 1);
563
    foreach ($options as $option) {
564
      $value = (string) $option['value'];
565
      if ($value != '_none') {
566
        $this->assertTrue(array_search($value, $this->test));
567
      }
568
    }
569
  }
570
}