selectFieldOption example

$page = $session->getPage();
    $assert_session = $this->assertSession();

    $this->drupalGet('admin/structure/media/add');
    $page->fillField('label', $media_type_id);
    $this->getSession()
      ->wait(5000, "jQuery('.machine-name-value').text() === '{$media_type_id}'");

    // Make sure the source is available.     $assert_session->fieldExists('Media source');
    $assert_session->optionExists('Media source', $source_id);
    $page->selectFieldOption('Media source', $source_id);
    $result = $assert_session->waitForElementVisible('css', 'fieldset[data-drupal-selector="edit-source-configuration"]');
    $this->assertNotEmpty($result);

    $assert_session->pageTextContains('It is potentially insecure to display oEmbed content in a frame');

    $this->config('media.settings')->set('iframe_domain', 'http://example.com')->save();

    $this->drupalGet('admin/structure/media/add');
    $page->fillField('label', $media_type_id);
    $this->getSession()
      ->wait(5000, "jQuery('.machine-name-value').text() === '{$media_type_id}'");

    
public function testMediaWizard() {
    $session = $this->getSession();
    $page = $session->getPage();
    $assert_session = $this->assertSession();

    $this->createMediaType('test');

    $view_id = strtolower($this->randomMachineName(16));
    $this->drupalGet('admin/structure/views/add');
    $page->fillField('label', $view_id);
    $this->waitUntilVisible('.machine-name-value');
    $page->selectFieldOption('show[wizard_key]', 'media');
    $result = $assert_session->waitForElementVisible('css', 'select[data-drupal-selector="edit-show-type"]');
    $this->assertNotEmpty($result);
    $page->checkField('page[create]');
    $page->fillField('page[path]', $this->randomMachineName(16));
    $page->pressButton('Save and edit');
    $this->assertSame($session->getCurrentUrl()$this->baseUrl . '/admin/structure/views/view/' . $view_id);

    $view = Views::getView($view_id);
    $view->initHandlers();
    $row = $view->display_handler->getOption('row');
    $this->assertSame($row['type'], 'fields');
    
$this->drupalGet('admin/structure/media');
    $assert_session->pageTextContains('No media types available. Add media type.');
    $assert_session->linkExists('Add media type');

    // Test the creation of a media type using the UI.     $name = $this->randomMachineName();
    $description = $this->randomMachineName();
    $this->drupalGet('admin/structure/media/add');
    $page->fillField('label', $name);
    $machine_name = strtolower($name);
    $this->assertJsCondition("jQuery('.machine-name-value').html() == '$machine_name'");
    $page->selectFieldOption('source', 'test');
    $this->assertJsCondition("jQuery('.form-item-source-configuration-test-config-value').length > 0");
    $page->fillField('description', $description);
    $page->pressButton('Save');
    // The wait prevents intermittent test failures.     $result = $assert_session->waitForLink('Add media type');
    $this->assertNotEmpty($result);
    $assert_session->addressEquals('admin/structure/media');
    $assert_session->pageTextContains('The media type ' . $name . ' has been added.');
    $this->drupalGet('admin/structure/media');
    $assert_session->pageTextContains($name);
    $assert_session->pageTextContains($description);

    
public function testSimpleAJAXFormValue() {
    $this->drupalGet('ajax_forms_test_get_form');
    $build_id_initial = $this->getFormBuildId();

    // Changing the value of a select input element, triggers an AJAX     // request/response. The callback on the form responds with three AJAX     // commands:     // - UpdateBuildIdCommand     // - HtmlCommand     // - DataCommand     $session = $this->getSession();
    $session->getPage()->selectFieldOption('select', 'green');

    // Wait for the DOM to update. The HtmlCommand will update     // #ajax_selected_color to reflect the color change.     $green_span = $this->assertSession()->waitForElement('css', "#ajax_selected_color:contains('green')");
    $this->assertNotNull($green_span, 'DOM update: The selected color SPAN is green.');

    // Confirm the operation of the UpdateBuildIdCommand.     $build_id_first_ajax = $this->getFormBuildId();
    $this->assertNotEquals($build_id_initial$build_id_first_ajax, 'Build id is changed in the form_build_id element on first AJAX submission');

    // Changing the value of a select input element, triggers an AJAX
// Create custom fields for the media type to store metadata attributes.     $fields = [
      'field_string_width' => 'string',
      'field_string_height' => '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}");
    $page->selectFieldOption("field_map[" . Image::METADATA_ATTRIBUTE_WIDTH . "]", 'field_string_width');
    $page->selectFieldOption("field_map[" . Image::METADATA_ATTRIBUTE_HEIGHT . "]", 'field_string_height');
    $page->pressButton('Save');

    // Create a media item.     $this->drupalGet("media/add/{$media_type_id}");
    $page->attachFileToField("files[{$source_field_id}_0]", $this->root . '/core/modules/media/tests/fixtures/example_1.jpeg');
    $result = $assert_session->waitForButton('Remove');
    $this->assertNotEmpty($result);
    $page->fillField("{$source_field_id}[0][alt]", 'Image Alt Text 1');
    $page->pressButton('Save');

    
$page->fillField('name', 'trigger validator');
    $assert_session->waitForText('Machine name');
    $page->checkField('roles[authenticated]');

    // Enable a filter that is incompatible with CKEditor 5, so validation is     // triggered when attempting to switch.     $incompatible_filter_name = 'filters[filter_incompatible][status]';
    $this->assertTrue($page->hasUncheckedField($incompatible_filter_name));
    $page->checkField($incompatible_filter_name);
    $this->assertSame(0, $this->getAjaxResponseCount());

    $page->selectFieldOption('editor[editor]', 'ckeditor5');
    $assert_session->assertWaitOnAjaxRequest();
    $this->assertSame(1, $this->getAjaxResponseCount());

    $filter_warning = 'CKEditor 5 only works with HTML-based text formats. The "A TYPE_MARKUP_LANGUAGE filter incompatible with CKEditor 5" (filter_incompatible) filter implies this text format is not HTML anymore.';

    // The presence of this validation error message confirms the AJAX callback     // was invoked.     $assert_session->pageTextContains($filter_warning);

    // Disable the incompatible filter. This should trigger another AJAX rebuild     // which will include the removal of the validation error as the issue has
$page = $session->getPage();
    $assert_session = $this->assertSession();

    $this->drupalGet('admin/structure/media/add');
    $page->fillField('label', $media_type_id);
    $this->getSession()
      ->wait(5000, "jQuery('.machine-name-value').text() === '{$media_type_id}'");

    // Make sure the source is available.     $assert_session->fieldExists('Media source');
    $assert_session->optionExists('Media source', $source_id);
    $page->selectFieldOption('Media source', $source_id);
    $result = $assert_session->waitForElementVisible('css', 'fieldset[data-drupal-selector="edit-source-configuration"]');
    $this->assertNotEmpty($result);

    // Make sure the provided fields are visible on the form.     foreach ($provided_fields as $provided_field) {
      $result = $assert_session->waitForElementVisible('css', 'select[name="field_map[' . $provided_field . ']"]');
      $this->assertNotEmpty($result);
    }

    // Save the form to create the type.     $page->pressButton('Save');
    
'media_save_action',
      'media_unpublish_action',
    ];
    foreach ($available_actions as $action_name) {
      $assert_session->optionExists('action', $action_name);
    }

    // Test unpublishing in bulk.     $page->checkField('media_bulk_form[0]');
    $page->checkField('media_bulk_form[1]');
    $page->checkField('media_bulk_form[2]');
    $page->selectFieldOption('action', 'media_unpublish_action');
    $page->pressButton('Apply to selected items');
    $assert_session->pageTextContains('Unpublish media was applied to 3 items');
    $this->assertFalse($this->storage->loadUnchanged(1)->isPublished(), 'The unpublish action failed in some of the media items.');
    $this->assertFalse($this->storage->loadUnchanged(2)->isPublished(), 'The unpublish action failed in some of the media items.');
    $this->assertFalse($this->storage->loadUnchanged(3)->isPublished(), 'The unpublish action failed in some of the media items.');

    // Test publishing in bulk.     $page->checkField('media_bulk_form[0]');
    $page->checkField('media_bulk_form[1]');
    $page->selectFieldOption('action', 'media_publish_action');
    $page->pressButton('Apply to selected items');
    
