You are here

public function MetaInformationTest::testSiteMap in Thunder 8.2

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

Test Site Map for Article.

File

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

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();
  $this
    ->runCron();
  $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, [
    'simple_sitemap_priority' => '0.9',
  ]);
  $this
    ->clickSave();
  $this
    ->runCron();
  $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
    ->getSession()
    ->visit($this
    ->buildUrl('admin/config/search/simplesitemap'));
  $page = $this
    ->getSession()
    ->getPage();
  $this
    ->setFieldValues($page, [
    'max_links' => '2',
  ]);
  $page
    ->find('xpath', '//input[@id="edit-submit"]')
    ->click();
  $this
    ->runCron();

  // 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', $lastSiteMapUrl);

  // Get 3rd sitemap.xml file and check that link exits there.
  $this
    ->getSession()
    ->visit($this
    ->buildUrl('sitemaps/3/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
    ->getSession()
    ->visit($this
    ->buildUrl('node/' . $articleId . '/edit'));
  $page = $this
    ->getSession()
    ->getPage();
  $this
    ->expandAllTabs();
  $this
    ->scrollElementInView('[name="simple_sitemap_index_content"]');
  $page
    ->find('css', '[name="simple_sitemap_index_content"]')
    ->click();
  $this
    ->clickSave();
  $this
    ->runCron();
  $this
    ->drupalGet('sitemaps/3/sitemap.xml');
  $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'));
}