getCurrentUrl example

$this->clickLink('Add link');
    $link_title = $this->randomString();
    $this->submitForm(['link[0][uri]' => '/', 'title[0][value]' => $link_title], 'Save');
    $this->assertSession()->linkExists($link_title);
    $this->assertSession()->addressEquals('admin/structure/menu/manage/tools');

    // Test adding a menu link direct from the menus listing page.     $this->drupalGet('admin/structure/menu');
    // Click the "Add link" operation in the Tools row.     $links = $this->xpath('//*/td[contains(text(),:menu_label)]/following::a[normalize-space()=:link_label]', [':menu_label' => 'Tools', ':link_label' => 'Add link']);
    $links[0]->click();
    $this->assertMatchesRegularExpression('#admin/structure/menu/manage/tools/add\?destination=(/[^/]*)*/admin/structure/menu/manage/tools$#', $this->getSession()->getCurrentUrl());
    $link_title = $this->randomString();
    $this->submitForm(['link[0][uri]' => '/', 'title[0][value]' => $link_title], 'Save');
    $this->assertSession()->linkExists($link_title);
    $this->assertSession()->addressEquals('admin/structure/menu/manage/tools');

    $menu_name = $this->menu->id();

    // Access the menu via the overview form to ensure it does not add a     // destination that breaks the user interface.     $this->drupalGet('admin/structure/menu');

    
