Chris@0: randomMachineName(12); Chris@0: $external_url = 'http://' . $this->randomMachineName(12) . '/' . $this->randomMachineName(12); Chris@0: $fully_qualified_local_url = Url::fromUri('base:' . $this->randomMachineName(12), ['absolute' => TRUE])->toString(); Chris@0: Chris@0: $path_for_title = $this->randomMachineName(12); Chris@0: $external_for_title = 'http://' . $this->randomMachineName(12) . '/' . $this->randomMachineName(12); Chris@0: $fully_qualified_for_title = Url::fromUri('base:' . $this->randomMachineName(12), ['absolute' => TRUE])->toString(); Chris@0: Chris@0: $urls = [ Chris@0: 'path without title' => [ Chris@0: 'url' => Url::fromUri('base:' . $path, ['absolute' => TRUE])->toString(), Chris@0: 'title' => '', Chris@0: ], Chris@0: 'external URL without title' => [ Chris@0: 'url' => $external_url, Chris@0: 'title' => '', Chris@0: ], Chris@0: 'local URL without title' => [ Chris@0: 'url' => $fully_qualified_local_url, Chris@0: 'title' => '', Chris@0: ], Chris@0: 'path with title' => [ Chris@0: 'url' => Url::fromUri('base:' . $path_for_title, ['absolute' => TRUE])->toString(), Chris@0: 'title' => $this->randomMachineName(12), Chris@0: ], Chris@0: 'external URL with title' => [ Chris@0: 'url' => $external_for_title, Chris@0: 'title' => $this->randomMachineName(12), Chris@0: ], Chris@0: 'local URL with title' => [ Chris@0: 'url' => $fully_qualified_for_title, Chris@0: 'title' => $this->randomMachineName(12), Chris@0: ], Chris@0: ]; Chris@0: Chris@0: $build = []; Chris@0: foreach ($urls as $feed_info) { Chris@0: $build['#attached']['feed'][] = [$feed_info['url'], $feed_info['title']]; Chris@0: } Chris@0: Chris@0: // Use the bare HTML page renderer to render our links. Chris@0: $renderer = $this->container->get('bare_html_page_renderer'); Chris@0: $response = $renderer->renderBarePage($build, '', 'maintenance_page'); Chris@0: // Glean the content from the response object. Chris@0: $this->setRawContent($response->getContent()); Chris@0: // Assert that the content contains the RSS links we specified. Chris@0: foreach ($urls as $description => $feed_info) { Chris@0: $this->assertPattern($this->urlToRSSLinkPattern($feed_info['url'], $feed_info['title']), format_string('Found correct feed header for %description', ['%description' => $description])); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Creates a pattern representing the RSS feed in the page. Chris@0: */ Chris@0: public function urlToRSSLinkPattern($url, $title = '') { Chris@0: // Escape any regular expression characters in the URL ('?' is the worst). Chris@0: $url = preg_replace('/([+?.*])/', '[$0]', $url); Chris@0: $generated_pattern = '%%'; Chris@0: return $generated_pattern; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Checks that special characters are correctly escaped. Chris@0: * Chris@0: * @see https://www.drupal.org/node/1211668 Chris@0: */ Chris@0: public function testFeedIconEscaping() { Chris@0: $variables = [ Chris@0: '#theme' => 'feed_icon', Chris@0: '#url' => 'node', Chris@0: '#title' => '<>&"\'', Chris@0: ]; Chris@0: $text = \Drupal::service('renderer')->renderRoot($variables); Chris@0: $this->assertEqual(trim(strip_tags($text)), 'Subscribe to <>&"'', 'feed_icon template escapes reserved HTML characters.'); Chris@0: } Chris@0: Chris@0: }