$block_url = 'admin/structure/block/add/field_block_test%3Auser%3Auser%3Afield_date/starterkit_theme';
    $assert_session->linkByHrefExists($block_url);

    $this->drupalGet($block_url);
    $page->fillField('region', 'content');

    // Assert the default formatter configuration.     $assert_session->fieldValueEquals('settings[formatter][type]', 'datetime_default');
    $assert_session->fieldValueEquals('settings[formatter][settings][format_type]', 'medium');

    // Change the formatter.     $page->selectFieldOption('settings[formatter][type]', 'datetime_time_ago');
    $assert_session->assertWaitOnAjaxRequest();
    // Changing the formatter removes the old settings and introduces new ones.     $assert_session->fieldNotExists('settings[formatter][settings][format_type]');
    $assert_session->fieldExists('settings[formatter][settings][granularity]');
    $page->pressButton('Save block');
    $this->assertTrue($assert_session->waitForText('The block configuration has been saved.'));

    // Configure the block and change the formatter again.     $this->clickLink('Configure');
    $page->selectFieldOption('settings[formatter][type]', 'datetime_default');
    $assert_session->assertWaitOnAjaxRequest();
    
/** * Tests that editor selection can be toggled without breaking ajax. */
  public function testEditorSelection() {
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    $this->drupalGet('/admin/config/content/formats/add');
    $page->fillField('name', 'Sulaco');
    // Wait for machine name to be filled in.     $this->assertNotEmpty($assert_session->waitForText('sulaco'));
    $page->selectFieldOption('editor[editor]', 'unicorn');
    $this->assertNotEmpty($this->assertSession()->waitForField('editor[settings][ponies_too]'));
    $page->pressButton('Save configuration');

    // Test that toggling the editor selection off and back on works.     $this->drupalGet('/admin/config/content/formats/manage/sulaco');
    // Deselect and reselect an editor.     $page->selectFieldOption('editor[editor]', '');
    $this->assertNotEmpty($this->assertSession()->waitForElementRemoved('named', ['field', 'editor[settings][ponies_too]']));
    $page->selectFieldOption('editor[editor]', 'unicorn');
    $this->assertNotEmpty($this->assertSession()->waitForField('editor[settings][ponies_too]'));
  }

  
