pressButton example


  protected function getPreviewAJAX($view_name$panel_id$row_count) {
    $this->drupalGet('admin/structure/views/view/' . $view_name . '/edit/' . $panel_id);
    $this->getSession()->getPage()->pressButton('Update preview');
    $this->assertSession()->assertWaitOnAjaxRequest();
    $this->assertPreviewAJAX($row_count);
  }

  /** * Click on a preview link. * * @param \Behat\Mink\Element\NodeElement $element * The element to click. * @param int $row_count * The expected number of rows in the preview. */
/** * Tests that after removing sections reloading the page does not re-add them. */
  public function testReloadWithNoSections() {
    $assert_session = $this->assertSession();
    $page = $this->getSession()->getPage();

    // Remove all of the sections from the page.     $this->drupalGet(static::FIELD_UI_PREFIX . '/display/default/layout');
    $page->clickLink('Remove Section 1');
    $assert_session->assertWaitOnAjaxRequest();
    $page->pressButton('Remove');
    $assert_session->assertWaitOnAjaxRequest();
    // Assert that there are no sections on the page.     $assert_session->pageTextNotContains('Remove Section 1');
    $assert_session->pageTextNotContains('Add block');

    // Reload the page.     $this->drupalGet(static::FIELD_UI_PREFIX . '/display/default/layout');
    // Assert that there are no sections on the page.     $assert_session->pageTextNotContains('Remove Section 1');
    $assert_session->pageTextNotContains('Add block');
  }

  

    _menu_ui_node_save($node[
      'title' => 'bar',
      'menu_name' => 'main',
      'description' => 'view bar',
      'parent' => '',
    ]);

    $this->drupalGet($node->toUrl());
    // Publish the node. Revision count: 2.     $page->fillField('new_state', 'published');
    $page->pressButton('Apply');

    // Modify the layout.     $page->clickLink('Layout');
    $assert_session->checkboxChecked('revision');
    $assert_session->fieldDisabled('revision');

    $page->clickLink('Add block');
    $page->clickLink('Powered by Drupal');
    $page->pressButton('Add block');
    // Save the node as a draft. Revision count: 3.     $page->fillField('moderation_state[0][state]', 'draft');
    
// First step: 'Add new field' on the 'Manage fields' page.     $this->drupalGet($bundle_path . '/fields/add-field');

    // Check if the commonly referenced entity types appear in the list.     $this->assertSession()->optionExists('edit-new-storage-type', 'field_ui:entity_reference:node');
    $this->assertSession()->optionExists('edit-new-storage-type', 'field_ui:entity_reference:user');

    $page->findField('new_storage_type')->setValue('entity_reference');
    $assert_session->waitForField('label')->setValue('Test');
    $machine_name = $assert_session->waitForElement('xpath', '//*[@id="edit-label-machine-name-suffix"]/span[contains(text(), "field_test")]');
    $this->assertNotEmpty($machine_name);
    $page->pressButton('Save and continue');

    // Node should be selected by default.     $this->assertSession()->fieldValueEquals('settings[target_type]', 'node');

    // Check that all entity types can be referenced.     $this->assertFieldSelectOptions('settings[target_type]', array_keys(\Drupal::entityTypeManager()->getDefinitions()));

    // Second step: 'Field settings' form.     $this->submitForm([], 'Save field settings');

    // The base handler should be selected by default.
    $this->getSession()->resizeWindow(1200, 600);
    $this->drupalGet('<front>');
    // Wait for toolbar to appear.     $this->assertNotEmpty($assert_session->waitForElement('css', 'body.toolbar-horizontal'));

    // Open workspace canvas.     $page->clickLink('Switch workspace');
    $this->waitForOffCanvasToOpen('top');
    $assert_session->elementExists('css', '.workspaces-dialog');

    // Close Canvas.     $page->pressButton('Close');
    $this->waitForOffCanvasToClose();
    $assert_session->assertNoElementAfterWait('css', '.workspaces-dialog');
  }

  /** * Tests workspace switch and landing page behavior. */
  public function testWorkspaceSwitch() {
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    
'access administration pages',
      'administer media',
    ]);
    $this->drupalLogin($account);

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

    $this->drupalGet('/admin/config');
    $page->clickLink('Media Library settings');
    $page->checkField('Enable advanced UI');
    $page->pressButton('Save configuration');
    $assert_session->checkboxChecked('Enable advanced UI');
    $page->uncheckField('Enable advanced UI');
    $page->pressButton('Save configuration');
    $assert_session->checkboxNotChecked('Enable advanced UI');
  }

}

  public function testEntityForm() {
    $this->drupalGet('entity_test/manage/1/edit');
    $this->assertSession()->fieldExists('field_test_text[0][value]');

    $this->drupalGet('entity_test/structure/entity_test/form-display');
    $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'content')->isSelected());
    $this->getSession()->getPage()->pressButton('Show row weights');
    $this->assertSession()->waitForElementVisible('css', '[name="fields[field_test_text][region]"]');
    $this->getSession()->getPage()->selectFieldOption('fields[field_test_text][region]', 'hidden');
    $this->assertSession()->assertWaitOnAjaxRequest();
    $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'hidden')->isSelected());

    $this->submitForm([], 'Save');
    $this->assertSession()->pageTextContains('Your settings have been saved.');
    $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'hidden')->isSelected());

    $this->drupalGet('entity_test/manage/1/edit');
    $this->assertSession()->fieldNotExists('field_test_text[0][value]');
  }
