selectExists example

$this->drupalGet('admin/config/content/formats/manage/filtered_html');

    // Ensure the form field order is correct.     $raw_content = $this->getSession()->getPage()->getContent();
    $roles_pos = strpos($raw_content, 'Roles');
    $editor_pos = strpos($raw_content, 'Text editor');
    $filters_pos = strpos($raw_content, 'Enabled filters');
    $this->assertGreaterThan($roles_pos$editor_pos);
    $this->assertLessThan($filters_pos$editor_pos);

    // Verify the <select>.     $select = $this->assertSession()->selectExists('editor[editor]');
    $this->assertSame('disabled', $select->getAttribute('disabled'));
    $options = $select->findAll('css', 'option');
    $this->assertCount(1, $options);
    $this->assertSame('None', $options[0]->getText(), 'Option 1 in the Text Editor select is "None".');
    $this->assertSession()->pageTextContains('This option is disabled because no modules that provide a text editor are currently enabled.');
  }

  /** * Tests adding a text editor to an existing text format. */
  public function testAddEditorToExistingFormat() {
    
    $assert->fieldExists('Name')->setValue('test 1');
    $machine_name_value = $page->find('css', '#edit-name-machine-name-suffix .machine-name-value');
    $this->assertNotEmpty($machine_name_value, 'Machine name field must be initialized');
    $this->assertJsCondition('jQuery("#edit-name-machine-name-suffix .machine-name-value").html() == "' . 'test_1' . '"');

    // Ensure that machine name generation still occurs after a non-HTML 5     // validation failure.     $this->assertEquals('test_1', $machine_name_value->getHtml()$test_values[1]['message']);
    $machine_name_wrapper = $page->find('css', '#edit-id')->getParent();
    // Machine name field should not expand after failing validation.     $this->assertTrue($machine_name_wrapper->hasClass('hidden'), 'The ID field must not be visible');
    $assert->selectExists('snack')->selectOption('apple');
    $assert->assertWaitOnAjaxRequest();
    $assert->buttonExists('Save')->press();
    $assert->pageTextContains('The form_test_machine_name_validation_form form has been submitted successfully.');

    // Test errors after using AJAX.     $assert->fieldExists('Name')->setValue('duplicate');
    $this->assertJsCondition('document.forms[0].id.value === "duplicate"');
    $assert->fieldExists('id2')->setValue('duplicate2');
    $assert->selectExists('snack')->selectOption('potato');
    $assert->assertWaitOnAjaxRequest();
    $assert->buttonExists('Save')->press();
    
/** * Checks if a select element contains the specified options. * * @param string $name * The field name. * @param array $expected_options * An array of expected options. * * @internal */
  protected function assertFieldSelectOptions(string $name, array $expected_options): void {
    $field = $this->assertSession()->selectExists($name);
    $options = $field->findAll('xpath', 'option');
    $optgroups = $field->findAll('xpath', 'optgroup');
    $nested_options = [];
    foreach ($optgroups as $optgroup) {
      $nested_options[] = $optgroup->findAll('xpath', 'option');
    }
    $options = array_merge($options, ...$nested_options);
    array_walk($optionsfunction DNodeElement &$option) {
      $option = $option->getAttribute('value');
    });
    $this->assertEqualsCanonicalizing($expected_options$options);
  }
// Check that selecting the 'none' option empties the field.     $edit = ['card_2[]' => ['_none' => '_none']];
    $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
    $this->submitForm($edit, 'Save');
    $this->assertFieldValues($entity_init, 'card_2', []);

    // A required select list does not have an empty key.     $field->setRequired(TRUE);
    $field->save();
    $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
    $this->assertEmpty($this->assertSession()->selectExists('edit-card-2')->find('xpath', 'option[@value=""]'));

    // We do not have to test that a required select list with one option is     // auto-selected because the browser does it for us.
    // Test optgroups.
    // Use a callback function defining optgroups.     $this->card2->setSetting('allowed_values', []);
    $this->card2->setSetting('allowed_values_function', 'options_test_allowed_values_callback');
    $this->card2->save();
    $field->setRequired(FALSE);
    