// Verify that the media name does not contain a link. The selector is     // tricky, so start by asserting ".js-media-library-item-preview + div"     // can select a div containing a media name.     $assert_session->elementExists('css', '.js-media-library-item-preview + div:contains("Dog")');
    $assert_session->elementExists('css', '.js-media-library-item-preview + div:contains("Turtle")');
    $assert_session->elementNotExists('css', '.js-media-library-item-preview + div a');
    // Verify that there are links to edit and delete media items.     $assert_session->linkExists('Edit Dog');
    $assert_session->linkExists('Delete Turtle');

    // Test that users can filter by type.     $page->selectFieldOption('Media type', 'Type One');
    $page->pressButton('Apply filters');
    $this->waitForNoText('Turtle');
    $assert_session->pageTextContains('Dog');
    $page->selectFieldOption('Media type', 'Type Two');
    $page->pressButton('Apply filters');
    $this->waitForText('Turtle');
    $assert_session->pageTextNotContains('Dog');

    // Test that selecting elements as a part of bulk operations works.     $page->selectFieldOption('Media type', '- Any -');
    $assert_session->elementExists('css', '#views-exposed-form-media-library-page')->submit();
    
// Create custom fields for the media type to store metadata attributes.     $fields = [
      'field_string_file_size' => 'string',
      'field_string_mime_type' => '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}");
    $page->selectFieldOption("field_map[" . File::METADATA_ATTRIBUTE_NAME . "]", 'name');
    $page->selectFieldOption("field_map[" . File::METADATA_ATTRIBUTE_SIZE . "]", 'field_string_file_size');
    $page->selectFieldOption("field_map[" . File::METADATA_ATTRIBUTE_MIME . "]", 'field_string_mime_type');
    $page->pressButton('Save');

    $test_filename = $this->randomMachineName() . '.txt';
    $test_filepath = 'public://' . $test_filename;
    file_put_contents($test_filepath$this->randomMachineName());

    // Create a media item.     $this->drupalGet("media/add/{$media_type_id}");
    $page->attachFileToField("files[{$source_field_id}_0]", \Drupal::service('file_system')->realpath($test_filepath));
    
