Skip to content

Commit

Permalink
Issue #3139439 by Bunty Badgujar, mondrake, xjm, daffie: Replace usag…
Browse files Browse the repository at this point in the history
…es of deprecated AssertLegacyTrait::assertHeader()

(cherry picked from commit 736a36cdb0ed509bbb8f42eac1179640676a35e7)
  • Loading branch information
xjm committed May 27, 2020
1 parent 32500fc commit 9ad497a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion modules/page_cache/tests/src/Functional/PageCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ public function testCacheableWithCustomCacheControl() {

$this->drupalGet('/system-test/custom-cache-control');
$this->assertResponse(200);
$this->assertHeader('Cache-Control', 'bar, private');
$this->assertSession()->responseHeaderEquals('Cache-Control', 'bar, private');
}

/**
Expand Down
36 changes: 18 additions & 18 deletions modules/rest/tests/src/Functional/Views/StyleSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,19 +239,19 @@ public function testSharedPagePath() {
// Test with no format as well as html explicitly.
$this->drupalGet('test/serialize/shared');
$this->assertResponse(200);
$this->assertHeader('content-type', 'text/html; charset=UTF-8');
$this->assertSession()->responseHeaderEquals('content-type', 'text/html; charset=UTF-8');

$this->drupalGet('test/serialize/shared', ['query' => ['_format' => 'html']]);
$this->assertResponse(200);
$this->assertHeader('content-type', 'text/html; charset=UTF-8');
$this->assertSession()->responseHeaderEquals('content-type', 'text/html; charset=UTF-8');

$this->drupalGet('test/serialize/shared', ['query' => ['_format' => 'json']]);
$this->assertResponse(200);
$this->assertHeader('content-type', 'application/json');
$this->assertSession()->responseHeaderEquals('content-type', 'application/json');

$this->drupalGet('test/serialize/shared', ['query' => ['_format' => 'xml']]);
$this->assertResponse(200);
$this->assertHeader('content-type', 'text/xml; charset=UTF-8');
$this->assertSession()->responseHeaderEquals('content-type', 'text/xml; charset=UTF-8');
}

/**
Expand Down Expand Up @@ -334,14 +334,14 @@ public function testRestRenderCaching() {
// varies by it.
$result1 = Json::decode($this->drupalGet('test/serialize/entity', ['query' => ['_format' => 'json']]));
$this->addRequestWithFormat('json');
$this->assertHeader('content-type', 'application/json');
$this->assertSession()->responseHeaderEquals('content-type', 'application/json');
$this->assertCacheContexts($cache_contexts);
$this->assertCacheTags($cache_tags);
$this->assertNotEmpty($render_cache->get($original));

$result_xml = $this->drupalGet('test/serialize/entity', ['query' => ['_format' => 'xml']]);
$this->addRequestWithFormat('xml');
$this->assertHeader('content-type', 'text/xml; charset=UTF-8');
$this->assertSession()->responseHeaderEquals('content-type', 'text/xml; charset=UTF-8');
$this->assertCacheContexts($cache_contexts);
$this->assertCacheTags($cache_tags);
$this->assertNotEmpty($render_cache->get($original));
Expand All @@ -352,7 +352,7 @@ public function testRestRenderCaching() {
// Ensure that the cached page works.
$result2 = Json::decode($this->drupalGet('test/serialize/entity', ['query' => ['_format' => 'json']]));
$this->addRequestWithFormat('json');
$this->assertHeader('content-type', 'application/json');
$this->assertSession()->responseHeaderEquals('content-type', 'application/json');
$this->assertEqual($result2, $result1);
$this->assertCacheContexts($cache_contexts);
$this->assertCacheTags($cache_tags);
Expand All @@ -362,7 +362,7 @@ public function testRestRenderCaching() {
EntityTest::create(['name' => 'test_11', 'user_id' => $this->adminUser->id()])->save();
$result3 = Json::decode($this->drupalGet('test/serialize/entity', ['query' => ['_format' => 'json']]));
$this->addRequestWithFormat('json');
$this->assertHeader('content-type', 'application/json');
$this->assertSession()->responseHeaderEquals('content-type', 'application/json');
$this->assertNotEqual($result3, $result2);

// Add the new entity cache tag and remove the first one, because we just
Expand All @@ -385,7 +385,7 @@ public function testResponseFormatConfiguration() {

// Ensure a request with no format returns 406 Not Acceptable.
$this->drupalGet('test/serialize/field');
$this->assertHeader('content-type', 'text/html; charset=UTF-8');
$this->assertSession()->responseHeaderEquals('content-type', 'text/html; charset=UTF-8');
$this->assertResponse(406);

// Select only 'xml' as an accepted format.
Expand All @@ -394,11 +394,11 @@ public function testResponseFormatConfiguration() {

// Ensure a request for JSON returns 406 Not Acceptable.
$this->drupalGet('test/serialize/field', ['query' => ['_format' => 'json']]);
$this->assertHeader('content-type', 'application/json');
$this->assertSession()->responseHeaderEquals('content-type', 'application/json');
$this->assertResponse(406);
// Ensure a request for XML returns 200 OK.
$this->drupalGet('test/serialize/field', ['query' => ['_format' => 'xml']]);
$this->assertHeader('content-type', 'text/xml; charset=UTF-8');
$this->assertSession()->responseHeaderEquals('content-type', 'text/xml; charset=UTF-8');
$this->assertResponse(200);

// Add 'json' as an accepted format, so we have multiple.
Expand All @@ -407,40 +407,40 @@ public function testResponseFormatConfiguration() {

// 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->assertHeader('content-type', 'text/html; charset=UTF-8');
$this->assertSession()->responseHeaderEquals('content-type', 'text/html; charset=UTF-8');
$this->assertResponse(406);

// Ensure a request for HTML returns 406 Not Acceptable.
$this->drupalGet('test/serialize/field', ['query' => ['_format' => 'html']]);
$this->assertHeader('content-type', 'text/html; charset=UTF-8');
$this->assertSession()->responseHeaderEquals('content-type', 'text/html; charset=UTF-8');
$this->assertResponse(406);

// Ensure a request for JSON returns 200 OK.
$this->drupalGet('test/serialize/field', ['query' => ['_format' => 'json']]);
$this->assertHeader('content-type', 'application/json');
$this->assertSession()->responseHeaderEquals('content-type', 'application/json');
$this->assertResponse(200);

// Ensure a request XML returns 200 OK.
$this->drupalGet('test/serialize/field', ['query' => ['_format' => 'xml']]);
$this->assertHeader('content-type', 'text/xml; charset=UTF-8');
$this->assertSession()->responseHeaderEquals('content-type', 'text/xml; charset=UTF-8');
$this->assertResponse(200);

// Now configure no format, so both serialization formats should be allowed.
$this->drupalPostForm($style_options, ['style_options[formats][json]' => '0', 'style_options[formats][xml]' => '0'], t('Apply'));

// Ensure a request for JSON returns 200 OK.
$this->drupalGet('test/serialize/field', ['query' => ['_format' => 'json']]);
$this->assertHeader('content-type', 'application/json');
$this->assertSession()->responseHeaderEquals('content-type', 'application/json');
$this->assertResponse(200);

// Ensure a request for XML returns 200 OK.
$this->drupalGet('test/serialize/field', ['query' => ['_format' => 'xml']]);
$this->assertHeader('content-type', 'text/xml; charset=UTF-8');
$this->assertSession()->responseHeaderEquals('content-type', 'text/xml; charset=UTF-8');
$this->assertResponse(200);

// Should return a 406 for HTML still.
$this->drupalGet('test/serialize/field', ['query' => ['_format' => 'html']]);
$this->assertHeader('content-type', 'text/html; charset=UTF-8');
$this->assertSession()->responseHeaderEquals('content-type', 'text/html; charset=UTF-8');
$this->assertResponse(406);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,35 @@ public function testAttachments() {
// Test ['#attached']['http_header] = ['Status', $code].
$this->drupalGet('/render_attached_test/teapot');
$this->assertResponse(418);
$this->assertHeader('X-Drupal-Cache', 'MISS');
$this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'MISS');
// Repeat for the cache.
$this->drupalGet('/render_attached_test/teapot');
$this->assertResponse(418);
$this->assertHeader('X-Drupal-Cache', 'HIT');
$this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'HIT');

// Test ['#attached']['http_header'] with various replacement rules.
$this->drupalGet('/render_attached_test/header');
$this->assertTeapotHeaders();
$this->assertHeader('X-Drupal-Cache', 'MISS');
$this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'MISS');
// Repeat for the cache.
$this->drupalGet('/render_attached_test/header');
$this->assertHeader('X-Drupal-Cache', 'HIT');
$this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'HIT');

// Test ['#attached']['feed'].
$this->drupalGet('/render_attached_test/feed');
$this->assertHeader('X-Drupal-Cache', 'MISS');
$this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'MISS');
$this->assertFeed();
// Repeat for the cache.
$this->drupalGet('/render_attached_test/feed');
$this->assertHeader('X-Drupal-Cache', 'HIT');
$this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'HIT');

// Test ['#attached']['html_head'].
$this->drupalGet('/render_attached_test/head');
$this->assertHeader('X-Drupal-Cache', 'MISS');
$this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'MISS');
$this->assertHead();
// Repeat for the cache.
$this->drupalGet('/render_attached_test/head');
$this->assertHeader('X-Drupal-Cache', 'HIT');
$this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'HIT');

// Test ['#attached']['html_head_link'] when outputted as HTTP header.
$this->drupalGet('/render_attached_test/html_header_link');
Expand Down Expand Up @@ -91,7 +91,7 @@ public function testRenderCachedBlock() {
// Make sure our block is visible.
$this->assertText('Markup from attached_rendering_block.');
// The header should be present again.
$this->assertHeader('X-Test-Teapot', 'Teapot Mode Active');
$this->assertSession()->responseHeaderEquals('X-Test-Teapot', 'Teapot Mode Active');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function testNonHtmlRequest() {
$this->drupalGet('<front>', ['query' => ['_format' => $format]]);
$this->assertResponse(503);
$this->assertRaw('Drupal is currently under maintenance. We should be back shortly. Thank you for your patience.');
$this->assertHeader('Content-Type', 'text/plain; charset=UTF-8');
$this->assertSession()->responseHeaderEquals('Content-Type', 'text/plain; charset=UTF-8');
}
}

Expand Down

0 comments on commit 9ad497a

Please sign in to comment.