$this->drupalGet($style_path);
    $this->submitForm($edit, 'Save');

    // Note that after changing the style name, the style path is changed.     $style_path = 'admin/config/media/image-styles/manage/' . $style_name;

    // Check that the URL was updated.     $this->drupalGet($style_path);
    $this->assertSession()->titleEquals("Edit style $style_label | Drupal");

    // Check that the available image effects are properly sorted.     $option = $this->assertSession()->selectExists('edit-new--2')->findAll('css', 'option');
    $this->assertEquals('Ajax test', $option[1]->getText(), '"Ajax test" is the first selectable effect.');

    // Check that the image was flushed after updating the style.     // This is especially important when renaming the style. Make sure that     // the old image directory has been deleted.     $this->assertEquals(0, $this->getImageCount($style)new FormattableMarkup('Image style %style was flushed after renaming the style and updating the order of effects.', ['%style' => $style->label()]));

    // Load the style by the new name with the new weights.     $style = ImageStyle::load($style_name);

    // Confirm the new style order was saved.
'field_string_height' => 'string',
      'field_string_author_name' => 'string',
    ];
    $this->createMediaTypeFields($fields$media_type_id);

    // Hide the name field widget to test default name generation.     $this->hideMediaTypeFieldWidget('name', $media_type_id);

    $this->drupalGet("admin/structure/media/manage/$media_type_id");
    // Only accept Vimeo videos.     $page->checkField("source_configuration[providers][Vimeo]");
    $assert_session->selectExists('field_map[width]')->setValue('field_string_width');
    $assert_session->selectExists('field_map[height]')->setValue('field_string_height');
    $assert_session->selectExists('field_map[author_name]')->setValue('field_string_author_name');
    $assert_session->buttonExists('Save')->press();

    // Configure the iframe to be narrower than the actual video, so we can     // verify that the video scales correctly.     $display = \Drupal::service('entity_display.repository')->getViewDisplay('media', $media_type_id);
    $this->assertFalse($display->isNew());
    $component = $display->getComponent('field_media_oembed_video');
    $this->assertIsArray($component);
    $component['settings']['max_width'] = 240;
    

  public function testBlockAddThemeSelector() {
    \Drupal::service('theme_installer')->install(['claro']);

    $this->drupalLogin($this->drupalCreateUser([
      'administer blocks',
    ]));

    $this->drupalGet('admin/structure/block/add/system_powered_by_block');
    $assert_session = $this->assertSession();
    // Pick a theme with a region that does not exist in another theme.     $assert_session->selectExists('Theme')->selectOption('claro');
    $assert_session->assertWaitOnAjaxRequest();
    $assert_session->selectExists('Region')->selectOption('pre_content');
    $assert_session->assertWaitOnAjaxRequest();
    // Switch to a theme that doesn't contain the region selected above.     $assert_session->selectExists('Theme')->selectOption('stark');
    $assert_session->assertWaitOnAjaxRequest();
    $assert_session->pageTextNotContains('The submitted value Pre-content in the Region element is not allowed.');
    $assert_session->optionExists('Region', '- Select -');
  }

}
    $this->entity->save();

    // Create a web user.     $web_user = $this->drupalCreateUser([
      'view test entity',
      'administer entity_test content',
    ]);
    $this->drupalLogin($web_user);

    // Display form.     $this->drupalGet('entity_test_rev/manage/' . $this->entity->id() . '/edit');
    $options = $this->assertSession()->selectExists('edit-test-options')->findAll('css', 'option');
    $this->assertCount(count($this->test) + 1, $options);
    foreach ($options as $option) {
      $value = $option->getValue();
      if ($value != '_none') {
        $this->assertContains($value$this->test);
      }
    }
  }

}
'source' => 'Spanish',
      'context' => '',
    ])->save();
    $this->storage->createTranslation([
      'lid' => $source->lid,
      'language' => 'fr',
      'translation' => 'Espagnol',
    ])->save();

    // Get language list displayed in select list.     $this->drupalGet('fr/admin/config/regional/language/add');
    $options = $this->assertSession()->selectExists('edit-predefined-langcode')->findAll('css', 'option');
    $options = array_map(function D$item) {
      return $item->getText();
    }$options);
    // Remove the 'Custom language...' option form the end.     array_pop($options);
    // Order language list.     $options_ordered = $options;
    natcasesort($options_ordered);

    // Check the language list displayed is ordered.     $this->assertSame($options$options_ordered, 'Language list is ordered.');
  }

  protected function assertOptions(string $id, array $expected_options, string $selected): void {
    $select = $this->assertSession()->selectExists($id);
    $found_options = $select->findAll('css', 'option');
    $found_options = array_map(function D$item) {
      return $item->getValue();
    }$found_options);
    $this->assertEqualsCanonicalizing($expected_options$found_options);
    $this->assertTrue($this->assertSession()->optionExists($id$selected)->isSelected());
  }

  /** * Asserts that there is a select element with the given ID that is required. * * @param string $id * The HTML ID of the select element. * @param array $options * An array of option values that are contained in the select element * besides the "- Select -" option. * * @internal */
$this->assertEquals($expected_states[$key]$element->find('xpath', 'td')->getText());
    }
    $expected_transitions = ['one', 'two a', 'two b', 'three'];
    $elements = $this->xpath('//details[@id="edit-transitions-container"]//table/tbody/tr');
    foreach ($elements as $key => $element) {
      $this->assertEquals($expected_transitions[$key]$element->find('xpath', 'td')->getText());
    }

    // Ensure that there are enough weights to satisfy the potential number of     // states and transitions.     $this->assertSession()
      ->selectExists('states[three][weight]')
      ->selectOption('2');
    $this->assertSession()
      ->selectExists('states[three][weight]')
      ->selectOption('-2');
    $this->assertSession()
      ->selectExists('transitions[three][weight]')
      ->selectOption('2');
    $this->assertSession()
      ->selectExists('transitions[three][weight]')
      ->selectOption('-2');
  }

}

  protected function getOptions($select, Element $container = NULL) {
    if (is_string($select)) {
      $select = $this->assertSession()->selectExists($select$container);
    }
    $options = [];
    /** @var \Behat\Mink\Element\NodeElement $option */
    foreach ($select->findAll('xpath', '//option') as $option) {
      $label = $option->getText();
      $value = $option->getAttribute('value') ?: $label;
      $options[$value] = $label;
    }
    return $options;
  }

  
    // lists, such as in Views UI.     $this->drupalGet('admin/config/regional/content-language');

    $expected_elements = [
      'site_default',
      'current_interface',
      'authors_default',
      'en',
      'und',
      'zxx',
    ];
    $options = $this->assertSession()->selectExists('edit-settings-node-article-settings-language-langcode')->findAll('css', 'option');
    $options = array_map(function D$item) {
      return $item->getValue();
    }$options);
    $this->assertSame($expected_elements$options);
  }

  /** * Tests the language settings checkbox on account settings page. */
  public function testAccountLanguageSettingsUI() {
    // Make sure the checkbox is available and not checked by default.
$this->setUpFields();
  }

  /** * Tests basic field handler settings in the UI. */
  public function testHandlerUI() {
    $url = "admin/structure/views/nojs/handler/test_view_fieldapi/default/field/field_name_0";
    $this->drupalGet($url);

    // Tests the available formatter options.     $options = $this->assertSession()->selectExists('edit-options-type')->findAll('css', 'option');
    $options = array_map(function D$item) {
      return $item->getValue();
    }$options);
    $this->assertEqualsCanonicalizing(['text_default', 'text_trimmed']$options);

    $this->submitForm(['options[type]' => 'text_trimmed'], 'Apply');

    $this->drupalGet($url);
    $this->assertTrue($this->assertSession()->optionExists('edit-options-type', 'text_trimmed')->isSelected());

    $random_number = rand(100, 400);
    
$view->setDisplay();
    $sorts = $view->display_handler->getOption('sorts');
    // Change the label to something with special characters.     $sorts['id']['expose']['label'] = $expected_label = "<script>alert('unsafe&dangerous');</script>";
    // Use a custom sort field identifier.     $sorts['id']['expose']['field_identifier'] = $field_identifier = $this->randomMachineName() . '-_.~';
    $view->display_handler->setOption('sorts', $sorts);
    $view->save();

    // Test label escaping.     $this->drupalGet('test_exposed_form_sort_items_per_page');
    $options = $this->assertSession()->selectExists('edit-sort-by')->findAll('css', 'option');
    $this->assertCount(1, $options);
    // Check option existence by option label.     $this->assertSession()->optionExists('Sort by', $expected_label);
    // Check option existence by option value.     $this->assertSession()->optionExists('Sort by', $field_identifier);
    $escape_1 = Html::escape($expected_label);
    $escape_2 = Html::escape($escape_1);
    // Make sure we see the single-escaped string in the raw output.     $this->assertSession()->responseContains($escape_1);
    // But no double-escaped string.     $this->assertSession()->responseNotContains($escape_2);
    
Home | Imprint | This part of the site doesn't use cookies.