assertWaitOnAjaxRequest example


  public function testAjaxCallMaintenanceMode(): void {
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    \Drupal::state()->set('system.maintenance_mode', TRUE);

    $this->drupalGet('ajax-test/insert-inline-wrapper');
    $assert_session->pageTextContains('Target inline');
    $page->clickLink('Link html pre-wrapped-div');
    $this->assertSession()->assertWaitOnAjaxRequest();
    $this->assertSession()->pageTextContainsOnce('Operating in maintenance mode');
  }

}
Editor::load('test_format'),
        FilterFormat::load('test_format')
      ))
    ));

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

    $this->drupalGet('/ckeditor5_test/dialog');
    $page->clickLink('Add Node');
    $assert_session->waitForElementVisible('css', '[role="dialog"]');
    $assert_session->assertWaitOnAjaxRequest();

    $content_area = $assert_session->waitForElementVisible('css', '.ck-editor__editable');
    // Focus the editable area first.     $content_area->click();
    // Then press the button to add a link.     $this->pressEditorButton('Link');

    $link_url = '/ckeditor5_test/dialog';
    $input = $assert_session->waitForElementVisible('css', '.ck-balloon-panel input.ck-input-text');
    // Make sure the input field can have focus and we can type into it.     $input->setValue($link_url);
    
$this->assertEmpty($result);
    $test_id->click();
    $result = $assert_session->waitForId('js_webassert_test_field_id');
    $this->assertNotEmpty($result);
    $this->assertInstanceOf(NodeElement::class$result);

    // Test waitOnAjaxRequest. Verify the element is available after the wait     // and the behaviors have run on completing by checking the value.     $result = $page->findField('test_assert_wait_on_ajax_input');
    $this->assertEmpty($result);
    $test_wait_on_ajax->click();
    $assert_session->assertWaitOnAjaxRequest();
    $result = $page->findField('test_assert_wait_on_ajax_input');
    $this->assertNotEmpty($result);
    $this->assertInstanceOf(NodeElement::class$result);
    $this->assertEquals('js_webassert_test', $result->getValue());

    $result = $page->findButton('Added WaitForElementVisible');
    $this->assertEmpty($result);
    $test_wait_on_element_visible->click();
    $result = $assert_session->waitForElementVisible('named', ['button', 'Added WaitForElementVisible']);
    $this->assertNotEmpty($result);
    $this->assertInstanceOf(NodeElement::class$result);
    
->save();

    // Log in a user who can create 'page' nodes.     $this->webUser = $this->drupalCreateUser(['create page content']);
    $this->drupalLogin($this->webUser);

    // Get the form for adding a 'page' node. Submit an "add another item" Ajax     // submission and verify it worked by ensuring the updated page has two text     // field items in the field for which we just added an item.     $this->drupalGet('node/add/page');
    $page->find('css', '[value="Add another item"]')->click();
    $this->assertSession()->assertWaitOnAjaxRequest();
    $this->assertSession()->elementsCount('xpath', '//div[contains(@class, "field--name-field-ajax-test")]//input[@type="text"]', 2);

    // Submit the form with the non-Ajax "Save" button, leaving the file field     // blank to trigger a validation error, and ensure that a validation error     // occurred, because this test is for testing what happens when a form is     // re-rendered without being re-built, which is what happens when there's     // a server side validation error.     $edit = [
      'title[0][value]' => $this->randomString(),
    ];
    $this->submitForm($edit, 'Save');
    
