diff --git a/core/modules/language/src/Tests/AdminPathEntityConverterLanguageTest.php b/core/modules/language/tests/src/Functional/AdminPathEntityConverterLanguageTest.php similarity index 89% rename from core/modules/language/src/Tests/AdminPathEntityConverterLanguageTest.php rename to core/modules/language/tests/src/Functional/AdminPathEntityConverterLanguageTest.php index 3cc00f9..bd46a40 100644 --- a/core/modules/language/src/Tests/AdminPathEntityConverterLanguageTest.php +++ b/core/modules/language/tests/src/Functional/AdminPathEntityConverterLanguageTest.php @@ -1,16 +1,16 @@ drupalLogin($admin_user); $this->drupalPostForm('admin/config/regional/language/add', array('predefined_langcode' => 'hu'), t('Add language')); $this->drupalGet('admin/structure/block/add/system_menu_block:admin/stark'); - $this->assertNoFieldByXPath('//input[@id="edit-visibility-language-langcodes-und"]', NULL, '\'Not specified\' option does not appear at block config, language settings section.'); - $this->assertNoFieldByXpath('//input[@id="edit-visibility-language-langcodes-zxx"]', NULL, '\'Not applicable\' option does not appear at block config, language settings section.'); - $this->assertFieldByXPath('//input[@id="edit-visibility-language-langcodes-en"]', NULL, '\'English\' option appears at block config, language settings section.'); - $this->assertFieldByXpath('//input[@id="edit-visibility-language-langcodes-hu"]', NULL, '\'Hungarian\' option appears at block config, language settings section.'); + + // 'Not specified' option does not appear at block config, language settings + // section. + $this->assertSession()->fieldNotExists('edit-visibility-language-langcodes-und'); + // 'Not applicable' option does not appear. + $this->assertSession()->fieldNotExists('edit-visibility-language-langcodes-zxx'); + + // // 'English' option appears.. + $this->assertSession()->fieldExists('edit-visibility-language-langcodes-en'); + // // 'Hungarian' option appears.. + $this->assertSession()->fieldExists('edit-visibility-language-langcodes-hu'); } } diff --git a/core/modules/language/src/Tests/LanguageBrowserDetectionTest.php b/core/modules/language/tests/src/Functional/LanguageBrowserDetectionTest.php similarity index 96% rename from core/modules/language/src/Tests/LanguageBrowserDetectionTest.php rename to core/modules/language/tests/src/Functional/LanguageBrowserDetectionTest.php index 3991b2a..1b1382a 100644 --- a/core/modules/language/src/Tests/LanguageBrowserDetectionTest.php +++ b/core/modules/language/tests/src/Functional/LanguageBrowserDetectionTest.php @@ -1,15 +1,15 @@ drupalGet('admin/config/regional/language/detection/url'); - $this->assertFieldByXPath('//input[@name="prefix[en]"]', '', 'Default English has no path prefix.'); + // Default English has no path prefix. + $this->assertSession()->fieldValueEquals('prefix[en]', ''); // Check that Add language is a primary button. $this->drupalGet('admin/config/regional/language/add'); - $this->assertFieldByXPath('//input[contains(@class, "button--primary")]', 'Add language', 'Add language is a primary button'); + $button = $this->assertSession()->buttonExists('Add language'); + $this->assertTrue($button->hasClass('button--primary')); // Add predefined language. $edit = array( @@ -53,10 +55,10 @@ function testLanguageConfiguration() { // Check if the Default English language has no path prefix. $this->drupalGet('admin/config/regional/language/detection/url'); - $this->assertFieldByXPath('//input[@name="prefix[en]"]', '', 'Default English has no path prefix.'); + $this->assertSession()->fieldValueEquals('prefix[en]', ''); // Check if French has a path prefix. $this->drupalGet('admin/config/regional/language/detection/url'); - $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'fr', 'French has a path prefix.'); + $this->assertSession()->fieldValueEquals('prefix[fr]', 'fr'); // Check if we can change the default language. $this->drupalGet('admin/config/regional/language'); @@ -74,17 +76,17 @@ function testLanguageConfiguration() { // Check if a valid language prefix is added after changing the default // language. $this->drupalGet('admin/config/regional/language/detection/url'); - $this->assertFieldByXPath('//input[@name="prefix[en]"]', 'en', 'A valid path prefix has been added to the previous default language.'); + $this->assertSession()->fieldValueEquals('prefix[en]', 'en'); // Check if French still has a path prefix. $this->drupalGet('admin/config/regional/language/detection/url'); - $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'fr', 'French still has a path prefix.'); + $this->assertSession()->fieldValueEquals('prefix[fr]', 'fr'); // Check that prefix can be changed. $edit = array( 'prefix[fr]' => 'french', ); $this->drupalPostForm(NULL, $edit, t('Save configuration')); - $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'french', 'French path prefix has changed.'); + $this->assertSession()->fieldValueEquals('prefix[fr]', 'french'); // Check that the prefix can be removed. $edit = array( @@ -169,10 +171,7 @@ function testLanguageConfigurationWeight() { $this->checkConfigurableLanguageWeight('after re-ordering'); // Remove predefined language. - $edit = array( - 'confirm' => 1, - ); - $this->drupalPostForm('admin/config/regional/language/delete/fr', $edit, 'Delete'); + $this->drupalPostForm('admin/config/regional/language/delete/fr', array(), 'Delete'); $this->checkConfigurableLanguageWeight('after deleting a language'); } diff --git a/core/modules/language/src/Tests/LanguageCustomLanguageConfigurationTest.php b/core/modules/language/tests/src/Functional/LanguageCustomLanguageConfigurationTest.php similarity index 96% rename from core/modules/language/src/Tests/LanguageCustomLanguageConfigurationTest.php rename to core/modules/language/tests/src/Functional/LanguageCustomLanguageConfigurationTest.php index dbd35cd..6c01c00 100644 --- a/core/modules/language/src/Tests/LanguageCustomLanguageConfigurationTest.php +++ b/core/modules/language/tests/src/Functional/LanguageCustomLanguageConfigurationTest.php @@ -1,8 +1,8 @@ assertResponse(403, 'Can not delete locked language'); // Ensure that NL cannot be set default when it's not available. + // First create the NL language. + $edit = array( + 'predefined_langcode' => 'nl', + ); + $this->drupalPostForm('admin/config/regional/language/add', $edit, 'Add language'); + + // Load the form which has now the additional NL language option. $this->drupalGet('admin/config/regional/language'); - $extra_values = '&site_default_language=nl'; - $this->drupalPostForm(NULL, array(), t('Save configuration'), array(), array(), NULL, $extra_values); + + // Delete the NL language in the background. + $language_storage = $this->container->get('entity_type.manager')->getStorage('configurable_language'); + $language_storage->load('nl')->delete(); + + $this->drupalPostForm(NULL, array('site_default_language' => 'nl'), 'Save configuration'); $this->assertText(t('Selected default language no longer exists.')); $this->assertNoFieldChecked('edit-site-default-language-xx', 'The previous default language got deselected.'); } diff --git a/core/modules/language/src/Tests/LanguageLocaleListTest.php b/core/modules/language/tests/src/Functional/LanguageLocaleListTest.php similarity index 84% rename from core/modules/language/src/Tests/LanguageLocaleListTest.php rename to core/modules/language/tests/src/Functional/LanguageLocaleListTest.php index dd3e02a..5ab3662 100644 --- a/core/modules/language/src/Tests/LanguageLocaleListTest.php +++ b/core/modules/language/tests/src/Functional/LanguageLocaleListTest.php @@ -1,15 +1,15 @@ drupalGet('fr/admin/config/regional/language/add'); - $select = $this->xpath('//select[@id="edit-predefined-langcode"]'); - $select_element = (array) end($select); - $options = $select_element['option']; + $option_elements = $this->xpath('//select[@id="edit-predefined-langcode/option"]'); + $options = []; + foreach ($option_elements as $option_element) { + $options[] = $option_element->getText(); + } // Remove the 'Custom language...' option form the end. array_pop($options); // Order language list. diff --git a/core/modules/language/src/Tests/LanguageNegotiationContentEntityTest.php b/core/modules/language/tests/src/Functional/LanguageNegotiationContentEntityTest.php similarity index 98% rename from core/modules/language/src/Tests/LanguageNegotiationContentEntityTest.php rename to core/modules/language/tests/src/Functional/LanguageNegotiationContentEntityTest.php index ba0a4db..8991437 100644 --- a/core/modules/language/src/Tests/LanguageNegotiationContentEntityTest.php +++ b/core/modules/language/tests/src/Functional/LanguageNegotiationContentEntityTest.php @@ -1,6 +1,6 @@ assertFalse(isset($negotiation[$interface_method_id]), 'Interface language negotiation method removed from the stored settings.'); $this->drupalGet('admin/config/regional/language/detection'); - $this->assertNoFieldByName($form_field, NULL, 'Interface language negotiation method unavailable.'); + // Interface language negotiation method unavailable.. + $this->assertNoFieldByName($form_field, NULL); // Check that type-specific language negotiation methods can be assigned // only to the corresponding language types. diff --git a/core/modules/language/src/Tests/LanguagePathMonolingualTest.php b/core/modules/language/tests/src/Functional/LanguagePathMonolingualTest.php similarity index 94% rename from core/modules/language/src/Tests/LanguagePathMonolingualTest.php rename to core/modules/language/tests/src/Functional/LanguagePathMonolingualTest.php index 510d805..681b378 100644 --- a/core/modules/language/src/Tests/LanguagePathMonolingualTest.php +++ b/core/modules/language/tests/src/Functional/LanguagePathMonolingualTest.php @@ -1,15 +1,15 @@ xpath('//select[@id=:id]//option[@value=:option]', array(':id' => 'edit-settings-user-user-settings-language-langcode', ':option' => 'en')); // Check that the language text is translated. - $this->assertEqual((string) $elements[0], $name_translation, 'Checking the option string English is translated to Spanish.'); + $this->assertEqual($elements[0]->getText(), $name_translation, 'Checking the option string English is translated to Spanish.'); } } diff --git a/core/modules/language/src/Tests/LanguageSwitchingTest.php b/core/modules/language/tests/src/Functional/LanguageSwitchingTest.php similarity index 99% rename from core/modules/language/src/Tests/LanguageSwitchingTest.php rename to core/modules/language/tests/src/Functional/LanguageSwitchingTest.php index c076e6f..11adb12 100644 --- a/core/modules/language/src/Tests/LanguageSwitchingTest.php +++ b/core/modules/language/tests/src/Functional/LanguageSwitchingTest.php @@ -1,19 +1,19 @@ $http_header_browser_fallback, 'message' => 'SELECTED: UI language is switched based on selected language.', ); - $this->runTest($test); + $this->doTest($test); // An invalid language is selected. $this->config('language.negotiation')->set('selected_langcode', NULL)->save(); @@ -148,7 +148,7 @@ function testUILanguageNegotiation() { 'http_header' => $http_header_browser_fallback, 'message' => 'SELECTED > DEFAULT: UI language is switched based on selected language.', ); - $this->runTest($test); + $this->doTest($test); // No selected language is available. $this->config('language.negotiation')->set('selected_langcode', $langcode_unknown)->save(); @@ -160,7 +160,7 @@ function testUILanguageNegotiation() { 'http_header' => $http_header_browser_fallback, 'message' => 'SELECTED > DEFAULT: UI language is switched based on selected language.', ); - $this->runTest($test); + $this->doTest($test); $tests = array( // Default, browser preference should have no influence. @@ -211,7 +211,7 @@ function testUILanguageNegotiation() { ); foreach ($tests as $test) { - $this->runTest($test); + $this->doTest($test); } // Unknown language prefix should return 404. @@ -240,7 +240,7 @@ function testUILanguageNegotiation() { 'http_header' => array(), 'message' => 'USER > DEFAULT: no preferred user language setting, the UI language is default', ); - $this->runTest($test); + $this->doTest($test); // Set preferred langcode for user to unknown language. $account = $this->loggedInUser; @@ -255,7 +255,7 @@ function testUILanguageNegotiation() { 'http_header' => array(), 'message' => 'USER > DEFAULT: invalid preferred user language setting, the UI language is default', ); - $this->runTest($test); + $this->doTest($test); // Set preferred langcode for user to non default. $account->preferred_langcode = $langcode; @@ -269,7 +269,7 @@ function testUILanguageNegotiation() { 'http_header' => array(), 'message' => 'USER > DEFAULT: defined preferred user language setting, the UI language is based on user setting', ); - $this->runTest($test); + $this->doTest($test); // Set preferred admin langcode for user to NULL. $account->preferred_admin_langcode = NULL; @@ -283,7 +283,7 @@ function testUILanguageNegotiation() { 'http_header' => array(), 'message' => 'USER ADMIN > DEFAULT: no preferred user admin language setting, the UI language is default', ); - $this->runTest($test); + $this->doTest($test); // Set preferred admin langcode for user to unknown language. $account->preferred_admin_langcode = $langcode_unknown; @@ -297,7 +297,7 @@ function testUILanguageNegotiation() { 'http_header' => array(), 'message' => 'USER ADMIN > DEFAULT: invalid preferred user admin language setting, the UI language is default', ); - $this->runTest($test); + $this->doTest($test); // Set preferred admin langcode for user to non default. $account->preferred_admin_langcode = $langcode; @@ -311,7 +311,7 @@ function testUILanguageNegotiation() { 'http_header' => array(), 'message' => 'USER ADMIN > DEFAULT: defined preferred user admin language setting, the UI language is based on user setting', ); - $this->runTest($test); + $this->doTest($test); // Go by session preference. $language_negotiation_session_param = $this->randomMachineName(); @@ -337,11 +337,11 @@ function testUILanguageNegotiation() { ), ); foreach ($tests as $test) { - $this->runTest($test); + $this->doTest($test); } } - protected function runTest($test) { + protected function doTest($test) { $test += array('path_options' => []); if (!empty($test['language_negotiation'])) { $method_weights = array_flip($test['language_negotiation']); diff --git a/core/modules/language/src/Tests/LanguageUrlRewritingTest.php b/core/modules/language/tests/src/Functional/LanguageUrlRewritingTest.php similarity index 96% rename from core/modules/language/src/Tests/LanguageUrlRewritingTest.php rename to core/modules/language/tests/src/Functional/LanguageUrlRewritingTest.php index 5cd80dc..e08eb0a 100644 --- a/core/modules/language/src/Tests/LanguageUrlRewritingTest.php +++ b/core/modules/language/tests/src/Functional/LanguageUrlRewritingTest.php @@ -1,12 +1,12 @@ getId()]) ? $prefixes[$language->getId()] : $this->randomMachineName(); - if ($this->assertNotEqual($stored_prefix, $prefix, $message1)) { - $prefix = $stored_prefix; - } + $this->assertNotEqual($stored_prefix, $prefix, $message1); + $prefix = $stored_prefix; $this->drupalGet("$prefix/$path"); $this->assertResponse(404, $message2); diff --git a/core/modules/language/src/Tests/Migrate/MigrateLanguageTest.php b/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageTest.php similarity index 96% rename from core/modules/language/src/Tests/Migrate/MigrateLanguageTest.php rename to core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageTest.php index 6bdd1f2..72d7ab8 100644 --- a/core/modules/language/src/Tests/Migrate/MigrateLanguageTest.php +++ b/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageTest.php @@ -1,6 +1,6 @@ configImporter) { - // Set up the ConfigImporter object for testing. - $storage_comparer = new StorageComparer( - $this->container->get('config.storage.sync'), - $this->container->get('config.storage'), - $this->container->get('config.manager') - ); - $this->configImporter = new ConfigImporter( - $storage_comparer, - $this->container->get('event_dispatcher'), - $this->container->get('config.manager'), - $this->container->get('lock'), - $this->container->get('config.typed'), - $this->container->get('module_handler'), - $this->container->get('module_installer'), - $this->container->get('theme_handler'), - $this->container->get('string_translation') - ); - } - // Always recalculate the changelist when called. - return $this->configImporter->reset(); - } - - /** - * Copies configuration objects from source storage to target storage. - * - * @param \Drupal\Core\Config\StorageInterface $source_storage - * The source config storage service. - * @param \Drupal\Core\Config\StorageInterface $target_storage - * The target config storage service. - */ - public function copyConfig(StorageInterface $source_storage, StorageInterface $target_storage) { - $target_storage->deleteAll(); - foreach ($source_storage->listAll() as $name) { - $target_storage->write($name, $source_storage->read($name)); - } - } - - /** * Configuration accessor for tests. Returns non-overridden configuration. * * @param $name diff --git a/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php index 6ca9f85..81da04a 100644 --- a/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php +++ b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php @@ -129,6 +129,27 @@ protected function assertFieldByName($name, $value = NULL) { } /** + * Asserts that a field exists with the given name and value. + * + * @param string $name + * Name of field to assert. + * @param string $value + * (optional) Value of the field to assert. You may pass in NULL (default) + * to skip checking the actual value, while still checking that the field + * exists. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use $this->assertSession()->fieldNotExists() or + * $this->assertSession()->fieldValueNotEquals() instead. + */ + protected function assertNoFieldByName($name, $value = NULL) { + $this->assertSession()->fieldNotExists($name); + if ($value !== NULL) { + $this->assertSession()->fieldValueNotEquals($name, (string) $value); + } + } + + /** * Asserts that a field exists with the given ID and value. * * @param string $id @@ -344,6 +365,47 @@ protected function assertNoOption($id, $option) { } /** + * Asserts that a select option in the current page is checked. + * + * @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()->optionSelected() instead. + */ + protected function assertOptionSelected($id, $option) { + $this->assertSession()->optionSelected($id, $option); + } + + /** + * Asserts that a checkbox field in the current page is checked. + * + * @param string $id + * ID of field to assert. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use $this->assertSession()->checkboxChecked() instead. + */ + protected function assertFieldChecked($id) { + $this->assertSession()->checkboxChecked($id); + } + + /** + * Asserts that a checkbox field in the current page is not checked. + * + * @param string $id + * ID of field to assert. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use $this->assertSession()->checkboxNotChecked() instead. + */ + protected function assertNoFieldChecked($id) { + $this->assertSession()->checkboxNotChecked($id); + } + + /** * Passes if the raw text IS found escaped on the loaded page, fail otherwise. * * Raw text refers to the raw HTML that the page generated. diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php index ed3875d..8807cb5 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBase.php +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php @@ -7,9 +7,6 @@ use Drupal\Component\FileCache\FileCacheFactory; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\SafeMarkup; -use Drupal\Core\Config\ConfigImporter; -use Drupal\Core\Config\StorageComparer; -use Drupal\Core\Config\StorageInterface; use Drupal\Core\Database\Database; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ServiceProviderInterface; @@ -20,6 +17,7 @@ use Drupal\Core\Site\Settings; use Drupal\simpletest\AssertContentTrait; use Drupal\simpletest\AssertHelperTrait; +use Drupal\Tests\ConfigTestTrait; use Drupal\Tests\RandomGeneratorTrait; use Drupal\simpletest\TestServiceProvider; use Symfony\Component\DependencyInjection\Reference; @@ -55,6 +53,7 @@ use AssertContentTrait; use AssertHelperTrait; use RandomGeneratorTrait; + use ConfigTestTrait; /** * {@inheritdoc} @@ -1016,54 +1015,6 @@ protected function setSetting($name, $value) { } /** - * Returns a ConfigImporter object to import test configuration. - * - * @return \Drupal\Core\Config\ConfigImporter - * - * @todo Move into Config-specific test base class. - */ - protected function configImporter() { - if (!$this->configImporter) { - // Set up the ConfigImporter object for testing. - $storage_comparer = new StorageComparer( - $this->container->get('config.storage.sync'), - $this->container->get('config.storage'), - $this->container->get('config.manager') - ); - $this->configImporter = new ConfigImporter( - $storage_comparer, - $this->container->get('event_dispatcher'), - $this->container->get('config.manager'), - $this->container->get('lock'), - $this->container->get('config.typed'), - $this->container->get('module_handler'), - $this->container->get('module_installer'), - $this->container->get('theme_handler'), - $this->container->get('string_translation') - ); - } - // Always recalculate the changelist when called. - return $this->configImporter->reset(); - } - - /** - * Copies configuration objects from a source storage to a target storage. - * - * @param \Drupal\Core\Config\StorageInterface $source_storage - * The source config storage. - * @param \Drupal\Core\Config\StorageInterface $target_storage - * The target config storage. - * - * @todo Move into Config-specific test base class. - */ - protected function copyConfig(StorageInterface $source_storage, StorageInterface $target_storage) { - $target_storage->deleteAll(); - foreach ($source_storage->listAll() as $name) { - $target_storage->write($name, $source_storage->read($name)); - } - } - - /** * Stops test execution. */ protected function stop() { diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index 3beb32f..18e1b25 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -29,6 +29,7 @@ use Drupal\simpletest\NodeCreationTrait; use Drupal\user\Entity\Role; use Drupal\user\Entity\User; +use Drupal\Tests\ConfigTestTrait; use Symfony\Component\CssSelector\CssSelectorConverter; use Symfony\Component\HttpFoundation\Request; @@ -56,6 +57,7 @@ use ContentTypeCreationTrait { createContentType as drupalCreateContentType; } + use ConfigTestTrait; /** * Class loader. diff --git a/core/tests/Drupal/Tests/ConfigTestTrait.php b/core/tests/Drupal/Tests/ConfigTestTrait.php new file mode 100644 index 0000000..4316827 --- /dev/null +++ b/core/tests/Drupal/Tests/ConfigTestTrait.php @@ -0,0 +1,58 @@ +configImporter) { + // Set up the ConfigImporter object for testing. + $storage_comparer = new StorageComparer( + $this->container->get('config.storage.sync'), + $this->container->get('config.storage'), + $this->container->get('config.manager') + ); + $this->configImporter = new ConfigImporter( + $storage_comparer, + $this->container->get('event_dispatcher'), + $this->container->get('config.manager'), + $this->container->get('lock'), + $this->container->get('config.typed'), + $this->container->get('module_handler'), + $this->container->get('module_installer'), + $this->container->get('theme_handler'), + $this->container->get('string_translation') + ); + } + // Always recalculate the changelist when called. + return $this->configImporter->reset(); + } + + /** + * Copies configuration objects from source storage to target storage. + * + * @param \Drupal\Core\Config\StorageInterface $source_storage + * The source config storage service. + * @param \Drupal\Core\Config\StorageInterface $target_storage + * The target config storage service. + */ + public function copyConfig(StorageInterface $source_storage, StorageInterface $target_storage) { + $target_storage->deleteAll(); + foreach ($source_storage->listAll() as $name) { + $target_storage->write($name, $source_storage->read($name)); + } + } + +} diff --git a/core/tests/Drupal/Tests/WebAssert.php b/core/tests/Drupal/Tests/WebAssert.php index 6156dda..d4cffd8 100644 --- a/core/tests/Drupal/Tests/WebAssert.php +++ b/core/tests/Drupal/Tests/WebAssert.php @@ -191,6 +191,29 @@ public function optionNotExists($select, $option, TraversableElement $container } /** + * Checks that a specific option in a select field is selected. + * + * @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 optionSelected($select, $option, TraversableElement $container = NULL) { + $option_field = $this->optionExists($select, $option, $container); + $this->assert(!empty($option_field->getAttribute('selected')), sprintf('Option "%s" in select "%s" is not selected as expected.', $option, $select)); + + return $option_field; + } + + /** * Pass if the page title is the given string. * * @param string $expected_title