Mercurial > hg > isophonics-drupal-site
comparison core/modules/options/tests/src/Functional/OptionsWidgetsTest.php @ 18:af1871eacc83
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:33:08 +0100 |
parents | 129ea1e6d783 |
children |
comparison
equal
deleted
inserted
replaced
17:129ea1e6d783 | 18:af1871eacc83 |
---|---|
32 * A field storage with cardinality 2 to use in this test class. | 32 * A field storage with cardinality 2 to use in this test class. |
33 * | 33 * |
34 * @var \Drupal\field\Entity\FieldStorageConfig | 34 * @var \Drupal\field\Entity\FieldStorageConfig |
35 */ | 35 */ |
36 protected $card2; | 36 protected $card2; |
37 | |
38 /** | |
39 * A field storage with float values to use in this test class. | |
40 * | |
41 * @var \Drupal\field\Entity\FieldStorageConfig | |
42 */ | |
43 protected $float; | |
37 | 44 |
38 protected function setUp() { | 45 protected function setUp() { |
39 parent::setUp(); | 46 parent::setUp(); |
40 | 47 |
41 // Field storage with cardinality 1. | 48 // Field storage with cardinality 1. |
74 ], | 81 ], |
75 ], | 82 ], |
76 ]); | 83 ]); |
77 $this->card2->save(); | 84 $this->card2->save(); |
78 | 85 |
86 // Field storage with list of float values. | |
87 $this->float = FieldStorageConfig::create([ | |
88 'field_name' => 'float', | |
89 'entity_type' => 'entity_test', | |
90 'type' => 'list_float', | |
91 'cardinality' => 1, | |
92 'settings' => [ | |
93 'allowed_values' => [ | |
94 '0.0' => '0.0', | |
95 '1.5' => '1.5', | |
96 '2.0' => '2.0', | |
97 ], | |
98 ], | |
99 ]); | |
100 $this->float->save(); | |
101 | |
79 // Create a web user. | 102 // Create a web user. |
80 $this->drupalLogin($this->drupalCreateUser(['view test entity', 'administer entity_test content'])); | 103 $this->drupalLogin($this->drupalCreateUser(['view test entity', 'administer entity_test content'])); |
81 } | 104 } |
82 | 105 |
83 /** | 106 /** |
446 $this->drupalPostForm('entity_test/manage/' . $entity->id() . '/edit', $edit, t('Save')); | 469 $this->drupalPostForm('entity_test/manage/' . $entity->id() . '/edit', $edit, t('Save')); |
447 $this->assertFieldValues($entity_init, 'card_2', []); | 470 $this->assertFieldValues($entity_init, 'card_2', []); |
448 } | 471 } |
449 | 472 |
450 /** | 473 /** |
474 * Tests the 'options_select' widget (float values). | |
475 */ | |
476 public function testSelectListFloat() { | |
477 | |
478 // Create an instance of the 'float value' field. | |
479 $field = FieldConfig::create([ | |
480 'field_storage' => $this->float, | |
481 'bundle' => 'entity_test', | |
482 'required' => TRUE, | |
483 ]); | |
484 $field->save(); | |
485 | |
486 $this->container | |
487 ->get('entity_type.manager') | |
488 ->getStorage('entity_form_display') | |
489 ->load('entity_test.entity_test.default') | |
490 ->setComponent($this->float->getName(), ['type' => 'options_select']) | |
491 ->save(); | |
492 | |
493 // Create an entity. | |
494 $entity = EntityTest::create([ | |
495 'user_id' => 1, | |
496 'name' => $this->randomMachineName(), | |
497 ]); | |
498 $entity->save(); | |
499 | |
500 // Display form. | |
501 $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); | |
502 | |
503 // With no field data, nothing is selected. | |
504 $this->assertFalse($this->assertSession()->optionExists('float', 0)->isSelected()); | |
505 $this->assertFalse($this->assertSession()->optionExists('float', 1.5)->isSelected()); | |
506 $this->assertFalse($this->assertSession()->optionExists('float', 2)->isSelected()); | |
507 | |
508 // Submit form. | |
509 $edit = ['float' => 1.5]; | |
510 $this->drupalPostForm(NULL, $edit, t('Save')); | |
511 $this->assertFieldValues($entity, 'float', [1.5]); | |
512 | |
513 // Display form: check that the right options are selected. | |
514 $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); | |
515 $this->assertFalse($this->assertSession()->optionExists('float', 0)->isSelected()); | |
516 $this->assertTrue($this->assertSession()->optionExists('float', 1.5)->isSelected()); | |
517 $this->assertFalse($this->assertSession()->optionExists('float', 2)->isSelected()); | |
518 } | |
519 | |
520 /** | |
451 * Tests the 'options_select' and 'options_button' widget for empty value. | 521 * Tests the 'options_select' and 'options_button' widget for empty value. |
452 */ | 522 */ |
453 public function testEmptyValue() { | 523 public function testEmptyValue() { |
454 // Create an instance of the 'single value' field. | 524 // Create an instance of the 'single value' field. |
455 $field = FieldConfig::create([ | 525 $field = FieldConfig::create([ |