// Ensure that the Content we're testing for is in the right order, default     // sorting is by changed timestamp so the last created node should be first.     /** @var \Behat\Mink\Element\NodeElement[] $rows */
    $rows = $page->findAll('css', 'tbody tr');
    $this->assertCount(2, $rows);
    $this->assertStringContainsString('Page B', $rows[0]->getHtml());
    $this->assertStringContainsString('Page A', $rows[1]->getHtml());

    // Now sort by title and check if the order changed.     $page->clickLink('Title');
    $session_assert->assertWaitOnAjaxRequest();
    $rows = $page->findAll('css', 'tbody tr');
    $this->assertCount(2, $rows);
    $this->assertStringContainsString('Page A', $rows[0]->getHtml());
    $this->assertStringContainsString('Page B', $rows[1]->getHtml());
  }

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

    $this->addNewTextFormat($page$assert_session);

    $this->drupalGet('/ckeditor5_test/off_canvas');

    // The "Add Node" link triggers an off-canvas dialog with an add node form     // that includes CKEditor.     $page->clickLink('Add Node');
    $assert_session->waitForElementVisible('css', '#drupal-off-canvas-wrapper');
    $assert_session->assertWaitOnAjaxRequest();

    $styles = $assert_session->elementExists('css', 'style#ckeditor5-off-canvas-reset');
    $this->stringContains('#drupal-off-canvas-wrapper [data-drupal-ck-style-fence]', $styles->getText());

    $assert_session->elementExists('css', '.ck');

    $ckeditor_toolbar_bg_color = $this->getSession()->evaluateScript('window.getComputedStyle(document.querySelector(\'.ck.ck-toolbar\')).backgroundColor');
    $this->assertEquals('rgb(255, 255, 255)', $ckeditor_toolbar_bg_color, 'Toolbar background-color should be unaffected by off-canvas');
    // Editable area should be visible.     $assert_session->elementExists('css', '.ck .ck-content');
    $ckeditor_editable_bg_color = $this->getSession()->evaluateScript('window.getComputedStyle(document.querySelector(\'.ck.ck-content\')).backgroundColor');
    
$this->drupalGet('admin/structure/views/view/content_recent');
    $assert_session = $this->assertSession();
    $session = $this->getSession();
    $page = $session->getPage();

    $this->openFilterDialog();

    // Add a new filter group.     $create_new_filter_group = $page->findById('views-add-group-link');
    $this->assertTrue($create_new_filter_group->isVisible(), 'Add group link found.');
    $create_new_filter_group->click();
    $assert_session->assertWaitOnAjaxRequest();

    // Assert the existence of the new filter group by checking the remove group     // link.     $remove_link = $page->findLink('Remove group');
    $this->assertTrue($remove_link->isVisible(), 'New group found.');

    // Remove the group again and assert the group is not present anymore.     $remove_link->click();
    $assert_session->assertWaitOnAjaxRequest();
    $remove_link = $page->findLink('Remove group');
    $this->assertEmpty($remove_link, 'Remove button not available');

    

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

    $incompatible_filter_name = 'filters[filter_incompatible][status]';
    $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.';

    $this->createNewTextFormat($page$assert_session, 'unicorn');
    $page->selectFieldOption('editor[editor]', 'unicorn');
    $assert_session->assertWaitOnAjaxRequest();
    $page->checkField('filters[filter_html][status]');
    $page->checkField($incompatible_filter_name);
    $assert_session->assertWaitOnAjaxRequest();
    $page->selectFieldOption('editor[editor]', 'ckeditor5');
    $assert_session->assertWaitOnAjaxRequest();
    $assert_session->pageTextContains($filter_warning);

    // Disable the incompatible filter.     $page->uncheckField($incompatible_filter_name);

    // Confirm there are no longer any warnings.

  public function testValidationMessages() {
    $page = $this->getSession()->getPage();
    $web_assert = $this->assertSession();
    foreach ($this->getTestThemes() as $theme) {
      $this->enableTheme($theme);
      $block = $this->placeBlock('settings_tray_test_validation');
      $this->drupalGet('user');
      $this->enableEditMode();
      $this->openBlockForm($this->getBlockSelector($block));
      $page->pressButton('Save Block with validation error');
      $web_assert->assertWaitOnAjaxRequest();
      // The settings_tray_test_validation test plugin form always has a       // validation error.       $web_assert->elementContains('css', '#drupal-off-canvas', 'Sorry system error. Please save again');
      $this->disableEditMode();
      $block->delete();
    }
  }

}
// Log in as user you can only configure layouts and access content.     $this->drupalLogin($this->drupalCreateUser([
      'access contextual links',
      'configure any layout',
      'access content',
      'create and edit custom blocks',
    ]));
    $this->drupalGet('node/1/layout');
    // @todo Occasionally SQLite has database locks here. Waiting seems to     // resolve it. https://www.drupal.org/project/drupal/issues/3055983     $assert_session->assertWaitOnAjaxRequest();
    $file = $this->createPrivateFile('drupal.txt');

    $file_real_path = $this->fileSystem->realpath($file->getFileUri());
    $this->assertFileExists($file_real_path);
    $this->addInlineFileBlockToLayout('The file', $file);
    $this->assertSaveLayout();

    $this->drupalGet('node/1');
    $private_href1 = $this->getFileHrefAccessibleOnNode($file);

    // Remove the inline block with the private file.
