Issue #2973827 by idebr: Options module PHPUnit tests extend a Simpletest base class

merge-requests/1654/head
Francesco Placella 2018-05-30 22:28:28 +02:00
parent 59fe5e752d
commit 48d26173b6
5 changed files with 37 additions and 37 deletions

View File

@ -3,9 +3,9 @@
namespace Drupal\Tests\options\Functional;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Tests\FieldTestBase;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\entity_test\Entity\EntityTestRev;
use Drupal\Tests\field\Functional\FieldTestBase;
/**
* Base class for testing allowed values of options fields.

View File

@ -4,7 +4,7 @@ namespace Drupal\Tests\options\Functional;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Tests\FieldTestBase;
use Drupal\Tests\field\Functional\FieldTestBase;
/**
* Tests the Options field UI functionality.

View File

@ -4,7 +4,7 @@ namespace Drupal\Tests\options\Functional;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Tests\FieldTestBase;
use Drupal\Tests\field\Functional\FieldTestBase;
/**
* Tests option fields can be updated and created through config synchronization.

View File

@ -25,7 +25,7 @@ class OptionsSelectDynamicValuesTest extends OptionsDynamicValuesTestBase {
$options = $this->xpath('//select[@id="edit-test-options"]/option');
$this->assertEqual(count($options), count($this->test) + 1);
foreach ($options as $option) {
$value = (string) $option['value'];
$value = $option->getValue();
if ($value != '_none') {
$this->assertTrue(array_search($value, $this->test));
}

View File

@ -4,8 +4,8 @@ namespace Drupal\Tests\options\Functional;
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.
@ -254,13 +254,13 @@ class OptionsWidgetsTest extends FieldTestBase {
// 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.
@ -277,9 +277,9 @@ class OptionsWidgetsTest extends FieldTestBase {
$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);
@ -288,7 +288,7 @@ class OptionsWidgetsTest extends FieldTestBase {
// 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'));
@ -302,9 +302,9 @@ class OptionsWidgetsTest extends FieldTestBase {
// 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.');
@ -316,9 +316,9 @@ class OptionsWidgetsTest extends FieldTestBase {
// 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'];
@ -352,10 +352,10 @@ class OptionsWidgetsTest extends FieldTestBase {
// 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.
@ -365,9 +365,9 @@ class OptionsWidgetsTest extends FieldTestBase {
// 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]];
@ -376,9 +376,9 @@ class OptionsWidgetsTest extends FieldTestBase {
// 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]];
@ -423,9 +423,9 @@ class OptionsWidgetsTest extends FieldTestBase {
// 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.');
@ -437,9 +437,9 @@ class OptionsWidgetsTest extends FieldTestBase {
// 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']];
@ -487,7 +487,7 @@ class OptionsWidgetsTest extends FieldTestBase {
// 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.');
}
}