$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);
// 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());
// 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());
// 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();
$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');
// 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');
$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.';
// Disable the incompatible filter.
$page->uncheckField($incompatible_filter_name);
// Confirm there are no longer any warnings.
publicfunctiontestValidationMessages(){ $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');
/**
* 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.
*/ protectedfunctionassertPageLoadComplete(){ $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.
*/
// 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();
/**
* Tests that AJAX loaded libraries are not retained between requests.
*
* @see https://www.drupal.org/node/2647916
*/ publicfunctiontestDrupalSettingsCachingRegression(){
/**
* 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.
*/