Chris@0: drupalGet('/render_attached_test/teapot'); Chris@0: $this->assertResponse(418); Chris@0: $this->assertHeader('X-Drupal-Cache', 'MISS'); Chris@0: // Repeat for the cache. Chris@0: $this->drupalGet('/render_attached_test/teapot'); Chris@0: $this->assertResponse(418); Chris@0: $this->assertHeader('X-Drupal-Cache', 'HIT'); Chris@0: Chris@0: // Test ['#attached']['http_header'] with various replacement rules. Chris@0: $this->drupalGet('/render_attached_test/header'); Chris@0: $this->assertTeapotHeaders(); Chris@0: $this->assertHeader('X-Drupal-Cache', 'MISS'); Chris@0: // Repeat for the cache. Chris@0: $this->drupalGet('/render_attached_test/header'); Chris@0: $this->assertHeader('X-Drupal-Cache', 'HIT'); Chris@0: Chris@0: // Test ['#attached']['feed']. Chris@0: $this->drupalGet('/render_attached_test/feed'); Chris@0: $this->assertHeader('X-Drupal-Cache', 'MISS'); Chris@0: $this->assertFeed(); Chris@0: // Repeat for the cache. Chris@0: $this->drupalGet('/render_attached_test/feed'); Chris@0: $this->assertHeader('X-Drupal-Cache', 'HIT'); Chris@0: Chris@0: // Test ['#attached']['html_head']. Chris@0: $this->drupalGet('/render_attached_test/head'); Chris@0: $this->assertHeader('X-Drupal-Cache', 'MISS'); Chris@0: $this->assertHead(); Chris@0: // Repeat for the cache. Chris@0: $this->drupalGet('/render_attached_test/head'); Chris@0: $this->assertHeader('X-Drupal-Cache', 'HIT'); Chris@0: Chris@0: // Test ['#attached']['html_head_link'] when outputted as HTTP header. Chris@0: $this->drupalGet('/render_attached_test/html_header_link'); Chris@0: $expected_link_headers = [ Chris@0: '; rel="alternate"', Chris@0: '; hreflang="nl"; rel="alternate"', Chris@0: ]; Chris@0: $this->assertEqual($this->drupalGetHeader('link'), implode(',', $expected_link_headers)); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Test caching of ['#attached']. Chris@0: */ Chris@0: public function testRenderCachedBlock() { Chris@0: // Make sure our test block is visible. Chris@0: $this->drupalPlaceBlock('attached_rendering_block', ['region' => 'content']); Chris@0: Chris@0: // Get the front page, which should now have our visible block. Chris@0: $this->drupalGet(''); Chris@0: // Make sure our block is visible. Chris@0: $this->assertText('Markup from attached_rendering_block.'); Chris@0: // Test that all our attached items are present. Chris@0: $this->assertFeed(); Chris@0: $this->assertHead(); Chris@0: $this->assertResponse(418); Chris@0: $this->assertTeapotHeaders(); Chris@0: Chris@0: // Reload the page, to test caching. Chris@0: $this->drupalGet(''); Chris@0: // Make sure our block is visible. Chris@0: $this->assertText('Markup from attached_rendering_block.'); Chris@0: // The header should be present again. Chris@0: $this->assertHeader('X-Test-Teapot', 'Teapot Mode Active'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Helper function to make assertions about added HTTP headers. Chris@0: */ Chris@0: protected function assertTeapotHeaders() { Chris@0: $this->assertHeader('X-Test-Teapot', 'Teapot Mode Active'); Chris@0: $this->assertHeader('X-Test-Teapot-Replace', 'Teapot replaced'); Chris@0: $this->assertHeader('X-Test-Teapot-No-Replace', 'This value is not replaced,This one is added'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Helper function to make assertions about the presence of an RSS feed. Chris@0: */ Chris@0: protected function assertFeed() { Chris@0: // Discover the DOM element for the feed link. Chris@0: $test_meta = $this->xpath('//head/link[@href="test://url"]'); Chris@0: $this->assertEqual(1, count($test_meta), 'Link has URL.'); Chris@0: // Reconcile the other attributes. Chris@0: $test_meta_attributes = [ Chris@0: 'href' => 'test://url', Chris@0: 'rel' => 'alternate', Chris@0: 'type' => 'application/rss+xml', Chris@0: 'title' => 'Your RSS feed.', Chris@0: ]; Chris@0: $test_meta = reset($test_meta); Chris@0: if (empty($test_meta)) { Chris@0: $this->fail('Unable to find feed link.'); Chris@0: } Chris@0: else { Chris@0: foreach ($test_meta->attributes() as $attribute => $value) { Chris@0: $this->assertEqual($value, $test_meta_attributes[$attribute]); Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Helper function to make assertions about HTML head elements. Chris@0: */ Chris@0: protected function assertHead() { Chris@0: // Discover the DOM element for the meta link. Chris@0: $test_meta = $this->xpath('//head/meta[@test-attribute="testvalue"]'); Chris@0: $this->assertEqual(1, count($test_meta), 'There\'s only one test attribute.'); Chris@0: // Grab the only DOM element. Chris@0: $test_meta = reset($test_meta); Chris@0: if (empty($test_meta)) { Chris@0: $this->fail('Unable to find the head meta.'); Chris@0: } Chris@0: else { Chris@0: $test_meta_attributes = $test_meta->attributes(); Chris@0: $this->assertEqual($test_meta_attributes['test-attribute'], 'testvalue'); Chris@0: } Chris@0: } Chris@0: Chris@0: }