return $return;
  }

  /** * Assert the page is completely loaded. * * Ajax requests may happen after page loads. Also for users who have access * to contextual links the contextual link placeholders will be filled after * the page is received. */
  protected function assertPageLoadComplete() {
    $this->assertSession()->assertWaitOnAjaxRequest();
    if ($this->loggedInUser && $this->loggedInUser->hasPermission('access contextual links')) {
      $this->assertAllContextualLinksLoaded();
    }
  }

  /** * Assert all contextual link areas have be loaded. * * Contextual link placeholders will be filled after * the page is received. * * @todo Move this function to https://www.drupal.org/node/2821724. */
$this->assertGreaterThan($last_fid_prior$last_fid, 'New file got uploaded.');
          $this->submitForm([], 'Save');

          // Remove, then Submit.           $remove_button_title = $multiple ? 'Remove selected' : 'Remove';
          $this->drupalGet($path . '/' . $last_fid);
          if ($multiple) {
            $selected_checkbox = ($tree ? 'nested[file]' : 'file') . '[file_' . $last_fid . '][selected]';
            $this->getSession()->getPage()->checkField($selected_checkbox);
          }
          $this->getSession()->getPage()->pressButton($remove_button_title);
          $this->assertSession()->assertWaitOnAjaxRequest();
          $this->submitForm([], 'Save');
          $this->assertSession()->pageTextContains('The file ids are .');

          // Upload, then Remove, then Submit.           $this->drupalGet($path);
          $this->getSession()->getPage()->attachFileToField($file_field_name$this->container->get('file_system')->realpath($filename));
          $uploaded_file = $this->assertSession()->waitForElement('css', '.file--mime-text-plain');
          $this->assertNotEmpty($uploaded_file);
          if ($multiple) {
            $selected_checkbox = ($tree ? 'nested[file]' : 'file') . '[file_' . $this->getLastFileId() . '][selected]';
            $this->getSession()->getPage()->checkField($selected_checkbox);
          }
// First visit the site directly via the URL. This should render it in the     // admin theme.     $this->drupalGet('admin/ajax-test/theme');
    $assert = $this->assertSession();
    $assert->pageTextContains('Current theme: claro');

    // Now click the modal, which should also use the admin theme.     $this->drupalGet('ajax-test/dialog');
    $assert->pageTextNotContains('Current theme: stable9');
    $this->clickLink('Link 8 (ajax)');
    $assert->assertWaitOnAjaxRequest();

    $assert->pageTextContains('Current theme: stable9');
    $assert->pageTextNotContains('Current theme: claro');
  }

  /** * Tests that AJAX loaded libraries are not retained between requests. * * @see https://www.drupal.org/node/2647916 */
  public function testDrupalSettingsCachingRegression() {
    

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

  /** * Copied from parent. * * This is Drupal\Tests\field_ui\FunctionalJavascript\EntityDisplayTest::testEntityView() * with a line changed to reflect row weight toggle being a link instead * of a button. */

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

    $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_revision');
    $assert_session->assertWaitOnAjaxRequest();
    $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');

    // Check for the default filters.
Home | Imprint | This part of the site doesn't use cookies.