/**
* Tests the use of regions for entity form displays.
*/ publicfunctiontestEntityForm(){ $this->drupalGet('entity_test/manage/1/edit'); $this->assertSession()->fieldExists('field_test_text[0][value]');
/**
* Tests if the dialog UI works properly with block layout page.
*/ publicfunctiontestDialogOpenAndClose(){ $admin_user = $this->drupalCreateUser(['administer blocks']); $this->drupalLogin($admin_user); $this->drupalGet('admin/structure/block'); $session = $this->getSession(); $assert_session = $this->assertSession(); $page = $session->getPage();
// Open the dialog using the place block link.
$placeBlockLink = $page->findLink('Place block'); $this->assertTrue($placeBlockLink->isVisible(), 'Place block button exists.'); $placeBlockLink->click(); $assert_session->assertWaitOnAjaxRequest(); $dialog = $page->find('css', '.ui-dialog'); $this->assertTrue($dialog->isVisible(), 'Dialog is opened after clicking the Place block button.');
// Close the dialog again.
$closeButton = $page->find('css', '.ui-dialog-titlebar-close');
/**
* Tests that we can alter a Layout Builder element while preparing.
*
* @see \Drupal\layout_builder_element_test\EventSubscriber\TestPrepareLayout;
*/ publicfunctiontestAlterPrepareLayout(){ $assert_session = $this->assertSession(); $page = $this->getSession()->getPage();
$this->drupalLogin($this->drupalCreateUser([ 'access content', 'administer blocks', 'configure any layout', 'administer node display', 'configure all bundle_with_section_field node layout overrides', ]));
// Add a block to the defaults.
$this->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
// Place the test blocks.
foreach($test_blocksas$test_block){ $this->drupalPlaceBlock('system_powered_by_block', [ 'label' => $test_block['label'], 'region' => $region, 'weight' => $test_block['weight'], 'id' => $test_block['id'], ]); }
// Add a node with text rendered via the Plain Text format.
$this->drupalGet('node/add'); $page->fillField('title[0][value]', 'My test content'); $page->fillField('body[0][value]', '<p>This is test content</p>'); $page->pressButton('Save'); $assert_session->responseNotContains('<p>This is test content</p>'); $assert_session->responseContains('<p>This is test content</p>');
// Create a test file that exceeds the maximum POST size with 1 kilobyte.
$post_max_size = Bytes::toNumber(ini_get('post_max_size')); $invalid_file = 'public://exceeding_post_max_size.bin'; $file = fopen($invalid_file, 'wb'); fseek($file, $post_max_size + 1024); fwrite($file, 0x0); fclose($file);
// Go to the node creation form and try to upload the test file.
$this->drupalGet('node/add/article'); $page = $session->getPage(); $page->attachFileToField("files[field_file_0]", $this->fileSystem->realpath($invalid_file));
// An error message should appear informing the user that the file exceeded
// the maximum file size. The error message includes the actual file size
// limit which depends on the current environment, so we check for a part
// of the message.
$this->assertSession()->statusMessageContainsAfterWait('An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size', 'error');
// Now upload a valid file and check that the error message disappears.
$valid_file = $this->generateFile('not_exceeding_post_max_size', 8, 8); $page->attachFileToField("files[field_file_0]", $this->fileSystem->realpath($valid_file));
// Check if there are any meta refresh redirects (like Batch API pages).
if($this->checkForMetaRefresh()){ // We are finished with all meta refresh redirects, so reset the counter.
$this->metaRefreshCount = 0; }
// Log only for WebDriverTestBase tests because for tests using
// DrupalTestBrowser we log with ::getResponseLogHandler.
if($this->htmlOutputEnabled && !$this->isTestUsingGuzzleClient()){ $out = $this->getSession()->getPage()->getContent(); $html_output = 'POST request to: ' . $action . '<hr />Ending URL: ' . $this->getSession()->getCurrentUrl(); $html_output .= '<hr />' . $out; $html_output .= $this->getHtmlOutputHeaders(); $this->htmlOutput($html_output); }
}
/**
* Logs in a user using the Mink controlled browser.
*
* If a user is already logged in, then the current user is logged out before
* logging in the specified user.
*
* Please note that neither the current user nor the passed-in user object is
* populated with data of the logged in user. If you need full access to the
* user object after logging in, it must be updated manually. If you also need
* access to the plain-text password of the user (set by drupalCreateUser()),
* e.g. to log in the same user again, then it must be re-assigned manually.
* For example:
* @code
* // Create a user.
* $account = $this->drupalCreateUser(array());
* $this->drupalLogin($account);
* // Load real user object.
* $pass_raw = $account->passRaw;
* $account = User::load($account->id());
* $account->passRaw = $pass_raw;
* @endcode
*
* @param \Drupal\Core\Session\AccountInterface $account
* User object representing the user to log in.
*
* @see drupalCreateUser()
*/
/**
* Tests an existing format without any editors available.
*/ publicfunctiontestNoEditorAvailable(){ $this->drupalLogin($this->adminUser); $this->drupalGet('admin/config/content/formats/manage/filtered_html');
// Ensure the form field order is correct.
$raw_content = $this->getSession()->getPage()->getContent(); $roles_pos = strpos($raw_content, 'Roles'); $editor_pos = strpos($raw_content, 'Text editor'); $filters_pos = strpos($raw_content, 'Enabled filters'); $this->assertGreaterThan($roles_pos, $editor_pos); $this->assertLessThan($filters_pos, $editor_pos);
/**
* Tests with a browser that denies cookies.
*/ publicfunctiontestCookiesNotAccepted(){ $this->drupalGet('user/login'); $form_build_id = $this->getSession()->getPage()->findField('form_build_id');
// Confirm that focus does not change if the selector targets a
// non-focusable container containing no tabbable elements.
$page->pressButton('SelectorNothingTabbable'); $this->assertNotNull($assert_session->waitForElementVisible('css', '#edit-selector-has-nothing-tabbable[data-has-focus]')); $has_focus_id = $this->getSession()->evaluateScript('document.activeElement.id');