$this->getSession()->getPage()->fillField('edit-title-0-value--2', 'form2');
    $this->submitForm([], 'Save', 'node-page-form--2');
    $this->assertSession()->pageTextContains('Page form2 has been created.');
  }

  /** * Tests clickLink() functionality. */
  public function testClickLink() {
    $this->drupalGet('test-page');
    $this->clickLink('Visually identical test links');
    $this->assertStringContainsString('user/login', $this->getSession()->getCurrentUrl());
    $this->drupalGet('test-page');
    $this->clickLink('Visually identical test links', 0);
    $this->assertStringContainsString('user/login', $this->getSession()->getCurrentUrl());
    $this->drupalGet('test-page');
    $this->clickLink('Visually identical test links', 1);
    $this->assertStringContainsString('user/register', $this->getSession()->getCurrentUrl());
  }

  public function testError() {
    $this->expectException('\Exception');
    $this->expectExceptionMessage('User notice: foo');
    
throw new ExpectationException(sprintf('The page contains a duplicate HTML ID "%s".', $id)$this->session->getDriver());
      }
      $seen_ids[$id] = TRUE;
    }
  }

  /** * {@inheritdoc} */
  public function addressEquals($page) {
    $expected = $this->cleanUrl($page, TRUE);
    $actual = $this->cleanUrl($this->session->getCurrentUrl()str_contains($expected, '?'));

    $this->assert($actual === $expectedsprintf('Current page is "%s", but "%s" expected.', $actual$expected));
  }

  /** * {@inheritdoc} */
  public function addressNotEquals($page) {
    $expected = $this->cleanUrl($page, TRUE);
    $actual = $this->cleanUrl($this->session->getCurrentUrl()str_contains($expected, '?'));

    

  protected function assertCookieExists(string $cookie_name, string $expected, string $cookie_label): void {
    $this->assertEquals($expected, !empty($this->getSession()->getCookie($cookie_name))$expected ? "$cookie_label cookie exists." : "$cookie_label cookie does not exist.");
  }

  /** * Calls ::performMetaRefresh() and asserts the responses. * * @internal */
  protected function assertBigPipeNoJsMetaRefreshRedirect(): void {
    $original_url = $this->getSession()->getCurrentUrl();

    // Disable automatic following of redirects by the HTTP client, so that this     // test can analyze the response headers of each redirect response.     $this->getSession()->getDriver()->getClient()->followRedirects(FALSE);
    $this->performMetaRefresh();
    $headers[0] = $this->getSession()->getResponseHeaders();
    $statuses[0] = $this->getSession()->getStatusCode();
    $this->performMetaRefresh();
    $headers[1] = $this->getSession()->getResponseHeaders();
    $statuses[1] = $this->getSession()->getStatusCode();
    $this->getSession()->getDriver()->getClient()->followRedirects(TRUE);

    
'administer nodes',
      'bypass node access',
    ]);
    $this->drupalLogin($user);
  }

  /** * Ensures that redirects work with ajax. */
  public function testRedirectWithAjax() {
    $this->drupalGet('admin/content');
    $original_url = $this->getSession()->getCurrentUrl();

    $this->assertSession()->pageTextContains('Tiny paws and playful mews, kittens bring joy in every hue');

    $this->submitForm(['title' => 'Kittens'], 'Filter');
    $this->assertSession()->assertWaitOnAjaxRequest();

    $this->assertSession()->pageTextContains('Tiny paws and playful mews, kittens bring joy in every hue');
    $this->getSession()->getPage()->find('css', '.dropbutton-toggle button')->click();
    $this->clickLink('Delete');
    $this->assertSession()->assertWaitOnAjaxRequest();

    
<?php if ($error): ?> <div class="alert alert-error"> <?= $t->t('license_agreement_error'); ?> </div> <?php endif; ?> <p> <?= $t->t('license_agreement_info'); ?> </p> <form action="<?= $menuHelper->getCurrentUrl(); ?>" method="post"> <iframe id="license--agreement" class="license--agreement" src="<?= $tosUrl; ?>"></iframe> <p> <label> <input type="checkbox" name="tos"/> <?= $t->t('license_agreement_checkbox'); ?> </label> </p> <div class="actions clearfix"> <a href="<?= $menuHelper->getPreviousUrl(); ?>" class="btn btn-default btn-arrow-left"><?= $t->t('back'); ?></a> <button type="submit" class="btn btn-primary btn-arrow-right is--right">
<?php $app->render('_header.php'); ?> <h2><?= $t->t('configuration_header'); ?></h2> <?php if ($error): ?> <div class="alert alert-error"> <?= $error; ?> </div> <?php endif; ?> <form action="<?= $menuHelper->getCurrentUrl(); ?>" method="post"> <p> <?= $t->t('configuration_sconfig_text'); ?> </p> <p> <label for="c_config_shopName"><?= $t->t('configuration_sconfig_name'); ?></label> <input type="text" value="<?= isset($parameters['c_config_shopName']) ? $parameters['c_config_shopName'] : 'Demoshop'; ?>" name="c_config_shopName" id="c_config_shopName" required="required" autofocus/> <span class="help-block">
// Replace original page output with new output from redirected page(s).     if ($new = $this->checkForMetaRefresh()) {
      $out = $new;
      // We are finished with all meta refresh redirects, so reset the counter.       $this->metaRefreshCount = 0;
    }

    // Log only for WebDriverTestBase tests because for DrupalTestBrowser we log     // with ::getResponseLogHandler.     if ($this->htmlOutputEnabled && !$this->isTestUsingGuzzleClient()) {
      $html_output = 'GET request to: ' . $url .
        '<hr />Ending URL: ' . $this->getSession()->getCurrentUrl();
      $html_output .= '<hr />' . $out;
      $html_output .= $this->getHtmlOutputHeaders();
      $this->htmlOutput($html_output);
    }

    return $out;
  }

}
$view['page[create]'] = 1;
    $view['page[title]'] = $this->randomMachineName(16);
    $view['page[path]'] = $this->randomMachineName(16);
    $view['page[items_per_page]'] = 4;
    $view['block[create]'] = 1;
    $view['block[title]'] = $this->randomMachineName(16);
    $view['block[items_per_page]'] = 3;
    $this->drupalGet('admin/structure/views/add');
    $this->submitForm($view, 'Save and edit');

    // Uncheck items per page in block settings.     $this->drupalGet($this->getSession()->getCurrentUrl() . '/edit/block_1');
    $this->clickLink('Items per page');
    $this->assertSession()->checkboxChecked('allow[items_per_page]');
    $this->getSession()->getPage()->uncheckField('allow[items_per_page]');
    $this->getSession()->getPage()->pressButton('Apply');
    $this->getSession()->getPage()->pressButton('Save');

    // Check items per page in block settings.     $this->drupalGet('admin/structure/views/nojs/display/' . $view['id'] . '/block_1/allow');
    $this->assertSession()->checkboxNotChecked('allow[items_per_page]');
    $this->getSession()->getPage()->checkField('allow[items_per_page]');
    $this->getSession()->getPage()->pressButton('Apply');
    
