use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
-use Drupal\field\Tests\FieldTestBase;
use Drupal\field\Entity\FieldStorageConfig;
+use Drupal\Tests\field\Functional\FieldTestBase;
/**
* Tests the Options widgets.
*/
protected $card2;
-
protected function setUp() {
parent::setUp();
// Display form.
$this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
// A required field without any value has a "none" option.
- $this->assertTrue($this->xpath('//select[@id=:id]//option[@value="_none" and text()=:label]', [':id' => 'edit-card-1', ':label' => t('- Select a value -')]), 'A required select list has a "Select a value" choice.');
+ $this->assertTrue($this->xpath('//select[@id=:id]//option[@value="_none" and text()=:label]', [':id' => 'edit-card-1', ':label' => '- Select a value -']), 'A required select list has a "Select a value" choice.');
// With no field data, nothing is selected.
- $this->assertNoOptionSelected('edit-card-1', '_none');
- $this->assertNoOptionSelected('edit-card-1', 0);
- $this->assertNoOptionSelected('edit-card-1', 1);
- $this->assertNoOptionSelected('edit-card-1', 2);
+ $this->assertTrue($this->assertSession()->optionExists('card_1', '_none')->isSelected());
+ $this->assertFalse($this->assertSession()->optionExists('card_1', 0)->isSelected());
+ $this->assertFalse($this->assertSession()->optionExists('card_1', 1)->isSelected());
+ $this->assertFalse($this->assertSession()->optionExists('card_1', 2)->isSelected());
$this->assertRaw('Some dangerous & unescaped markup', 'Option text was properly filtered.');
// Submit form: select invalid 'none' option.
$this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
// A required field with a value has no 'none' option.
$this->assertFalse($this->xpath('//select[@id=:id]//option[@value="_none"]', [':id' => 'edit-card-1']), 'A required select list with an actual value has no "none" choice.');
- $this->assertOptionSelected('edit-card-1', 0);
- $this->assertNoOptionSelected('edit-card-1', 1);
- $this->assertNoOptionSelected('edit-card-1', 2);
+ $this->assertTrue($this->assertSession()->optionExists('card_1', 0)->isSelected());
+ $this->assertFalse($this->assertSession()->optionExists('card_1', 1)->isSelected());
+ $this->assertFalse($this->assertSession()->optionExists('card_1', 2)->isSelected());
// Make the field non required.
$field->setRequired(FALSE);
// Display form.
$this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
// A non-required field has a 'none' option.
- $this->assertTrue($this->xpath('//select[@id=:id]//option[@value="_none" and text()=:label]', [':id' => 'edit-card-1', ':label' => t('- None -')]), 'A non-required select list has a "None" choice.');
+ $this->assertTrue($this->xpath('//select[@id=:id]//option[@value="_none" and text()=:label]', [':id' => 'edit-card-1', ':label' => '- None -']), 'A non-required select list has a "None" choice.');
// Submit form: Unselect the option.
$edit = ['card_1' => '_none'];
$this->drupalPostForm('entity_test/manage/' . $entity->id() . '/edit', $edit, t('Save'));
// Display form: with no field data, nothing is selected
$this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
- $this->assertNoOptionSelected('edit-card-1', 0);
- $this->assertNoOptionSelected('edit-card-1', 1);
- $this->assertNoOptionSelected('edit-card-1', 2);
+ $this->assertFalse($this->assertSession()->optionExists('card_1', 0)->isSelected());
+ $this->assertFalse($this->assertSession()->optionExists('card_1', 1)->isSelected());
+ $this->assertFalse($this->assertSession()->optionExists('card_1', 2)->isSelected());
$this->assertRaw('Some dangerous & unescaped markup', 'Option text was properly filtered.');
$this->assertRaw('More <script>dangerous</script> markup', 'Option group text was properly filtered.');
$this->assertRaw('Group 1', 'Option groups are displayed.');
// Display form: check that the right options are selected.
$this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
- $this->assertOptionSelected('edit-card-1', 0);
- $this->assertNoOptionSelected('edit-card-1', 1);
- $this->assertNoOptionSelected('edit-card-1', 2);
+ $this->assertTrue($this->assertSession()->optionExists('card_1', 0)->isSelected());
+ $this->assertFalse($this->assertSession()->optionExists('card_1', 1)->isSelected());
+ $this->assertFalse($this->assertSession()->optionExists('card_1', 2)->isSelected());
// Submit form: Unselect the option.
$edit = ['card_1' => '_none'];
// Display form: with no field data, nothing is selected.
$this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
- $this->assertOptionSelected("edit-card-2", '_none');
- $this->assertNoOptionSelected('edit-card-2', 0);
- $this->assertNoOptionSelected('edit-card-2', 1);
- $this->assertNoOptionSelected('edit-card-2', 2);
+ $this->assertTrue($this->assertSession()->optionExists('card_2', '_none')->isSelected());
+ $this->assertFalse($this->assertSession()->optionExists('card_2', 0)->isSelected());
+ $this->assertFalse($this->assertSession()->optionExists('card_2', 1)->isSelected());
+ $this->assertFalse($this->assertSession()->optionExists('card_2', 2)->isSelected());
$this->assertRaw('Some dangerous & unescaped markup', 'Option text was properly filtered.');
// Submit form: select first and third options.
// Display form: check that the right options are selected.
$this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
- $this->assertOptionSelected('edit-card-2', 0);
- $this->assertNoOptionSelected('edit-card-2', 1);
- $this->assertOptionSelected('edit-card-2', 2);
+ $this->assertTrue($this->assertSession()->optionExists('card_2', 0)->isSelected());
+ $this->assertFalse($this->assertSession()->optionExists('card_2', 1)->isSelected());
+ $this->assertTrue($this->assertSession()->optionExists('card_2', 2)->isSelected());
// Submit form: select only first option.
$edit = ['card_2[]' => [0 => 0]];
// Display form: check that the right options are selected.
$this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
- $this->assertOptionSelected('edit-card-2', 0);
- $this->assertNoOptionSelected('edit-card-2', 1);
- $this->assertNoOptionSelected('edit-card-2', 2);
+ $this->assertTrue($this->assertSession()->optionExists('card_2', 0)->isSelected());
+ $this->assertFalse($this->assertSession()->optionExists('card_2', 1)->isSelected());
+ $this->assertFalse($this->assertSession()->optionExists('card_2', 2)->isSelected());
// Submit form: select the three options while the field accepts only 2.
$edit = ['card_2[]' => [0 => 0, 1 => 1, 2 => 2]];
// Display form: with no field data, nothing is selected.
$this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
- $this->assertNoOptionSelected('edit-card-2', 0);
- $this->assertNoOptionSelected('edit-card-2', 1);
- $this->assertNoOptionSelected('edit-card-2', 2);
+ $this->assertFalse($this->assertSession()->optionExists('card_2', 0)->isSelected());
+ $this->assertFalse($this->assertSession()->optionExists('card_2', 1)->isSelected());
+ $this->assertFalse($this->assertSession()->optionExists('card_2', 2)->isSelected());
$this->assertRaw('Some dangerous & unescaped markup', 'Option text was properly filtered.');
$this->assertRaw('More <script>dangerous</script> markup', 'Option group text was properly filtered.');
$this->assertRaw('Group 1', 'Option groups are displayed.');
// Display form: check that the right options are selected.
$this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
- $this->assertOptionSelected('edit-card-2', 0);
- $this->assertNoOptionSelected('edit-card-2', 1);
- $this->assertNoOptionSelected('edit-card-2', 2);
+ $this->assertTrue($this->assertSession()->optionExists('card_2', 0)->isSelected());
+ $this->assertFalse($this->assertSession()->optionExists('card_2', 1)->isSelected());
+ $this->assertFalse($this->assertSession()->optionExists('card_2', 2)->isSelected());
// Submit form: Unselect the option.
$edit = ['card_2[]' => ['_none' => '_none']];
// Display form: check that _none options are present and has label.
$this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
// A required field without any value has a "none" option.
- $this->assertTrue($this->xpath('//select[@id=:id]//option[@value="_none" and text()=:label]', [':id' => 'edit-card-1', ':label' => t('- None -')]), 'A test select has a "None" choice.');
+ $this->assertTrue($this->xpath('//select[@id=:id]//option[@value="_none" and text()=:label]', [':id' => 'edit-card-1', ':label' => '- None -']), 'A test select has a "None" choice.');
}
}