getPage example



  /** * Tests the use of regions for entity form displays. */
  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]');
  }
protected $defaultTheme = 'stark';

  /** * Tests if the dialog UI works properly with block layout page. */
  public function testDialogOpenAndClose() {
    $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');
    
$this->drupalLogin($admin_user);
  }

  /** * Tests filtering options in the 'Add fields' dialog. */
  public function testFilterOptionsAddFields() {
    $this->drupalGet('admin/structure/views/view/content');

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

    // Open the dialog.     $page->clickLink('views-add-field');

    // Wait for the popup to open and the search field to be available.     $options_search = $web_assert->waitForField('override[controls][options_search]');

    // Test that the both special fields are visible.     $this->assertTrue($page->findField('name[views.views_test_field_1]')->isVisible());
    $this->assertTrue($page->findField('name[views.views_test_field_2]')->isVisible());

    

    ]);
  }

  /** * Tests that we can alter a Layout Builder element while preparing. * * @see \Drupal\layout_builder_element_test\EventSubscriber\TestPrepareLayout; */
  public function testAlterPrepareLayout() {
    $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_blocks as $test_block) {
      $this->drupalPlaceBlock('system_powered_by_block', [
        'label' => $test_block['label'],
        'region' => $region,
        'weight' => $test_block['weight'],
        'id' => $test_block['id'],
      ]);
    }

    $this->drupalGet('');
    $test_content = $this->getSession()->getPage()->getContent();

    $controller = $this->container->get('entity_type.manager')->getStorage('block');
    foreach ($controller->loadMultiple() as $return_block) {
      $id = $return_block->id();
      if ($return_block_weight = $return_block->getWeight()) {
        $this->assertSame((int) $test_blocks[$id]['weight']$return_block_weight, 'Block weight is set as "' . $return_block_weight . '" for ' . $id . ' block.');
        $position[$id] = strpos($test_content, Html::getClass('block-' . $test_blocks[$id]['id']));
      }
    }
    // Verify that blocks with different weight are rendered in the correct     // order.
/** * {@inheritdoc} */
  protected static $modules = [
    'media_library',
  ];

  /** * Tests configuring CKEditor 5 for existing content. */
  public function testExistingContent() {
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    // 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('&lt;p&gt;This is test content&lt;/p&gt;');

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

    
$admin_user = $this->drupalCreateUser(['administer content types']);
    $this->drupalLogin($admin_user);
    $this->drupalCreateContentType(['type' => 'test']);
  }

  /** * Tests a vertical tab 'Workflow' summary. */
  public function testWorkflowSummary() {
    $this->drupalGet('admin/structure/types/manage/test');
    $page = $this->getSession()->getPage();
    $page->find('css', 'a[href="#edit-workflow"]')->click();
    $this->assertSession()->waitForElementVisible('css', '[name="options[status]"]');
    $page->findField('options[status]')->uncheck();
    $page->findField('options[sticky]')->check();
    $page->findField('options[promote]')->check();
    $page->findField('options[revision]')->check();
    $locator = '[href="#edit-workflow"] .vertical-tabs__menu-item-summary';
    $this->assertTrue($page->waitFor(10, function D) use ($page$locator) {
      $summary = $page->find('css', $locator)->getText();
      return str_contains($summary, 'Not published');
    }));
    
// 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));
    
    $this->refreshVariables();

    // 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() */
    $this->adminUser = $this->drupalCreateUser(['administer filters']);
  }

  /** * Tests an existing format without any editors available. */
  public function testNoEditorAvailable() {
    $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);

    // Verify the <select>.     $select = $this->assertSession()->selectExists('editor[editor]');
    $this->assertSame('disabled', $select->getAttribute('disabled'));
    $options = $select->findAll('css', 'option');
    $this->assertCount(1, $options);
    
'pass' => $new_password,
    ];
    $this->submitForm($edit, 'Log in');
    return $new_password;
  }

  /** * Tests with a browser that denies cookies. */
  public function testCookiesNotAccepted() {
    $this->drupalGet('user/login');
    $form_build_id = $this->getSession()->getPage()->findField('form_build_id');

    $account = $this->drupalCreateUser([]);
    $post = [
      'form_id' => 'user_login_form',
      'form_build_id' => $form_build_id,
      'name' => $account->getAccountName(),
      'pass' => $account->passRaw,
      'op' => 'Log in',
    ];
    $url = $this->buildUrl(Url::fromRoute('user.login'));

    
public static function assertPageEvent(
        string $expectedClass,
        PageLoadedEvent $event,
        SalesChannelContext $salesChannelContext,
        Request $request,
        Struct $page
    ): void {
        TestCase::assertInstanceOf($expectedClass$event);
        TestCase::assertSame($salesChannelContext$event->getSalesChannelContext());
        TestCase::assertSame($salesChannelContext->getContext()$event->getContext());
        TestCase::assertSame($request$event->getRequest());
        TestCase::assertSame($page$event->getPage());
    }

    /** * @param class-string<object> $expectedClass */
    public static function assertPageletEvent(
        string $expectedClass,
        PageletLoadedEvent $event,
        SalesChannelContext $salesChannelContext,
        Request $request,
        Struct $page
    ):
protected static $modules = ['ajax_test'];

  /** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * Tests AjaxFocusFirstCommand on a page. */
  public function testFocusFirst() {
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    $this->drupalGet('ajax-test/focus-first');
    $has_focus_id = $this->getSession()->evaluateScript('document.activeElement.id');
    $this->assertNotContains($has_focus_id['edit-first-input', 'edit-first-container-input']);

    // 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');
    
'administer workspaces',
      'access toolbar',
      'access administration pages',
    ]);
    $this->drupalLogin($admin_user);
  }

  /** * Tests workspace canvas can be toggled with JavaScript. */
  public function testWorkspaceCanvasToggling() {
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    // Set size for horizontal toolbar.     $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');
    

  public function testResponsiveImageFormatterUi() {
    $manage = 'admin/structure/types/manage/' . $this->type;
    $add_field = $manage . '/fields/add-field';
    $manage_display = $manage . '/display';
    $assert_session = $this->assertSession();

    // Create a field, and a node with some data for the field.     // Create the field.     $this->drupalGet($add_field);

    $page = $this->getSession()->getPage();
    $storage_type = $page->findField('edit-new-storage-type');
    $storage_type->setValue('image');

    // Set the label.     $label = $page->findField('edit-label');
    $label->setValue('Image');

    // Wait for the machine name.     $assert_session->waitForElementVisible('css', '[name="label"] + * .machine-name-value');

    // Save the current page.
Home | Imprint | This part of the site doesn't use cookies.