<tr class="notice-text "> <td colspan="4"> <p><i class="icon-info22"></i> <?= $systemCheckResult['notice']; ?></p> </td> </tr> <?php endif; ?> <?php endforeach; ?> </tbody> </table> </div> <form action="<?= $menuHelper->getCurrentUrl(); ?>" method="post"> <div class="actions clearfix"> <a href="<?= $menuHelper->getPreviousUrl(); ?>" class="btn btn-default btn-arrow-left"><?= $t->t('back'); ?></a> <button type="submit" class="btn btn-primary btn-arrow-right is--right" <?php if ($error): ?>disabled="disabled"<?php endif; ?>><?= $t->t('forward'); ?></button> </div> </form> <?php $app->render('_footer.php'); ?>
<?php if ($error): ?> <div class="alert alert-error"> <?= $error; ?> </div> <?php endif; ?> <p> <?= $t->t('database-configuration_info'); ?> </p> <form action="<?= $menuHelper->getCurrentUrl(); ?>" method="post" data-ajaxDatabaseSelection="true" data-url="<?= $app->urlFor('database'); ?>"> <p> <label for="c_database_host"><?= $t->t('database-configuration_field_host'); ?></label> <input type="text" value="<?= isset($parameters['c_database_host']) ? $parameters['c_database_host'] : 'localhost'; ?>" name="c_database_host" id="c_database_host" required="required" /> </p> <p> <label for="c_database_user"><?= $t->t('database-configuration_field_user'); ?></label> <input type="text" value="<?= isset($parameters['c_database_user']) ? $parameters['c_database_user'] : ''; ?>" name="c_database_user" id="c_database_user" required="required" /> </p> <p> <label for="c_database_password">
<?php $app->render('_header.php'); ?> <h2><?= $t->t('language-selection_header'); ?></h2> <?= $t->t('language-selection_welcome_message'); ?> <form action="<?= $menuHelper->getNextUrl(); ?>" method="get"> <input type="hidden" class="hidden-action" value="<?= $menuHelper->getCurrentUrl(); ?>" /> <p> <label for="language"><?= $t->t('language-selection_select_language'); ?></label> <?= $t->t('language-selection_info_message'); ?> </p> <select id="language" name="language" class="language-selection"> <?php foreach ($languages as $language): ?> <option value="<?= $language; ?>" <?= ($selectedLanguage == $language) ? 'selected' : ''; ?>> <?= $t->t('select_language_' . $language); ?> </option>
// 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() */

  protected function submitNodeForm($title$moderation_state$default_translation = FALSE, $langcode = 'en') {
    $is_new = str_contains($this->getSession()->getCurrentUrl(), '/node/add/');
    $edit = [
      'title[0][value]' => $title,
      'moderation_state[0][state]' => $moderation_state,
    ];
    if ($is_new) {
      $default_translation = TRUE;
      $edit['langcode[0][value]'] = $langcode;
    }
    $submit = $default_translation ? 'Save' : 'Save (this translation)';
    $this->submitForm($edit$submit);
    $message = $is_new ? "Article $title has been created." : "Article $title has been updated.";
    
$this->drupalGet('admin/config/workflow/workflows');
    $this->assertSession()->pageTextContains('There are no workflow types available. In order to create workflows you need to install a module that provides a workflow type. For example, the Content Moderation module provides a workflow type that enables workflows for content entities.');
    $this->assertSession()->linkExists('Content Moderation');
    $this->assertSession()->pageTextNotContains('Add workflow');

    $this->clickLink('Content Moderation');

    $modules_list_url_absolute = Url::fromRoute('system.modules_list', [][
      'fragment' => 'module-content-moderation',
      'absolute' => TRUE,
    ])->toString();
    $this->assertSame($this->getSession()->getCurrentUrl()$modules_list_url_absolute);
    // The current user does not have the 'administer modules' permission.     $this->assertSession()->statusCodeEquals(403);

    $this->container->get('module_installer')->install(['workflow_type_test']);
    // The render cache needs to be cleared because although the cache tags are     // correctly set the render cache does not pick it up.     \Drupal::cache('render')->deleteAll();

    $this->drupalGet('admin/config/workflow/workflows');
    $this->assertSession()->pageTextNotContains('There are no workflow types available. In order to create workflows you need to install a module that provides a workflow type. For example, the Content Moderation module provides a workflow type that enables workflows for content entities.');
    $this->assertSession()->linkExists('Add workflow');
    
Home | Imprint | This part of the site doesn't use cookies.