switchToMediaType example


  public function testUnlimitedCardinality(?string $selected_operation): void {
    if ($selected_operation) {
      $this->config('media_library.settings')->set('advanced_ui', TRUE)->save();
    }

    $assert_session = $this->assertSession();
    // Visit a node create page and open the media library.     $this->drupalGet('node/add/basic_page');
    $this->openMediaLibraryForField('field_unlimited_media');
    $this->switchToMediaType('Three');
    $this->uploadFiles(5);
    if ($selected_operation) {
      $this->saveAnd($selected_operation);
    }
    else {
      $this->pressSaveButton();
    }

    if ($selected_operation !== 'insert') {
      $this->pressInsertSelected();
    }
    
// Visit a node create page and open the media library.     $this->drupalGet('node/add/basic_page');
    $this->openMediaLibraryForField('field_twin_media');

    // Assert the upload form is not visible for default tab type_three without     // the proper permissions.     $assert_session->elementNotExists('css', '.js-media-library-add-form');

    // Assert the upload form is not visible for the non-file based media type     // type_one.     $this->switchToMediaType('One');
    $assert_session->elementNotExists('css', '.js-media-library-add-form');

    // Assert the upload form is visible for type_four.     $this->switchToMediaType('Four');
    $assert_session->fieldExists('Add files');
    $assert_session->pageTextContains('Maximum 2 files.');

    // Create a user that can create media for all media types.     $user = $this->drupalCreateUser([
      'access administration pages',
      'access content',
      
// Assert generic media library elements.     $this->openMediaLibraryForField('field_unlimited_media');
    $assert_session->elementExists('css', '.ui-dialog-titlebar-close')->click();

    // Assert that the media type menu is available when more than 1 type is     // configured for the field.     $menu = $this->openMediaLibraryForField('field_unlimited_media');
    $this->assertTrue($menu->hasLink('Show Type One media (selected)'));
    $this->assertFalse($menu->hasLink('Type Two'));
    $this->assertTrue($menu->hasLink('Type Three'));
    $this->assertFalse($menu->hasLink('Type Four'));
    $this->switchToMediaType('Three');
    // Assert the active tab is set correctly.     $this->assertFalse($menu->hasLink('Show Type One media (selected)'));
    $this->assertTrue($menu->hasLink('Show Type Three media (selected)'));
    // Assert the focus is set to the first tabbable element when a vertical tab     // is clicked.     $this->assertJsCondition('jQuery(tabbable.tabbable(document.getElementById("media-library-content"))[0]).is(":focus")');
    $assert_session->elementExists('css', '.ui-dialog-titlebar-close')->click();

    // Assert that there are no links in the media library view.     $this->openMediaLibraryForField('field_unlimited_media');
    $assert_session->elementNotExists('css', '.media-library-item__name a');
    
// Visit a node create page.     $this->drupalGet('node/add/basic_page');

    // Add to the unlimited media field.     $this->openMediaLibraryForField('field_unlimited_media');

    // Assert the default tab for media type one does not have an oEmbed form.     $assert_session->fieldNotExists('Add Type Five via URL');

    // Assert other media types don't have the oEmbed form fields.     $this->switchToMediaType('Three');
    $assert_session->fieldNotExists('Add Type Five via URL');

    // Assert we can add an oEmbed video to media type five.     $this->switchToMediaType('Five');
    $page->fillField('Add Type Five via URL', $youtube_url);
    $assert_session->pageTextContains('Allowed providers: YouTube, Vimeo.');
    $page->pressButton('Add');
    // assertWaitOnAjaxRequest() required for input "id" attributes to     // consistently match their label's "for" attribute.     $assert_session->assertWaitOnAjaxRequest();
    $this->waitForText('The media item has been created but has not yet been saved.');
    
Home | Imprint | This part of the site doesn't use cookies.