$media_type_id = $media_type->id();
    $this->assertSame('txt doc docx pdf', FieldConfig::load("media.$media_type_id.field_media_file")->get('settings')['file_extensions']);

    $this->drupalGet("admin/structure/media/manage/$media_type_id/fields/media.$media_type_id.field_media_file");

    // File extension field exists.     $assert_session->fieldExists('Allowed file extensions');

    // Add another extension.     $page->fillField('settings[file_extensions]', 'txt, doc, docx, pdf, odt');

    $page->pressButton('Save settings');
    $this->drupalGet("admin/structure/media/manage/$media_type_id/fields/media.$media_type_id.field_media_file");

    // Verify that new extension is present.     $assert_session->fieldValueEquals('settings[file_extensions]', 'txt, doc, docx, pdf, odt');
    $this->assertSame('txt doc docx pdf odt', FieldConfig::load("media.$media_type_id.field_media_file")->get('settings')['file_extensions']);
  }

  /** * Ensure source field deletion is not possible. */
  public function testPreventSourceFieldDeletion() {
    
$page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    $this->drupalGet('admin/structure/types/manage/article/fields');

    $page->find('css', '.dropbutton-toggle button')->click();
    $page->clickLink('Delete');

    // Asserts a dialog opens with the expected text.     $this->assertEquals('Are you sure you want to delete the field Body?', $assert_session->waitForElement('css', '.ui-dialog-title')->getText());

    $page->find('css', '.ui-dialog-buttonset')->pressButton('Delete');
    $assert_session->waitForText('The field Body has been deleted from the Article content type.');
  }

}
// Test that it is possible to toggle the toolbar tray.     $content = $page->findLink('Content');
    $this->assertTrue($content->isVisible(), 'Toolbar tray is open by default.');
    $page->clickLink('Manage');
    $this->assertFalse($content->isVisible(), 'Toolbar tray is closed after clicking the "Manage" link.');
    $page->clickLink('Manage');
    $this->assertTrue($content->isVisible(), 'Toolbar tray is visible again after clicking the "Manage" button a second time.');

    // Test toggling the toolbar tray between horizontal and vertical.     $tray = $page->findById('toolbar-item-administration-tray');
    $this->assertFalse($tray->hasClass('toolbar-tray-vertical'), 'Toolbar tray is not vertically oriented by default.');
    $page->pressButton('Vertical orientation');
    $this->assertTrue($tray->hasClass('toolbar-tray-vertical'), 'After toggling the orientation the toolbar tray is now displayed vertically.');

    $page->pressButton('Horizontal orientation');
    $this->assertTrue($tray->hasClass('toolbar-tray-horizontal'), 'After toggling the orientation a second time the toolbar tray is displayed horizontally again.');
  }

  /** * Tests that the orientation toggle is not shown for empty toolbar items. */
  public function testEmptyTray() {
    // Granting access to the toolbar but not any administrative menu links will
$assert_session->statusCodeEquals(200);
    $assert_session->addressEquals('media/add/' . $media_type->id());
    $assert_session->elementNotExists('css', '#edit-revision');

    // Tests media add form.     $media_name = $this->randomMachineName();
    $page->fillField('name[0][value]', $media_name);
    $revision_log_message = $this->randomString();
    $page->fillField('revision_log_message[0][value]', $revision_log_message);
    $source_field = $this->randomString();
    $page->fillField('field_media_test[0][value]', $source_field);
    $page->pressButton('Save');
    $media_id = $this->container->get('entity_type.manager')
      ->getStorage('media')
      ->getQuery()
      ->accessCheck(FALSE)
      ->execute();
    $media_id = reset($media_id);
    /** @var \Drupal\media\MediaInterface $media */
    $media = $this->container->get('entity_type.manager')
      ->getStorage('media')
      ->loadUnchanged($media_id);
    $this->assertSame($media->getRevisionLogMessage()$revision_log_message);
    
case 'system_branding_block':
        // Fill out form, save the form.         $page->fillField('settings[site_information][site_name]', $new_page_text);
        break;

      case 'settings_tray_test_class':
        $web_assert->elementExists('css', '[data-drupal-selector="edit-settings-some-setting"]');
        break;
    }

    if (isset($new_page_text)) {
      $page->pressButton($button_text);
      // Make sure the changes are present.       $new_page_text_locator = "$block_selector $label_selector:contains($new_page_text)";
      $this->assertElementVisibleAfterWait('css', $new_page_text_locator);
      // The page is loaded with the new change but make sure page is       // completely loaded.       $this->assertPageLoadComplete();
    }

    $this->openBlockForm($block_selector);

    $this->disableEditMode();
    
