publicfunctiontestRouteAccess(){ $client = $this->getHttpClient(); $csrf_token_path = 'session/token'; // Test using the current path.
$route_name = 'csrf_test.protected'; $user = $this->drupalCreateUser(); $this->drupalLogin($user);
// Test that access is allowed for anonymous user with no token in header.
$result = $client->post($url, $post_options); $this->assertEquals(200, $result->getStatusCode());
// testing Attribute object merging with the twig link() function.
'#attributes' => newAttribute(['class' => ['llama', 'kitten', 'panda']]), ]; }
/**
* Renders a URL to a string.
*/ publicfunctionurlToStringRender(){ return[ '#theme' => 'twig_theme_test_url_to_string', '#test_url' => Url::fromRoute('user.register'), ]; }
/**
* Renders for testing file_url functions in a Twig template.
*/ publicfunctionfileUrlRender(){ return[ '#theme' => 'twig_theme_test_file_url', ]; }
// Verify certain routes' responses are cacheable by Dynamic Page Cache, to
// ensure these responses are very fast for authenticated users.
$this->drupalLogin($this->adminUser); $url = Url::fromRoute('contact.site_page'); $this->drupalGet($url); // Verify that site-wide contact page cannot be cached by Dynamic Page
// Cache.
$this->assertSession()->responseHeaderEquals(DynamicPageCacheSubscriber::HEADER, 'UNCACHEABLE');
$url = Url::fromRoute('<front>'); $this->drupalGet($url); $this->drupalGet($url); // Verify that frontpage is cached by Dynamic Page Cache.
$this->assertSession()->responseHeaderEquals(DynamicPageCacheSubscriber::HEADER, 'HIT');
// Add a translation and check that the untranslatable field widget is
// displayed on the translation and edit forms along with translatability
// clues.
$add_url = Url::fromRoute("entity.{$this->entityTypeId}.content_translation_add", [ $entity->getEntityTypeId() => $entity->id(), 'source' => 'en', 'target' => 'it', ]); $this->drupalGet($add_url); $this->assertSession()->elementExists('xpath', $field_xpath); $this->assertSession()->elementExists('xpath', $clue_xpath); $this->assertSession()->pageTextContains('Untranslatable-but-visible test field'); $this->submitForm([], 'Save');
// Check that the widget is displayed along with its clue in the edit form
$form['update_notification_threshold'] = [ '#type' => 'radios', '#title' => $this->t('Email notification threshold'), '#default_value' => $config->get('notification.threshold'), '#options' => [ 'all' => $this->t('All newer versions'), 'security' => $this->t('Only security updates'), ], '#description' => $this->t( 'You can choose to send email only if a security update is available, or to be notified about all newer versions. If there are updates available of Drupal core or any of your installed modules and themes, your site will always print a message on the <a href=":status_report">status report</a> page. If there is a security update, an error message will be printed on administration pages for users with <a href=":update_permissions">permission to view update notifications</a>.', [ ':status_report' => Url::fromRoute('system.status')->toString(), ':update_permissions' => Url::fromRoute('user.admin_permissions', [], ['fragment' => 'module-update'])->toString(), ] ), ];
// After saving, we should be at the canonical URL and viewing the first
// revision.
$this->assertSession()->addressEquals(Url::fromRoute('entity.node.canonical', ['node' => $node->id()])); $this->assertSession()->pageTextContains('First version of the content.');
// Create a new draft; after saving, we should still be on the canonical
// URL, but viewing the second revision.
$this->drupalGet($edit_path); $this->submitForm([ 'body[0][value]' => 'Second version of the content.', 'moderation_state[0][state]' => 'draft', ], 'Save'); $this->assertSession()->addressEquals(Url::fromRoute('entity.node.canonical', ['node' => $node->id()])); $this->assertSession()->pageTextContains('Second version of the content.');
$this->drupalGet('form-test/confirm-form-array-path'); $this->clickLink('ConfirmFormArrayPathTestForm::getCancelText().'); // Verify that the form's complex cancel link was followed.
$this->assertSession()->addressEquals('form-test/confirm-form?destination=admin/config'); }
/**
* Tests that the confirm form does not use external destinations.
*/ publicfunctiontestConfirmFormWithExternalDestination(){ $this->drupalGet('form-test/confirm-form'); $this->assertSession()->linkByHrefExists(Url::fromRoute('form_test.route8')->toString()); $this->drupalGet('form-test/confirm-form', ['query' => ['destination' => 'node']]); $this->assertSession()->linkByHrefExists(Url::fromUri('internal:/node')->toString()); $this->drupalGet('form-test/confirm-form', ['query' => ['destination' => 'http://example.com']]); $this->assertSession()->linkByHrefExists(Url::fromRoute('form_test.route8')->toString()); $this->drupalGet('form-test/confirm-form', ['query' => ['destination' => '<front>']]); $this->assertSession()->linkByHrefExists(Url::fromRoute('<front>')->toString()); // Other invalid destinations, should fall back to the form default.
$this->drupalGet('form-test/confirm-form', ['query' => ['destination' => '/http://example.com']]); $this->assertSession()->linkByHrefExists(Url::fromRoute('form_test.route8')->toString()); }
// You can't create an exception in PHP without throwing it. Store the
// current error_log, and disable it temporarily.
$this->errorLog = ini_set('error_log', file_exists('/dev/null') ? '/dev/null' : 'nul'); }