/**
  * Ensures that a metatag can be removed.
  */
 public function testMetatagRemovability()
 {
     $page = new HtmlPage();
     $page->addMetaElement(new MetaElement('', array('name' => 'example')));
     $page->addMetaElement(new MetaElement('', array('name' => 'example2')));
     $metatags =& $page->getMetaElements();
     foreach ($metatags as $key => $tag) {
         if ($tag->getName() == 'example') {
             unset($metatags[$key]);
         }
     }
     $metatags = $page->getMetaElements();
     reset($metatags);
     $this->assertCount(1, $metatags);
     $this->assertEquals('example2', current($metatags)->getName());
 }
Пример #2
0
 /**
  * Tests drupal_add_feed() with paths, URLs, and titles.
  */
 function testBasicFeedAddNoTitle()
 {
     $path = $this->randomMachineName(12);
     $external_url = 'http://' . $this->randomMachineName(12) . '/' . $this->randomMachineName(12);
     $fully_qualified_local_url = url($this->randomMachineName(12), array('absolute' => TRUE));
     $path_for_title = $this->randomMachineName(12);
     $external_for_title = 'http://' . $this->randomMachineName(12) . '/' . $this->randomMachineName(12);
     $fully_qualified_for_title = url($this->randomMachineName(12), array('absolute' => TRUE));
     // Possible permutations of drupal_add_feed() to test.
     // - 'input_url': the path passed to drupal_add_feed(),
     // - 'output_url': the expected URL to be found in the header.
     // - 'title' == the title of the feed as passed into drupal_add_feed().
     $urls = array('path without title' => array('url' => url($path, array('absolute' => TRUE)), 'title' => ''), 'external URL without title' => array('url' => $external_url, 'title' => ''), 'local URL without title' => array('url' => $fully_qualified_local_url, 'title' => ''), 'path with title' => array('url' => url($path_for_title, array('absolute' => TRUE)), 'title' => $this->randomMachineName(12)), 'external URL with title' => array('url' => $external_for_title, 'title' => $this->randomMachineName(12)), 'local URL with title' => array('url' => $fully_qualified_for_title, 'title' => $this->randomMachineName(12)));
     $html_page = new HtmlPage();
     foreach ($urls as $feed_info) {
         $feed_link = new FeedLinkElement($feed_info['title'], $feed_info['url']);
         $html_page->addLinkElement($feed_link);
     }
     $this->drupalSetContent(\Drupal::service('html_page_renderer')->render($html_page));
     foreach ($urls as $description => $feed_info) {
         $this->assertPattern($this->urlToRSSLinkPattern($feed_info['url'], $feed_info['title']), format_string('Found correct feed header for %description', array('%description' => $description)));
     }
 }
 /**
  * Apply the default meta tags to the page object.
  *
  * @param \Drupal\Core\Page\HtmlPage $page
  *   The html page.
  */
 protected function setDefaultMetaTags(HtmlPage $page)
 {
     // Add default elements. Make sure the Content-Type comes first because the
     // IE browser may be vulnerable to XSS via encoding attacks from any content
     // that comes before this META tag, such as a TITLE tag.
     $page->addMetaElement(new MetaElement(NULL, array('name' => 'charset', 'charset' => 'utf-8')));
     // Show Drupal and the major version number in the META GENERATOR tag.
     // Get the major version.
     list($version) = explode('.', \Drupal::VERSION, 2);
     $page->addMetaElement(new MetaElement('Drupal ' . $version . ' (http://drupal.org)', array('name' => 'Generator')));
     // Display the html.html.twig's default mobile metatags for responsive design.
     $page->addMetaElement(new MetaElement(NULL, array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1.0')));
 }