'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');
    $assert_session->pageTextContains('Publish media was applied to 2 items');
    
$this->assertNotNull($assert_session->waitForElementVisible('css', '[data-drupal-selector="edit-editor-settings-plugins-ckeditor5-sourceediting-allowed-tags"]'));

    $javascript = <<<JS const allowedTags = document.querySelector('[data-drupal-selector="edit-editor-settings-plugins-ckeditor5-sourceediting-allowed-tags"]'); allowedTags.value = '<div data-foo>'; allowedTags.dispatchEvent(new Event('input')); JS;
    $this->getSession()->executeScript($javascript);

    // Immediately save the configuration. Intentionally do nothing that would     // trigger an AJAX rebuild.     $page->pressButton('Save configuration');

    // Verify that the configuration was saved.     $this->drupalGet('admin/config/content/formats/manage/ckeditor5');
    $page->clickLink('Source editing');
    $this->assertNotNull($ghs_textarea = $assert_session->waitForElementVisible('css', '[data-drupal-selector="edit-editor-settings-plugins-ckeditor5-sourceediting-allowed-tags"]'));

    $ghs_string = '<div data-foo>';
    $this->assertSame($ghs_string$ghs_textarea->getValue());
    $allowed_html_field = $assert_session->fieldExists('filters[filter_html][settings][allowed_html]');
    $this->assertStringContainsString($ghs_string$allowed_html_field->getValue(), "$ghs_string not found in the allowed tags value of: {$allowed_html_field->getValue()}");
  }

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

    $this->drupalGet('dialog_renderer-collapsed-opener');

    // Open a modal using a link inside a dropbutton.     $page->find('css', '.dropbutton-toggle button')->click();
    $modal_link = $assert_session->waitForElementVisible('css', '.secondary-action a');
    $modal_link->click();
    $assert_session->waitForElementVisible('css', '.ui-dialog');
    $assert_session->assertVisibleInViewport('css', '.ui-dialog .ui-dialog-content');
    $page->pressButton('Close');

    // When the dialog "closes" it is still present, so wait on it switching to     // `display: none;`.     $assert_session->waitForElement('css', '.ui-dialog[style*="display: none;"]');

    // Confirm that when the modal closes, focus is moved to the first visible     // and focusable item in the contextual link container, because the original     // opener is not available.     $this->assertJsCondition('document.activeElement === document.querySelector(".dropbutton-action a")');
  }

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