diff --git a/core/modules/action/src/Tests/ActionUninstallTest.php b/core/modules/action/tests/src/Functional/ActionUninstallTest.php similarity index 89% rename from core/modules/action/src/Tests/ActionUninstallTest.php rename to core/modules/action/tests/src/Functional/ActionUninstallTest.php index c4d5ba3..93e0bc0 100644 --- a/core/modules/action/src/Tests/ActionUninstallTest.php +++ b/core/modules/action/tests/src/Functional/ActionUninstallTest.php @@ -1,8 +1,8 @@ drupalGet('test_bulk_form'); $result = $this->xpath('//label[@for="edit-action"]'); - $this->assertEqual('With selection', (string) $result[0]); + $this->assertEqual('With selection', $result[0]->getText()); // Setup up a different bulk form title. $view = Views::getView('test_bulk_form'); @@ -133,7 +133,7 @@ public function testBulkForm() { $this->drupalGet('test_bulk_form'); $result = $this->xpath('//label[@for="edit-action"]'); - $this->assertEqual('Test title', (string) $result[0]); + $this->assertEqual('Test title', $result[0]->getText()); $this->drupalGet('test_bulk_form'); // Call the node delete action. diff --git a/core/modules/action/src/Tests/ConfigurationTest.php b/core/modules/action/tests/src/Functional/ConfigurationTest.php similarity index 95% rename from core/modules/action/src/Tests/ConfigurationTest.php rename to core/modules/action/tests/src/Functional/ConfigurationTest.php index 225a528..647e1a7 100644 --- a/core/modules/action/src/Tests/ConfigurationTest.php +++ b/core/modules/action/tests/src/Functional/ConfigurationTest.php @@ -3,8 +3,8 @@ namespace Drupal\action\Tests; use Drupal\Component\Utility\Crypt; -use Drupal\simpletest\WebTestBase; use Drupal\system\Entity\Action; +use Drupal\Tests\BrowserTestBase; /** * Tests complex actions configuration by adding, editing, and deleting a @@ -12,7 +12,7 @@ * * @group action */ -class ConfigurationTest extends WebTestBase { +class ConfigurationTest extends BrowserTestBase { /** * Modules to install. @@ -83,7 +83,7 @@ function testActionConfiguration() { $this->assertNoText($new_action_label, "Make sure the action label does not appear on the overview page after we've deleted the action."); $action = Action::load($aid); - $this->assertFalse($action, 'Make sure the action is gone after being deleted.'); + $this->assertNull($action, 'Make sure the action is gone after being deleted.'); } } diff --git a/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php index 878c7c7..bf680be 100644 --- a/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php +++ b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php @@ -53,10 +53,19 @@ protected function assertElementNotPresent($css_selector) { * Plain text to look for. * * @deprecated Scheduled for removal in Drupal 9.0.0. - * Use $this->assertSession()->responseContains() instead. + * Use $this->assertSession()->pageTextContains() or + * $this->assertSession()->responseContains() instead. */ protected function assertText($text) { - $this->assertSession()->responseContains($text); + $content_type = $this->getSession()->getResponseHeader('Content-type'); + // In case of a Non-HTML response (example: XML) check the original + // response. + if (strpos($content_type, 'html') === FALSE) { + $this->assertSession()->responseContains($text); + } + else { + $this->assertSession()->pageTextContains($text); + } } /** @@ -111,6 +120,25 @@ protected function assertFieldByName($name, $value = NULL) { } /** + * Asserts that a field exists with the given ID and value. + * + * @param string $id + * ID of field to assert. + * @param string|\Drupal\Component\Render\MarkupInterface $value + * (optional) Value for the field to assert. You may pass in NULL to skip + * checking the value, while still checking that the field exists. + * However, the default value ('') asserts that the field value is an empty + * string. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use $this->assertSession()->fieldExists() or + * $this->assertSession()->fieldValueEquals() instead. + */ + protected function assertFieldById($id, $value = NULL) { + $this->assertFieldByName($id, $value); + } + + /** * Passes if the raw text IS found on the loaded page, fail otherwise. * * Raw text refers to the raw HTML that the page generated. @@ -149,4 +177,19 @@ public function assertLink($label, $index = 0) { return $this->assertSession()->linkExists($label, $index); } + /** + * Asserts that a select option in the current page exists. + * + * @param string $id + * ID of select field to assert. + * @param string $option + * Option to assert. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use $this->assertSession()->optionExists() instead. + */ + protected function assertOption($id, $option) { + return $this->assertSession()->optionExists($id, $option); + } + } diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index 5a9b0c0..8c72d80 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -22,6 +22,7 @@ use Drupal\Core\Test\TestDatabase; use Drupal\FunctionalTests\AssertLegacyTrait; use Drupal\simpletest\AssertHelperTrait; +use Drupal\simpletest\ContentTypeCreationTrait; use Drupal\simpletest\BlockCreationTrait; use Drupal\simpletest\NodeCreationTrait; use Drupal\user\Entity\Role; @@ -47,6 +48,9 @@ use NodeCreationTrait { createNode as drupalCreateNode; } + use ContentTypeCreationTrait { + createContentType as drupalCreateContentType; + } /** * Class loader. diff --git a/core/tests/Drupal/Tests/WebAssert.php b/core/tests/Drupal/Tests/WebAssert.php index 84fc744..7b15d2d 100644 --- a/core/tests/Drupal/Tests/WebAssert.php +++ b/core/tests/Drupal/Tests/WebAssert.php @@ -67,6 +67,42 @@ public function selectExists($select, TraversableElement $container = NULL) { } /** + * Checks that specific option in a select field exists on the current page. + * + * @param string $select + * One of id|name|label|value for the select field. + * @param string $option + * The option value. + * @param \Behat\Mink\Element\TraversableElement $container + * (optional) The document to check against. Defaults to the current page. + * + * @return \Behat\Mink\Element\NodeElement + * The matching option element + * + * @throws \Behat\Mink\Exception\ElementNotFoundException + * When the element doesn't exist. + */ + public function optionExists($select, $option, TraversableElement $container = NULL) { + $container = $container ?: $this->session->getPage(); + $select_field = $container->find('named', array( + 'select', + $this->session->getSelectorsHandler()->xpathLiteral($select), + )); + + if ($select_field === NULL) { + throw new ElementNotFoundException($this->session, 'select', 'id|name|label|value', $select); + } + + $option_field = $select_field->find('named', array('option', $option)); + + if ($option_field === NULL) { + throw new ElementNotFoundException($this->session, 'select', 'id|name|label|value', $option); + } + + return $option_field; + } + + /** * Pass if the page title is the given string. * * @param string $expected_title