Skip to content
Snippets Groups Projects
Commit d2f5b62f authored by Jess's avatar Jess
Browse files

Issue #2907485 by Lendude, jonathan1055: Add getAllOptions() to AssertLegacyTrait

parent 2e3db915
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -115,6 +115,14 @@ public function buildForm(array $form, FormStateInterface $form_state) { ...@@ -115,6 +115,14 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#multiple' => TRUE, '#multiple' => TRUE,
]; ];
$form['opt_groups'] = [
'#type' => 'select',
'#options' => [
'optgroup_one' => ['one' => 'one', 'two' => 'two', 'three' => 'three', 'four' => '<strong>four</strong>'],
'optgroup_two' => ['five' => 'five', 'six' => 'six'],
],
];
$form['submit'] = ['#type' => 'submit', '#value' => 'Submit']; $form['submit'] = ['#type' => 'submit', '#value' => 'Submit'];
return $form; return $form;
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\FunctionalTests; namespace Drupal\FunctionalTests;
use Behat\Mink\Element\NodeElement;
use Behat\Mink\Exception\ExpectationException; use Behat\Mink\Exception\ExpectationException;
use Behat\Mink\Selector\Xpath\Escaper; use Behat\Mink\Selector\Xpath\Escaper;
use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Render\FormattableMarkup;
...@@ -812,4 +813,21 @@ protected function getRawContent() { ...@@ -812,4 +813,21 @@ protected function getRawContent() {
return $this->getSession()->getPage()->getContent(); return $this->getSession()->getPage()->getContent();
} }
/**
* Get all option elements, including nested options, in a select.
*
* @param \Behat\Mink\Element\NodeElement $element
* The element for which to get the options.
*
* @return \Behat\Mink\Element\NodeElement[]
* Option elements in select.
*
* @deprecated Scheduled for removal in Drupal 9.0.0.
* Use $element->findAll('xpath', 'option') instead.
*/
protected function getAllOptions(NodeElement $element) {
@trigger_error('AssertLegacyTrait::getAllOptions() is scheduled for removal in Drupal 9.0.0. Use $element->findAll(\'xpath\', \'option\') instead.', E_USER_DEPRECATED);
return $element->findAll('xpath', '//option');
}
} }
...@@ -434,6 +434,10 @@ public function testLegacyFieldAssertsForOptions() { ...@@ -434,6 +434,10 @@ public function testLegacyFieldAssertsForOptions() {
catch (\PHPUnit_Framework_ExpectationFailedException $e) { catch (\PHPUnit_Framework_ExpectationFailedException $e) {
$this->pass($e->getMessage()); $this->pass($e->getMessage());
} }
// Test \Drupal\FunctionalTests\AssertLegacyTrait::getAllOptions.
$this->drupalGet('/form-test/select');
$this->assertCount(6, $this->getAllOptions($this->cssSelect('select[name="opt_groups"]')[0]));
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment