You are here

public function MetaInformationTest::testSiteMap in Thunder 6.1.x

Same name and namespace in other branches
  1. 8.5 tests/src/FunctionalJavascript/MetaInformationTest.php \Drupal\Tests\thunder\FunctionalJavascript\MetaInformationTest::testSiteMap()
  2. 8.2 tests/src/FunctionalJavascript/MetaInformationTest.php \Drupal\Tests\thunder\FunctionalJavascript\MetaInformationTest::testSiteMap()
  3. 8.3 tests/src/FunctionalJavascript/MetaInformationTest.php \Drupal\Tests\thunder\FunctionalJavascript\MetaInformationTest::testSiteMap()
  4. 8.4 tests/src/FunctionalJavascript/MetaInformationTest.php \Drupal\Tests\thunder\FunctionalJavascript\MetaInformationTest::testSiteMap()
  5. 6.2.x tests/src/FunctionalJavascript/MetaInformationTest.php \Drupal\Tests\thunder\FunctionalJavascript\MetaInformationTest::testSiteMap()
  6. 6.0.x tests/src/FunctionalJavascript/MetaInformationTest.php \Drupal\Tests\thunder\FunctionalJavascript\MetaInformationTest::testSiteMap()

Test Site Map for Article.

File

tests/src/FunctionalJavascript/MetaInformationTest.php, line 324

Class

MetaInformationTest
Testing of Meta Information.

Namespace

Drupal\Tests\thunder\FunctionalJavascript

Code

public function testSiteMap() {
  $articleId = 10;
  $articleUrl = 'test-sitemap-seo-title';
  $customFields = [
    'field_seo_title[0][value]' => $articleUrl,
  ];
  $this
    ->createArticleWithFields($customFields);
  $this
    ->drupalGet('node/' . $articleId . '/edit');

  // Publish article.
  $this
    ->setModerationState('published');
  $this
    ->clickSave();

  // Do not add html transformation information to prevent rendering of the
  // sitemap in html.
  $this->sitemapGenerator
    ->saveSetting('xsl', FALSE);
  $this->sitemapGenerator
    ->generateSitemap('backend');
  $this
    ->drupalGet('sitemap.xml');
  $content = $this
    ->getSession()
    ->getPage()
    ->getContent();
  $domElements = $this
    ->getSiteMapDomElements($content, '//sm:loc[contains(text(),"/' . $articleUrl . '")]/parent::sm:url/sm:priority');
  $this
    ->assertEquals(1, $domElements->length);
  $this
    ->assertEquals('0.5', $domElements
    ->item(0)->nodeValue);

  // After sitemap.xml -> we have to open page without setting cookie before.
  $this
    ->getSession()
    ->visit($this
    ->buildUrl('node/' . $articleId . '/edit'));
  $page = $this
    ->getSession()
    ->getPage();
  $this
    ->expandAllTabs();
  $this
    ->setFieldValues($page, [
    'priority_default_node_settings' => '0.9',
  ]);
  $this
    ->clickSave();
  $this->sitemapGenerator
    ->generateSitemap('backend');
  $this
    ->drupalGet('sitemap.xml');
  $content = $this
    ->getSession()
    ->getPage()
    ->getContent();
  $domElements = $this
    ->getSiteMapDomElements($content, '//sm:loc[contains(text(),"/' . $articleUrl . '")]/parent::sm:url/sm:priority');
  $this
    ->assertEquals(1, $domElements->length);
  $this
    ->assertEquals('0.9', $domElements
    ->item(0)->nodeValue);

  // After sitemap.xml -> we have to open page without setting cookie before.
  $this->container
    ->get('config.factory')
    ->getEditable('simple_sitemap.settings')
    ->set('max_links', 2)
    ->save();
  $this->sitemapGenerator
    ->generateSitemap('backend');

  // Check loc, that it's pointing to sitemap.xml file.
  $this
    ->drupalGet('sitemap.xml');
  $content = $this
    ->getSession()
    ->getPage()
    ->getContent();
  $domElements = $this
    ->getSiteMapDomElements($content, '(//sm:loc)[last()]');
  $lastSiteMapUrl = $domElements
    ->item(0)->nodeValue;
  $this
    ->assertStringEndsWith('/sitemap.xml?page=7', $lastSiteMapUrl);

  // Get 3rd sitemap.xml file and check that link exits there.
  $urlOptions = [
    'query' => [
      'page' => 3,
    ],
  ];
  $this
    ->getSession()
    ->visit($this
    ->buildUrl('sitemap.xml', $urlOptions));
  $content = $this
    ->getSession()
    ->getPage()
    ->getContent();
  $domElements = $this
    ->getSiteMapDomElements($content, '//sm:loc[contains(text(),"/' . $articleUrl . '")]/parent::sm:url/sm:priority');
  $this
    ->assertEquals(1, $domElements->length);
  $this
    ->assertEquals('0.9', $domElements
    ->item(0)->nodeValue);

  // After sitemap.xml -> we have to open page without setting cookie before.
  $this
    ->getSession()
    ->visit($this
    ->buildUrl('node/' . $articleId . '/edit'));
  $page = $this
    ->getSession()
    ->getPage();
  $this
    ->expandAllTabs();
  $this
    ->setFieldValues($page, [
    'index_default_node_settings' => '0',
  ]);
  $this
    ->clickSave();
  $this->sitemapGenerator
    ->generateSitemap('backend');
  $this
    ->drupalGet('sitemap.xml', $urlOptions);
  $content = $this
    ->getSession()
    ->getPage()
    ->getContent();
  $domElements = $this
    ->getSiteMapDomElements($content, '//sm:loc[contains(text(),"/' . $articleUrl . '")]');
  $this
    ->assertEquals(0, $domElements->length);
  $this
    ->getSession()
    ->visit($this
    ->buildUrl('node/' . $articleId . '/edit'));
}