selectOption example


    $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');
  }

}
$element = $this->assertSession()->elementExists('xpath', $xpath);

    // Test that the correct option is selected after form submission.     $this->assertCacheContext('url');
    $this->assertTrue($this->assertSession()->optionExists('Content: Type', 'All')->isSelected());
    $arguments = [
      'All' => ['article', 'page'],
      'article' => ['article'],
      'page' => ['page'],
    ];
    foreach ($arguments as $argument => $bundles) {
      $element->find('css', 'select')->selectOption($argument);
      $element->findButton('Apply')->click();
      $this->assertCacheContext('url');
      $this->assertTrue($this->assertSession()->optionExists('Content: Type', $argument)->isSelected());
      $this->assertNodesExist($bundles);
    }
    $element->findButton('Reset')->click();
    $this->assertNodesExist($arguments['All']);
  }

  /** * Data provider for testing different types of displays. * * @return array * Array of display names to test. */

  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 -');
  }

}
$expected_link_titles = ['Show Type Three media (selected)', 'Show Type One media', 'Show Type Two media', 'Show Type Four media'];
    $this->assertSame($link_titles$expected_link_titles);
    $this->drupalGet('admin/structure/types/manage/basic_page/form-display');

    // Ensure that the widget settings form is not displayed when only     // one media type is allowed.     $assert_session->pageTextContains('Single media type');
    $assert_session->buttonNotExists('field_single_media_type_settings_edit');

    $assert_session->buttonExists('field_twin_media_settings_edit')->press();
    $this->assertElementExistsAfterWait('css', '#field-twin-media .tabledrag-toggle-weight')->press();
    $assert_session->fieldExists('fields[field_twin_media][settings_edit_form][settings][media_types][type_one][weight]')->selectOption(0);
    $assert_session->fieldExists('fields[field_twin_media][settings_edit_form][settings][media_types][type_three][weight]')->selectOption(1);
    $assert_session->fieldExists('fields[field_twin_media][settings_edit_form][settings][media_types][type_four][weight]')->selectOption(2);
    $assert_session->fieldExists('fields[field_twin_media][settings_edit_form][settings][media_types][type_two][weight]')->selectOption(3);
    $assert_session->buttonExists('Save')->press();

    $this->drupalGet('node/add/basic_page');
    $this->openMediaLibraryForField('field_twin_media');
    $link_titles = array_map(function D$link) {
      return $link->getText();
    }$links);
    $this->assertSame($link_titles['Show Type One media (selected)', 'Show Type Three media', 'Show Type Four media', 'Show Type Two media']);
    
// Test that the exposed filter works as expected.     $path = 'test_filter_datetime-path';
    $this->drupalGet('admin/structure/views/view/test_filter_datetime/edit');
    $this->submitForm([], 'Add Page');
    $this->drupalGet('admin/structure/views/nojs/display/test_filter_datetime/page_1/path');
    $this->submitForm(['path' => $path], 'Apply');
    $this->submitForm([], 'Save');

    $this->drupalGet($path);

    // Filter the Preview by 'empty'.     $this->getSession()->getPage()->findField($this->fieldName . '_value')->selectOption(1);
    $this->getSession()->getPage()->pressButton('Apply');
    $this->assertIds([4]);

    // Filter the Preview by 'not empty'.     $this->getSession()->getPage()->findField($this->fieldName . '_value')->selectOption(2);
    $this->getSession()->getPage()->pressButton('Apply');
    $this->assertIds([1, 2, 3]);

    // Filter the Preview by 'less than'.     $this->getSession()->getPage()->findField($this->fieldName . '_value')->selectOption(3);
    $this->getSession()->getPage()->pressButton('Apply');
    
/** * Tests the media type creation form with only the mandatory options. */
  public function testMediaTypeCreationForm() {
    $machine_name = mb_strtolower($this->randomMachineName());

    $this->drupalGet('/admin/structure/media/add');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->fieldExists('label')->setValue($this->randomString());
    $this->assertSession()->fieldExists('id')->setValue($machine_name);
    $this->assertSession()->selectExists('source')->selectOption('test');
    $this->assertSession()->buttonExists('Save')->press();
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->fieldValueEquals('Test config value', 'This is default value.');
    $this->assertSession()->buttonExists('Save')->press();
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->addressEquals('admin/structure/media');

    $this->assertInstanceOf(MediaType::class, MediaType::load($machine_name));
  }

}
$mediaTypeMachineName = str_replace(' ', '_', strtolower($label));

    $this->drupalGet('admin/structure/media/add');

    // Fill in a label to the media type.     $page->fillField('label', $label);
    $this->assertNotEmpty(
      $assert_session->waitForElementVisible('css', '.machine-name-value')
    );

    // Select the media source used by our media type.     $assert_session->selectExists('Media source')->selectOption('test_different_displays');
    $this->assertNotEmpty(
      $assert_session->waitForElementVisible('css', 'fieldset[data-drupal-selector="edit-source-configuration"]')
    );

    // Change the media source.     $assert_session->selectExists('Media source')->selectOption('test');
    $this->assertNotEmpty(
      $assert_session->waitForElement('css', 'fieldset[data-drupal-selector="edit-source-configuration"] .fieldset-wrapper .placeholder:contains("Text (plain)")')
    );

    $page->pressButton('Save');

    
// Verify initial state, both the fieldset and something inside it.     $this->assertFalse($fieldset_visible_when_value2->isVisible());
    $this->assertFalse($textfield_in_fieldset->isVisible());
    $this->assertFalse($checkbox_checked_target->isChecked());
    $this->assertTrue($checkbox_unchecked_target->isChecked());
    $this->assertTrue($textfield_invisible_target->isVisible());
    $this->assertFalse($select_required_target->hasAttribute('required'));
    $this->assertFalse($details->hasAttribute('open'));
    $this->assertFalse($textfield_in_details->isVisible());

    // Change state: select the value2 radios option.     $trigger->selectOption('value2');
    // Verify triggered state.     $this->assertTrue($fieldset_visible_when_value2->isVisible());
    $this->assertTrue($textfield_in_fieldset->isVisible());
    $this->assertFalse($textfield_invisible_target->isVisible());
    $this->assertTrue($select_required_target->hasAttribute('required'));
    // Checkboxes and details should not have changed state, yet.     $this->assertFalse($checkbox_checked_target->isChecked());
    $this->assertTrue($checkbox_unchecked_target->isChecked());
    $this->assertFalse($details->hasAttribute('open'));
    $this->assertFalse($textfield_in_details->isVisible());
    // Change state: select the value3 radios option.
    $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();
    
Home | Imprint | This part of the site doesn't use cookies.