Skip to content
Snippets Groups Projects
Verified Commit ebe942c7 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3440169 by pooja_sharma, marcoliver, smustgrave, DYdave, alexpott: When...

Issue #3440169 by pooja_sharma, marcoliver, smustgrave, DYdave, alexpott: When using drupalGet(), provide an associative array for $headers
parent 9cd7babd
No related branches found
No related tags found
24 merge requests!11131[10.4.x-only-DO-NOT-MERGE]: Issue ##2842525 Ajax attached to Views exposed filter form does not trigger callbacks,!9470[10.3.x-only-DO-NOT-MERGE]: #3331771 Fix file_get_contents(): Passing null to parameter,!8736Update the Documention As per the Function uses.,!8528Issue #3456871 by Tim Bozeman: Support NULL services,!8513Issue #3453786: DefaultSelection should document why values for target_bundles NULL and [] behave as they do,!8126Added escape fucntionality on admintoolbar close icon,!3878Removed unused condition head title for views,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2062Issue #3246454: Add weekly granularity to views date sort,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493
Pipeline #213736 canceled
Showing
with 14 additions and 16 deletions
...@@ -102,7 +102,7 @@ public function testAcceptLanguageEmptyDefault(): void { ...@@ -102,7 +102,7 @@ public function testAcceptLanguageEmptyDefault(): void {
$this->assertSession()->responseHeaderDoesNotExist('X-Drupal-Cache'); $this->assertSession()->responseHeaderDoesNotExist('X-Drupal-Cache');
// Check with browser without language settings - should return fallback language. // Check with browser without language settings - should return fallback language.
$this->drupalGet('/system-test/echo/language test', [], ['Accept-Language' => NULL]); $this->drupalGet('/system-test/echo/language test', [], ['Accept-Language' => '']);
$this->assertSession()->responseHeaderEquals('Content-Language', 'en'); $this->assertSession()->responseHeaderEquals('Content-Language', 'en');
$this->assertSession()->responseHeaderDoesNotExist('X-Drupal-Cache'); $this->assertSession()->responseHeaderDoesNotExist('X-Drupal-Cache');
......
...@@ -1059,13 +1059,13 @@ public function enableMenuLink(MenuLinkContent $item) { ...@@ -1059,13 +1059,13 @@ public function enableMenuLink(MenuLinkContent $item) {
public function testMenuParentsJsAccess(): void { public function testMenuParentsJsAccess(): void {
$this->drupalLogin($this->drupalCreateUser(['administer menu'])); $this->drupalLogin($this->drupalCreateUser(['administer menu']));
// Just check access to the callback overall, the POST data is irrelevant. // Just check access to the callback overall, the POST data is irrelevant.
$this->drupalGet('admin/structure/menu/parents', ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']], ['X-Requested-With: XMLHttpRequest']); $this->drupalGet('admin/structure/menu/parents', ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']], ['X-Requested-With' => 'XMLHttpRequest']);
$this->assertSession()->statusCodeEquals(200); $this->assertSession()->statusCodeEquals(200);
// Log in as authenticated user. // Log in as authenticated user.
$this->drupalLogin($this->drupalCreateUser()); $this->drupalLogin($this->drupalCreateUser());
// Check that a simple user is not able to access the menu. // Check that a simple user is not able to access the menu.
$this->drupalGet('admin/structure/menu/parents', ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']], ['X-Requested-With: XMLHttpRequest']); $this->drupalGet('admin/structure/menu/parents', ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']], ['X-Requested-With' => 'XMLHttpRequest']);
$this->assertSession()->statusCodeEquals(403); $this->assertSession()->statusCodeEquals(403);
} }
......
...@@ -194,7 +194,7 @@ public function testConditionalRequests(): void { ...@@ -194,7 +194,7 @@ public function testConditionalRequests(): void {
$this->assertSession()->statusCodeEquals(304); $this->assertSession()->statusCodeEquals(304);
// Ensure a conditional request without If-None-Match returns 200 OK. // Ensure a conditional request without If-None-Match returns 200 OK.
$this->drupalGet('', [], ['If-Modified-Since' => $last_modified, 'If-None-Match' => NULL]); $this->drupalGet('', [], ['If-Modified-Since' => $last_modified, 'If-None-Match' => '']);
// Verify the page is not printed twice when the cache is warm. // Verify the page is not printed twice when the cache is warm.
$this->assertSession()->responseNotMatches('#<html.*<html#'); $this->assertSession()->responseNotMatches('#<html.*<html#');
$this->assertSession()->statusCodeEquals(200); $this->assertSession()->statusCodeEquals(200);
......
...@@ -338,7 +338,7 @@ public function testResponseFormatConfiguration(): void { ...@@ -338,7 +338,7 @@ public function testResponseFormatConfiguration(): void {
$this->submitForm([], 'Save'); $this->submitForm([], 'Save');
// Should return a 406. Emulates a sample Firefox header. // Should return a 406. Emulates a sample Firefox header.
$this->drupalGet('test/serialize/field', [], ['Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8']); $this->drupalGet('test/serialize/field', [], ['Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8']);
$this->assertSession()->responseHeaderEquals('content-type', 'text/html; charset=UTF-8'); $this->assertSession()->responseHeaderEquals('content-type', 'text/html; charset=UTF-8');
$this->assertSession()->statusCodeEquals(406); $this->assertSession()->statusCodeEquals(406);
......
...@@ -149,7 +149,7 @@ protected function assertCommand(array $haystack, array $needle): void { ...@@ -149,7 +149,7 @@ protected function assertCommand(array $haystack, array $needle): void {
* Decoded JSON. * Decoded JSON.
*/ */
protected function drupalGetAjax($path, array $options = [], array $headers = []) { protected function drupalGetAjax($path, array $options = [], array $headers = []) {
$headers[] = 'X-Requested-With: XMLHttpRequest'; $headers = ['X-Requested-With' => 'XMLHttpRequest'];
if (!isset($options['query'][MainContentViewSubscriber::WRAPPER_FORMAT])) { if (!isset($options['query'][MainContentViewSubscriber::WRAPPER_FORMAT])) {
$options['query'][MainContentViewSubscriber::WRAPPER_FORMAT] = 'drupal_ajax'; $options['query'][MainContentViewSubscriber::WRAPPER_FORMAT] = 'drupal_ajax';
} }
......
...@@ -45,7 +45,7 @@ public function testBogusAcceptHeader(): void { ...@@ -45,7 +45,7 @@ public function testBogusAcceptHeader(): void {
'Android #2 (2012)' => 'text/xml,text/html,application/xhtml+xml,image/png,text/plain,*/*;q=0.8', 'Android #2 (2012)' => 'text/xml,text/html,application/xhtml+xml,image/png,text/plain,*/*;q=0.8',
]; ];
foreach ($tests as $case => $header) { foreach ($tests as $case => $header) {
$this->drupalGet('', [], ['Accept: ' . $header]); $this->drupalGet('', [], ['Accept' => $header]);
$this->assertSession()->pageTextNotContains('Unsupported Media Type'); $this->assertSession()->pageTextNotContains('Unsupported Media Type');
$this->assertSession()->pageTextContains('Log in'); $this->assertSession()->pageTextContains('Log in');
} }
......
...@@ -191,7 +191,7 @@ public function testImmutableFormLegacyProtection(): void { ...@@ -191,7 +191,7 @@ public function testImmutableFormLegacyProtection(): void {
$build_id = $this->assertSession()->hiddenFieldExists('form_build_id')->getValue(); $build_id = $this->assertSession()->hiddenFieldExists('form_build_id')->getValue();
// Try to poison the form cache. // Try to poison the form cache.
$response = $this->drupalGet('form-test/form-storage-legacy/' . $build_id, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']], ['X-Requested-With: XMLHttpRequest']); $response = $this->drupalGet('form-test/form-storage-legacy/' . $build_id, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']], ['X-Requested-With' => 'XMLHttpRequest']);
$original = json_decode($response, TRUE); $original = json_decode($response, TRUE);
$this->assertEquals($original['form']['#build_id_old'], $build_id, 'Original build_id was recorded'); $this->assertEquals($original['form']['#build_id_old'], $build_id, 'Original build_id was recorded');
...@@ -208,7 +208,7 @@ public function testImmutableFormLegacyProtection(): void { ...@@ -208,7 +208,7 @@ public function testImmutableFormLegacyProtection(): void {
$this->assertTrue($status, 'A watchdog message was logged by \Drupal::formBuilder()->setCache'); $this->assertTrue($status, 'A watchdog message was logged by \Drupal::formBuilder()->setCache');
// Ensure that the form state was not poisoned by the preceding call. // Ensure that the form state was not poisoned by the preceding call.
$response = $this->drupalGet('form-test/form-storage-legacy/' . $build_id, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']], ['X-Requested-With: XMLHttpRequest']); $response = $this->drupalGet('form-test/form-storage-legacy/' . $build_id, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']], ['X-Requested-With' => 'XMLHttpRequest']);
$original = json_decode($response, TRUE); $original = json_decode($response, TRUE);
$this->assertEquals($original['form']['#build_id_old'], $build_id, 'Original build_id was recorded'); $this->assertEquals($original['form']['#build_id_old'], $build_id, 'Original build_id was recorded');
$this->assertNotEquals($original['form']['#build_id'], $build_id, 'New build_id was generated'); $this->assertNotEquals($original['form']['#build_id'], $build_id, 'New build_id was generated');
......
...@@ -298,7 +298,7 @@ public function testControllerResolutionAjax(): void { ...@@ -298,7 +298,7 @@ public function testControllerResolutionAjax(): void {
// This will fail with a JSON parse error if the request is not routed to // This will fail with a JSON parse error if the request is not routed to
// The correct controller. // The correct controller.
$options['query'][MainContentViewSubscriber::WRAPPER_FORMAT] = 'drupal_ajax'; $options['query'][MainContentViewSubscriber::WRAPPER_FORMAT] = 'drupal_ajax';
$headers[] = 'X-Requested-With: XMLHttpRequest'; $headers = ['X-Requested-With' => 'XMLHttpRequest'];
$this->drupalGet('/router_test/test10', $options, $headers); $this->drupalGet('/router_test/test10', $options, $headers);
$this->assertSession()->responseHeaderEquals('Content-Type', 'application/json'); $this->assertSession()->responseHeaderEquals('Content-Type', 'application/json');
......
...@@ -29,7 +29,7 @@ class StackSessionHandlerIntegrationTest extends BrowserTestBase { ...@@ -29,7 +29,7 @@ class StackSessionHandlerIntegrationTest extends BrowserTestBase {
*/ */
public function testRequest(): void { public function testRequest(): void {
$options['query'][MainContentViewSubscriber::WRAPPER_FORMAT] = 'drupal_ajax'; $options['query'][MainContentViewSubscriber::WRAPPER_FORMAT] = 'drupal_ajax';
$headers[] = 'X-Requested-With: XMLHttpRequest'; $headers = ['X-Requested-With' => 'XMLHttpRequest'];
$actual_trace = json_decode($this->drupalGet('session-test/trace-handler', $options, $headers)); $actual_trace = json_decode($this->drupalGet('session-test/trace-handler', $options, $headers));
$sessionId = $this->getSessionCookies()->getCookieByName($this->getSessionName())->getValue(); $sessionId = $this->getSessionCookies()->getCookieByName($this->getSessionName())->getValue();
$expect_trace = [ $expect_trace = [
......
...@@ -385,7 +385,7 @@ public function testSubtreesJsonRequest(): void { ...@@ -385,7 +385,7 @@ public function testSubtreesJsonRequest(): void {
// Request a new page to refresh the drupalSettings object. // Request a new page to refresh the drupalSettings object.
$subtrees_hash = $this->getSubtreesHash(); $subtrees_hash = $this->getSubtreesHash();
$this->drupalGet('toolbar/subtrees/' . $subtrees_hash, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']], ['X-Requested-With: XMLHttpRequest']); $this->drupalGet('toolbar/subtrees/' . $subtrees_hash, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']], ['X-Requested-With' => 'XMLHttpRequest']);
$ajax_result = json_decode($this->getSession()->getPage()->getContent(), TRUE); $ajax_result = json_decode($this->getSession()->getPage()->getContent(), TRUE);
$this->assertEquals('setToolbarSubtrees', $ajax_result[0]['command'], 'Subtrees response uses the correct command.'); $this->assertEquals('setToolbarSubtrees', $ajax_result[0]['command'], 'Subtrees response uses the correct command.');
$this->assertEquals(['system-admin_content', 'system-admin_structure', 'system-themes_page', 'system-modules_list', 'system-admin_config', 'entity-user-collection', 'front'], array_keys($ajax_result[0]['subtrees']), 'Correct subtrees returned.'); $this->assertEquals(['system-admin_content', 'system-admin_structure', 'system-themes_page', 'system-modules_list', 'system-admin_config', 'entity-user-collection', 'front'], array_keys($ajax_result[0]['subtrees']), 'Correct subtrees returned.');
......
...@@ -245,13 +245,11 @@ protected function drupalGet($path, array $options = [], array $headers = []) { ...@@ -245,13 +245,11 @@ protected function drupalGet($path, array $options = [], array $headers = []) {
$this->prepareRequest(); $this->prepareRequest();
foreach ($headers as $header_name => $header_value) { foreach ($headers as $header_name => $header_value) {
if (is_int($header_name)) { if (is_int($header_name)) {
// @todo Trigger deprecation in @trigger_error('Passing an integer as header name to ' . __METHOD__ . '() is deprecated in drupal:11.1.0 and will be removed from drupal:12.0.0. Update the calling code to pass the header name as a key. See https://www.drupal.org/node/3456178', E_USER_DEPRECATED);
// https://www.drupal.org/project/drupal/issues/3421105.
[$header_name, $header_value] = explode(':', $header_value); [$header_name, $header_value] = explode(':', $header_value);
} }
if (is_null($header_value)) { if (is_null($header_value)) {
// @todo Trigger deprecation in @trigger_error('Using null as a header value to ' . __METHOD__ . '() is deprecated in drupal:11.1.0 and will be removed from drupal:12.0.0. Use an empty string instead. See https://www.drupal.org/node/3456233', E_USER_DEPRECATED);
// https://www.drupal.org/project/drupal/issues/3421105.
$header_value = ''; $header_value = '';
} }
$session->setRequestHeader($header_name, $header_value); $session->setRequestHeader($header_name, $header_value);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment