Problem/Motivation

The following PHPUnit tests in the Options module extend a Simpletest base class (\Drupal\field\Tests\FieldTestBase):

  • \Drupal\Tests\options\Functional\OptionsDynamicValuesTestBase
  • \Drupal\Tests\options\Functional\OptionsFieldUITest
  • \Drupal\Tests\options\Functional\OptionsFloatFieldImportTest
  • \Drupal\Tests\options\FunctionalOptionsWidgetsTest

According to the instructions at #2735005: Convert all Simpletest web tests to BrowserTestBase (or UnitTestBase/KernelTestBase), these tests should extend the new version \Drupal\Tests\field\Functional\FieldTestBase:

Any TestBase or Trait which is in the old /src/Tests/ location should remain there and be deprecated. Copy the TestBase or Trait file into the new location and alter the tests to use the new version. The deprecated class must not "use" the newly-moved class, but remain exactly as it is. Create a change record for the deprecation notice - one CR can cover all deprecations within a module.

Proposed resolution

Update the tests to extend the PHPUnit based \Drupal\Tests\field\Functional\FieldTestBase

Remaining tasks

  1. Write a patch
  2. Review
  3. Commit

User interface changes

None.

API changes

None.

Data model changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

idebr created an issue. See original summary.

idebr’s picture

Status: Active » Needs review
FileSize
2.45 KB

Attached patch updates the tests in \Drupal\Tests\options\Functional\ to extend \Drupal\Tests\field\Functional\FieldTestBase instead.

Status: Needs review » Needs work

The last submitted patch, 2: 2973827-2.patch, failed testing. View results

dawehner’s picture

Interesting! Nice catch.

idebr’s picture

Status: Needs work » Needs review
FileSize
10.32 KB
12.44 KB

@dawehner Thanks! I was thoroughly confused for a minute why PHPStorm would not let me run the class as a PHPUnit test.

Replaced the assertOptionSelected() / assertNoOptionSelected() methods with assertSession()->optionExists()->isSelected() and updated the failing tests.

Status: Needs review » Needs work

The last submitted patch, 5: 2973827-5.patch, failed testing. View results

idebr’s picture

Status: Needs work » Needs review
borisson_’s picture

Status: Needs review » Reviewed & tested by the community

Great work @idebr!

plach’s picture

+++ b/core/modules/options/tests/src/Functional/OptionsWidgetsTest.php
@@ -254,13 +254,13 @@ public function testSelectListSingle() {
-    $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());

Why are we switching the first assertion ("_none") from "not selected" to "selected"?

idebr’s picture

#9 Interesting observation indeed.

The generated code looks like this:

<select>
  <option value="_none">- Select a value -</option>
  <option value="0">Zero</option>
  <option value="1">One</option>
  <option value="2">Some dangerous &amp; unescaped markup</option>
  <option value="3">Some HTML encoded markup with &lt; &amp; &gt;</option>
</select>

Note that the '_none' option is not explicitly selected in the html. However, visually the select element looks like this:

So the select value appears to be '_none' in the UI. Perhaps this assertion is handled differently between browser test drivers. The behavior in PHPUnit does match the DOM selected property, for example using jQuery:

> jQuery('#edit-field-list-options').val()
"_none"
plach’s picture

Makes sense, thanks!

  • plach committed 48d2617 on 8.6.x
    Issue #2973827 by idebr: Options module PHPUnit tests extend a...
plach’s picture

Status: Reviewed & tested by the community » Fixed

Committed 48d2617 and pushed to 8.6.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.