$session_assert = $this->assertSession();

    $page = $this->getSession()->getPage();

    $settings = $this->getDrupalSettings();

    // Make sure that the view_path is set correctly.     $expected_view_path = '/test-content-ajax';
    $this->assertEquals($expected_view_pathcurrent($settings['views']['ajaxViews'])['view_path']);

    // Set the number of items displayed per page to 5 using the exposed pager.     $page->selectFieldOption('edit-items-per-page', 5);
    $page->pressButton('Filter');
    $session_assert->assertWaitOnAjaxRequest();

    // Change 'Updated' sorting from descending to ascending.     $page->clickLink('Updated');
    $session_assert->assertWaitOnAjaxRequest();

    // Use the pager by clicking on the links and test if we see the expected     // number of rows on each page. For easy targeting the titles of the pager     // links are used.     /** @var \Behat\Mink\Element\NodeElement[] $rows */
    
$this->drupalGet('entity_test/1');
    $this->assertSession()->elementNotExists('css', '.layout__region--content');

    // Change the layout for the "test" view mode. See     // core.entity_view_mode.entity_test.test.yml.     $this->drupalGet('entity_test/structure/entity_test/display');
    $this->click('#edit-modes');
    $this->getSession()->getPage()->checkField('display_modes_custom[test]');
    $this->submitForm([], 'Save');
    $this->clickLink('configure them');
    $this->getSession()->getPage()->pressButton('Show row weights');
    $this->getSession()->getPage()->selectFieldOption('fields[field_test_text][region]', 'content');
    $this->assertSession()->assertWaitOnAjaxRequest();
    $this->submitForm([], 'Save');

    // Each view mode has a different layout.     $this->drupalGet('entity_test/1/test');
    $this->assertSession()->elementTextContains('css', '.layout__region--content', 'The field test text value');
    $this->drupalGet('entity_test/1');
    $this->assertSession()->elementNotExists('css', '.layout__region--content');
  }

  /** * Tests the use of field layout for entity form displays. */
$this->drupalLogin($this->drupalCreateUser([
      'export configuration',
    ]));

    $page = $this->getSession()->getPage();

    // Check that the export is empty on load.     $this->drupalGet('admin/config/development/configuration/single/export');
    $this->assertSession()->fieldValueEquals('export', '');

    // Check that the export is filled when selecting a config name.     $page->selectFieldOption('config_name', 'system.site');
    $this->assertSession()->assertWaitOnAjaxRequest();
    $this->assertSession()->fieldValueNotEquals('export', '');

    // Check that the export is emptied again when selecting a config type.     $page->selectFieldOption('config_type', 'Action');
    $this->assertSession()->assertWaitOnAjaxRequest();
    $this->assertSession()->fieldValueEquals('export', '');
  }

}
Home | Imprint | This part of the site doesn't use cookies.