Commit 0bb3f721 authored by voleger's avatar voleger Committed by pifagor

Issue #2978936 by voleger, andralex, Tolyan4ik, pifagor, Dave Reid,...

Issue #2978936 by voleger, andralex, Tolyan4ik, pifagor, Dave Reid, alex_optim: Update tests for Drupal 9 based testing
parent 096dce13
<?php
namespace Drupal\xmlsitemap\Tests;
namespace Drupal\Tests\xmlsitemap\Functional;
use Drupal\Core\Session\AccountInterface;
use Drupal\entity_test\Entity\EntityTestMul;
......@@ -38,15 +38,15 @@ class XmlSitemapEntityFunctionalTest extends XmlSitemapTestBase {
public function testEntitiesSettingsForms() {
$this->drupalLogin($this->admin_user);
$this->drupalGet('admin/config/search/xmlsitemap/entities/settings');
$this->assertResponse(200);
$this->assertField('entity_types[entity_test_mul]');
$this->assertField('settings[entity_test_mul][types][entity_test_mul]');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->fieldExists('entity_types[entity_test_mul]');
$this->assertSession()->fieldExists('settings[entity_test_mul][types][entity_test_mul]');
$edit = [
'entity_types[entity_test_mul]' => 1,
'settings[entity_test_mul][types][entity_test_mul]' => 1,
];
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertText(t('The configuration options have been saved.'));
$this->drupalPostForm(NULL, $edit, 'Save');
$this->assertSession()->pageTextContains('The configuration options have been saved.');
$entity = EntityTestMul::create();
$entity->save();
$this->assertSitemapLinkValues('entity_test_mul', $entity->id(), [
......@@ -68,10 +68,10 @@ class XmlSitemapEntityFunctionalTest extends XmlSitemapTestBase {
$this->drupalLogin($this->admin_user);
// Set priority and inclusion for entity_test_mul - entity_test_mul.
$this->drupalGet('admin/config/search/xmlsitemap/settings/entity_test_mul/entity_test_mul');
$this->assertResponse(200);
$this->assertField('xmlsitemap[status]');
$this->assertField('xmlsitemap[priority]');
$this->assertField('xmlsitemap[changefreq]');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->fieldExists('xmlsitemap[status]');
$this->assertSession()->fieldExists('xmlsitemap[priority]');
$this->assertSession()->fieldExists('xmlsitemap[changefreq]');
$edit = [
'xmlsitemap[status]' => 0,
'xmlsitemap[priority]' => 0.3,
......@@ -89,8 +89,8 @@ class XmlSitemapEntityFunctionalTest extends XmlSitemapTestBase {
$this->regenerateSitemap();
$this->drupalGetSitemap();
$this->assertResponse(200);
$this->assertNoRaw($entity->toUrl()->getInternalPath());
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->responseNotContains($entity->toUrl()->getInternalPath());
$entity->delete();
$this->assertNoSitemapLink('entity_test_mul');
......@@ -112,8 +112,8 @@ class XmlSitemapEntityFunctionalTest extends XmlSitemapTestBase {
$this->regenerateSitemap();
$this->drupalGetSitemap();
$this->assertResponse(200);
$this->assertRaw($entity->toUrl()->getInternalPath());
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->responseContains($entity->toUrl()->getInternalPath());
$id = $entity->id();
$entity->delete();
......
<?php
namespace Drupal\xmlsitemap\Tests;
namespace Drupal\Tests\xmlsitemap\Functional;
/**
* Tests the generation of sitemaps.
......@@ -32,14 +32,17 @@ class XmlSitemapFunctionalTest extends XmlSitemapTestBase {
$this->drupalLogin($this->admin_user);
$this->regenerateSitemap();
$this->drupalGetSitemap();
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$etag = $this->drupalGetHeader('etag');
$last_modified = $this->drupalGetHeader('last-modified');
$this->assertTrue($etag, t('Etag header found.'));
$this->assertTrue($last_modified, t('Last-modified header found.'));
$this->assertNotEmpty($etag, t('Etag header found.'));
$this->assertNotEmpty($last_modified, t('Last-modified header found.'));
$this->drupalGetSitemap([], [], ['If-Modified-Since: ' . $last_modified, 'If-None-Match: ' . $etag]);
$this->assertResponse(304);
$this->drupalGetSitemap([], [], [
'If-Modified-Since' => $last_modified,
'If-None-Match' => $etag,
]);
$this->assertSession()->statusCodeEquals(304);
}
/**
......@@ -51,23 +54,23 @@ class XmlSitemapFunctionalTest extends XmlSitemapTestBase {
// @codingStandardsIgnoreEnd
$this->drupalLogin($this->admin_user);
$edit = ['xmlsitemap_base_url' => ''];
$this->drupalPostForm('admin/config/search/xmlsitemap/settings', $edit, t('Save configuration'));
$this->drupalPostForm('admin/config/search/xmlsitemap/settings', $edit, 'Save configuration');
$edit = ['xmlsitemap_base_url' => 'invalid'];
$this->drupalPostForm('admin/config/search/xmlsitemap/settings', $edit, t('Save configuration'));
$this->assertText(t('Invalid base URL.'));
$this->drupalPostForm('admin/config/search/xmlsitemap/settings', $edit, 'Save configuration');
$this->assertSession()->pageTextContains('Invalid base URL.');
$edit = ['xmlsitemap_base_url' => 'http://example.com/ '];
$this->drupalPostForm('admin/config/search/xmlsitemap/settings', $edit, t('Save configuration'));
$this->assertText(t('Invalid base URL.'));
$this->drupalPostForm('admin/config/search/xmlsitemap/settings', $edit, 'Save configuration');
$this->assertSession()->pageTextContains('Invalid base URL.');
$edit = ['xmlsitemap_base_url' => 'http://example.com/'];
$this->drupalPostForm('admin/config/search/xmlsitemap/settings', $edit, t('Save configuration'));
$this->assertText(t('The configuration options have been saved.'));
$this->drupalPostForm('admin/config/search/xmlsitemap/settings', $edit, 'Save configuration');
$this->assertSession()->pageTextContains('The configuration options have been saved.');
$this->regenerateSitemap();
$this->drupalGetSitemap([], ['base_url' => NULL]);
$this->assertRaw('<loc>http://example.com/</loc>');
$this->assertSession()->responseContains('<loc>http://example.com/</loc>');
}
/**
......@@ -81,28 +84,28 @@ class XmlSitemapFunctionalTest extends XmlSitemapTestBase {
// Test the rebuild flag.
$this->drupalLogin($this->admin_user);
$this->state->set('xmlsitemap_generated_last', REQUEST_TIME);
$this->state->set('xmlsitemap_generated_last', $this->time->getRequestTime());
$this->state->set('xmlsitemap_rebuild_needed', TRUE);
$this->assertXMLSitemapProblems(t('The XML sitemap data is out of sync and needs to be completely rebuilt.'));
$this->clickLink(t('completely rebuilt'));
$this->assertResponse(200);
$this->assertXMLSitemapProblems('The XML sitemap data is out of sync and needs to be completely rebuilt.');
$this->clickLink('completely rebuilt');
$this->assertSession()->statusCodeEquals(200);
$this->state->set('xmlsitemap_rebuild_needed', FALSE);
$this->assertNoXMLSitemapProblems();
// Test the regenerate flag (and cron has run recently).
$this->state->set('xmlsitemap_regenerate_needed', TRUE);
$this->state->set('xmlsitemap_generated_last', REQUEST_TIME - $cron_warning_threshold - 600);
$this->state->set('system.cron_last', REQUEST_TIME - $cron_warning_threshold + 600);
$this->state->set('xmlsitemap_generated_last', $this->time->getRequestTime() - $cron_warning_threshold - 600);
$this->state->set('system.cron_last', $this->time->getRequestTime() - $cron_warning_threshold + 600);
$this->assertNoXMLSitemapProblems();
// Test the regenerate flag (and cron hasn't run in a while).
$this->state->set('xmlsitemap_regenerate_needed', TRUE);
$this->state->set('system.cron_last', 0);
$this->state->set('install_time', 0);
$this->state->set('xmlsitemap_generated_last', REQUEST_TIME - $cron_warning_threshold - 600);
$this->assertXMLSitemapProblems(t('The XML cached files are out of date and need to be regenerated. You can run cron manually to regenerate the sitemap files.'));
$this->clickLink(t('run cron manually'));
$this->assertResponse(200);
$this->state->set('xmlsitemap_generated_last', $this->time->getRequestTime() - $cron_warning_threshold - 600);
$this->assertXMLSitemapProblems('The XML cached files are out of date and need to be regenerated. You can run cron manually to regenerate the sitemap files.');
$this->clickLink('run cron manually');
$this->assertSession()->statusCodeEquals(200);
$this->assertNoXMLSitemapProblems();
}
......
<?php
namespace Drupal\xmlsitemap\Tests;
namespace Drupal\Tests\xmlsitemap\Functional;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\xmlsitemap\Entity\XmlSitemap;
......@@ -17,12 +18,21 @@ class XmlSitemapListBuilderTest extends XmlSitemapTestBase {
*/
public static $modules = ['language', 'locale', 'content_translation'];
/**
* Entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->entityTypeManager = $this->container->get('entity_type.manager');
$this->admin_user = $this->drupalCreateUser([
'administer languages',
'access administration pages',
......@@ -32,7 +42,7 @@ class XmlSitemapListBuilderTest extends XmlSitemapTestBase {
]);
$this->drupalLogin($this->admin_user);
$this->languageManager = \Drupal::languageManager();
$this->languageManager = $this->container->get('language_manager');
if (!$this->languageManager->getLanguage('fr')) {
// Add a new language.
ConfigurableLanguage::createFromLangcode('fr')->save();
......@@ -61,7 +71,7 @@ class XmlSitemapListBuilderTest extends XmlSitemapTestBase {
$id = xmlsitemap_sitemap_get_context_hash($context);
$this->drupalGet('admin/config/search/xmlsitemap');
$this->assertText($id);
$this->assertSession()->pageTextContains($id);
}
/**
......@@ -76,31 +86,31 @@ class XmlSitemapListBuilderTest extends XmlSitemapTestBase {
$this->drupalPostForm('admin/config/search/xmlsitemap/add', $edit, t('Save'));
$context = ['language' => 'en'];
$id = xmlsitemap_sitemap_get_context_hash($context);
$this->assertText(t('Saved the English sitemap.'));
$this->assertText($id);
$this->assertSession()->pageTextContains('Saved the English sitemap.');
$this->assertSession()->pageTextContains($id);
$edit = [
'label' => 'French',
'context[language]' => 'fr',
];
$this->drupalPostForm('admin/config/search/xmlsitemap/add', $edit, t('Save'));
$this->drupalPostForm('admin/config/search/xmlsitemap/add', $edit, 'Save');
$context = ['language' => 'fr'];
$id = xmlsitemap_sitemap_get_context_hash($context);
$this->assertText(t('Saved the French sitemap.'));
$this->assertText($id);
$this->assertSession()->pageTextContains('Saved the French sitemap.');
$this->assertSession()->pageTextContains($id);
$this->drupalPostForm('admin/config/search/xmlsitemap/add', $edit, t('Save'));
$this->assertText(t('There is another sitemap saved with the same context.'));
$this->assertSession()->pageTextContains('There is another sitemap saved with the same context.');
$sitemaps = XmlSitemap::loadMultiple();
foreach ($sitemaps as $sitemap) {
$label = $sitemap->label();
$this->drupalPostForm("admin/config/search/xmlsitemap/{$sitemap->id()}/delete", [], t('Delete'));
$this->assertRaw(t("Sitemap %label has been deleted.", ['%label' => $label]));
$this->assertSession()->responseContains((string) new FormattableMarkup('Sitemap %label has been deleted.', ['%label' => $label]));
}
$sitemaps = XmlSitemap::loadMultiple();
$this->assertEqual(count($sitemaps), 0, t('No more sitemaps.'));
$this->assertEquals(0, count($sitemaps), 'No more sitemaps.');
}
}
<?php
namespace Drupal\xmlsitemap\Tests;
namespace Drupal\Tests\xmlsitemap\Functional;
use Drupal\Core\Session\AccountInterface;
use Drupal\user\Entity\Role;
......@@ -17,19 +17,27 @@ class XmlSitemapMenuFunctionalTest extends XmlSitemapTestBase {
*/
public static $modules = ['menu_link_content', 'menu_ui'];
/**
* Entity type bundle info service.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $entityTypeBundleInfo;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->entityTypeBundleInfo = $this->container->get('entity_type.bundle.info');
// Allow anonymous user to administer menu links.
$user_role = Role::load(AccountInterface::ANONYMOUS_ROLE);
$user_role->grantPermission('administer menu');
$user_role->grantPermission('access content');
$user_role->save();
$bundles = \Drupal::service('entity_type.bundle.info')->getAllBundleInfo();
$bundles = $this->entityTypeBundleInfo->getAllBundleInfo();
foreach ($bundles['menu_link_content'] as $bundle_id => $bundle) {
xmlsitemap_link_bundle_enable('menu_link_content', $bundle_id);
}
......@@ -86,7 +94,7 @@ class XmlSitemapMenuFunctionalTest extends XmlSitemapTestBase {
* {@inheritdoc}
*/
public function tearDown() {
$bundles = \Drupal::service('entity_type.bundle.info')->getAllBundleInfo();
$bundles = $this->entityTypeBundleInfo->getAllBundleInfo();
foreach ($bundles['menu_link_content'] as $bundle_id => $bundle) {
xmlsitemap_link_bundle_delete('menu_link_content', $bundle_id);
}
......
<?php
namespace Drupal\xmlsitemap\Tests;
namespace Drupal\Tests\xmlsitemap\Functional;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Session\AccountInterface;
use Drupal\user\Entity\Role;
......@@ -46,8 +47,10 @@ class XmlSitemapMultilingualNodeTest extends XmlSitemapMultilingualTestBase {
$edit = [
'language_configuration[language_alterable]' => TRUE,
];
$this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type'));
$this->assertRaw(t('The content type %type has been updated.', ['%type' => 'Basic page']), 'Basic page content type has been updated.');
$this->drupalPostForm('admin/structure/types/manage/page', $edit, 'Save content type');
$this->assertSession()->responseContains((string) new FormattableMarkup('The content type %content_type has been updated.', [
'%content_type' => 'Basic page',
]));
}
/**
......@@ -61,11 +64,11 @@ class XmlSitemapMultilingualNodeTest extends XmlSitemapMultilingualTestBase {
'langcode[0][value]' => 'en',
], t('Save'));
$link = $this->assertSitemapLink('node', $node->id(), ['status' => 0, 'access' => 1]);
$this->assertIdentical($link['language'], 'en');
$this->assertSame('en', $link['language']);
$this->drupalPostForm('node/' . $node->id() . '/edit', ['langcode[0][value]' => 'fr'], t('Save'));
$link = $this->assertSitemapLink('node', $node->id(), ['status' => 0, 'access' => 1]);
$this->assertIdentical($link['language'], 'fr');
$this->assertSame('fr', $link['language']);
}
}
<?php
namespace Drupal\xmlsitemap\Tests;
namespace Drupal\Tests\xmlsitemap\Functional;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Url;
......@@ -39,10 +39,10 @@ class XmlSitemapMultilingualTest extends XmlSitemapMultilingualTestBase {
// languages. The link ends with a slash.
$frontpage_link = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();
$this->drupalGet('sitemap.xml');
$this->assertRaw($frontpage_link, "English frontpage link found in the sitemap.");
$this->assertSession()->responseContains($frontpage_link, "English frontpage link found in the sitemap.");
$this->drupalGet('fr/sitemap.xml');
$this->assertRaw($frontpage_link . 'fr', "French frontpage link found in the sitemap.");
$this->assertSession()->responseContains($frontpage_link . 'fr', "French frontpage link found in the sitemap.");
}
/**
......
<?php
namespace Drupal\xmlsitemap\Tests;
namespace Drupal\Tests\xmlsitemap\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\xmlsitemap\Entity\XmlSitemap;
......
<?php
namespace Drupal\xmlsitemap\Tests;
namespace Drupal\Tests\xmlsitemap\Functional;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
......@@ -32,12 +32,21 @@ class XmlSitemapNodeFunctionalTest extends XmlSitemapTestBase {
*/
protected $nodes = [];
/**
* Entity type manager interface.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->entityTypeManager = $this->container->get('entity_type.manager');
$this->admin_user = $this->drupalCreateUser([
'administer nodes',
'bypass node access',
......@@ -174,15 +183,15 @@ class XmlSitemapNodeFunctionalTest extends XmlSitemapTestBase {
$this->drupalLogin($this->normal_user);
$this->drupalGet('node/' . $node->id() . '/edit');
$this->assertNoField('xmlsitemap[status]');
$this->assertNoField('xmlsitemap[priority]');
$this->assertSession()->fieldNotExists('xmlsitemap[status]');
$this->assertSession()->fieldNotExists('xmlsitemap[priority]');
$edit = [
'title[0][value]' => 'Test node title',
'body[0][value]' => 'Test node body',
];
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
$this->assertText('Basic page Test node title has been updated.');
$this->assertSession()->pageTextContains('Basic page Test node title has been updated.');
$this->assertSitemapLinkValues('node', $node->id(), [
'access' => 1,
'status' => 1,
......@@ -194,16 +203,16 @@ class XmlSitemapNodeFunctionalTest extends XmlSitemapTestBase {
$this->drupalLogin($this->admin_user);
$this->drupalGet('node/' . $node->id() . '/edit');
$this->assertField('xmlsitemap[status]');
$this->assertField('xmlsitemap[priority]');
$this->assertField('xmlsitemap[changefreq]');
$this->assertSession()->fieldExists('xmlsitemap[status]');
$this->assertSession()->fieldExists('xmlsitemap[priority]');
$this->assertSession()->fieldExists('xmlsitemap[changefreq]');
$edit = [
'xmlsitemap[status]' => 1,
'xmlsitemap[priority]' => 0.9,
'xmlsitemap[changefreq]' => XMLSITEMAP_FREQUENCY_ALWAYS,
];
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
$this->assertText('Basic page Test node title has been updated.');
$this->assertSession()->pageTextContains('Basic page Test node title has been updated.');
$this->assertSitemapLinkValues('node', $node->id(), [
'access' => 1,
'status' => 1,
......@@ -218,7 +227,7 @@ class XmlSitemapNodeFunctionalTest extends XmlSitemapTestBase {
'xmlsitemap[priority]' => 'default',
];
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
$this->assertText('Basic page Test node title has been updated.');
$this->assertSession()->pageTextContains('Basic page Test node title has been updated.');
$this->assertSitemapLinkValues('node', $node->id(), [
'access' => 1,
'status' => 1,
......@@ -246,7 +255,7 @@ class XmlSitemapNodeFunctionalTest extends XmlSitemapTestBase {
'xmlsitemap[priority]' => '0.0',
];
$this->drupalPostForm('admin/config/search/xmlsitemap/settings/node/page', $edit, t('Save configuration'));
$this->assertText('The configuration options have been saved.');
$this->assertSession()->pageTextContains('The configuration options have been saved.');
$node = $this->drupalCreateNode();
$this->assertSitemapLinkValues('node', $node->id(), ['status' => 0, 'priority' => 0.0]);
$this->assertSitemapLinkValues('node', $node_old->id(), ['status' => 0, 'priority' => 0.0]);
......@@ -256,8 +265,8 @@ class XmlSitemapNodeFunctionalTest extends XmlSitemapTestBase {
$node_old->delete();
$this->drupalPostForm('admin/structure/types/manage/page/delete', [], t('Delete'));
$this->assertText('The content type Basic page has been deleted.');
$this->assertFalse($this->linkStorage->loadMultiple(['type' => 'node', 'subtype' => 'page']), 'Nodes with deleted node type removed from {xmlsitemap}.');
$this->assertSession()->pageTextContains('The content type Basic page has been deleted.');
$this->assertEmpty($this->linkStorage->loadMultiple(['type' => 'node', 'subtype' => 'page']), 'Nodes with deleted node type removed from {xmlsitemap}.');
}
/**
......
<?php
namespace Drupal\xmlsitemap\Tests;
namespace Drupal\Tests\xmlsitemap\Functional;
use Drupal\Core\Session\AccountInterface;
use Drupal\user\Entity\Role;
......@@ -41,11 +41,11 @@ class XmlSitemapRebuildTest extends XmlSitemapTestBase {
public function testSimpleRebuild() {
$this->drupalLogin($this->admin_user);
$this->drupalGet('admin/config/search/xmlsitemap/rebuild');
$this->assertResponse(200);
$this->assertText(t("This action rebuilds your site's XML sitemap and regenerates the cached files, and may be a lengthy process. If you just installed XML sitemap, this can be helpful to import all your site's content into the sitemap. Otherwise, this should only be used in emergencies."));
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains("This action rebuilds your site's XML sitemap and regenerates the cached files, and may be a lengthy process. If you just installed XML sitemap, this can be helpful to import all your site's content into the sitemap. Otherwise, this should only be used in emergencies.");
$this->drupalPostForm(NULL, [], t('Save configuration'));
$this->assertText('The sitemap links were rebuilt.');
$this->drupalPostForm(NULL, [], 'Save configuration');
$this->assertSession()->pageTextContains('The sitemap links were rebuilt.');
}
/**
......@@ -61,7 +61,7 @@ class XmlSitemapRebuildTest extends XmlSitemapTestBase {
$dummy_user = $this->drupalCreateUser([]);
$this->drupalLogin($this->admin_user);
$this->drupalPostForm('admin/config/search/xmlsitemap/rebuild', [], t('Save configuration'));
$this->assertText('The sitemap links were rebuilt.');
$this->assertSession()->pageTextContains('The sitemap links were rebuilt.');
$this->assertSitemapLinkValues('user', $dummy_user->id(), [
'status' => 1,
'priority' => 0.4,
......@@ -69,7 +69,7 @@ class XmlSitemapRebuildTest extends XmlSitemapTestBase {
'access' => 1,
]);
$this->drupalGet('sitemap.xml');
$this->assertRaw("user/{$dummy_user->id()}");
$this->assertSession()->responseContains("user/{$dummy_user->id()}");
}
}
<?php
namespace Drupal\xmlsitemap\Tests;
namespace Drupal\Tests\xmlsitemap\Functional;
use Drupal\Core\Url;
use Drupal\xmlsitemap\Entity\XmlSitemap;
/**
* Tests the robots.txt file existence.
......@@ -28,8 +29,10 @@ class XmlSitemapRobotsTxtIntegrationTest extends XmlSitemapTestBase {
$this->container = $this->kernel->rebuildContainer();
$this->prepareRequestForGenerator(FALSE);
$this->drupalGet('robots.txt');
$this->assertRaw('Sitemap: ' . Url::fromRoute('xmlsitemap.sitemap_xml', [], ['absolute' => TRUE])->toString());
$this->assertNotEmpty(XmlSitemap::loadByContext());
$this->drupalGet(Url::fromRoute('robotstxt.content'));
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->responseContains('Sitemap: ' . Url::fromRoute('xmlsitemap.sitemap_xml', [], ['absolute' => TRUE])->toString());
}
}
<?php
namespace Drupal\xmlsitemap\Tests;
namespace Drupal\Tests\xmlsitemap\Functional;
use Drupal\Core\Language\LanguageInterface;
use Drupal\taxonomy\Entity\Vocabulary;
......@@ -50,10 +50,11 @@ class XmlSitemapTaxonomyFunctionalTest extends XmlSitemapTestBase {
xmlsitemap_link_bundle_settings_save('taxonomy_term', 'tags', $settings);
$this->drupalGet('admin/structure/taxonomy/manage/tags/add');
$this->assertResponse(200);
$this->assertField('xmlsitemap[status]');
$this->assertField('xmlsitemap[priority]');
$this->assertField('xmlsitemap[changefreq]');
$session = $this->assertSession();
$session->statusCodeEquals(200);
$session->fieldExists('xmlsitemap[status]');
$session->fieldExists('xmlsitemap[priority]');
$session->fieldExists('xmlsitemap[changefreq]');
$term_name = $this->randomMachineName();
$edit = [
......@@ -64,9 +65,9 @@ class XmlSitemapTaxonomyFunctionalTest extends XmlSitemapTestBase {
$this->drupalPostForm(NULL, $edit, t('Save'));
$term = taxonomy_term_load_multiple_by_name($term_name, 'tags')[1];
$link = \Drupal::service('xmlsitemap.link_storage')->load('taxonomy_term', $term->id());
$this->assertEqual((int) $link['status'], 1);
$this->assertEqual((int) $link['priority'], 1);
$link = $this->linkStorage->load('taxonomy_term', $term->id());
$this->assertEquals(1, (int) $link['status']);
$this->assertEquals(1, (int) $link['priority']);
}
}
<?php
namespace Drupal\xmlsitemap\Tests;
namespace Drupal\Tests\xmlsitemap\Functional;
use Drupal\Core\Logger\RfcLogLevel;
use Drupal\Core\Url;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\Traits\Core\CronRunTrait;
use Drupal\xmlsitemap\Entity\XmlSitemap;
/**
* Helper test class with some added functions for testing.
*/
abstract class XmlSitemapTestBase extends WebTestBase {
abstract class XmlSitemapTestBase extends BrowserTestBase {
use CronRunTrait;
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Modules to enable.
......@@ -71,17 +79,34 @@ abstract class XmlSitemapTestBase extends WebTestBase {
*/
protected $linkStorage;
/**
* System time service.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $time;
/**
* Entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->state = \Drupal::state();
$this->config = \Drupal::configFactory()->getEditable('xmlsitemap.settings');
$this->moduleHandler = \Drupal::moduleHandler();
$this->languageManager = \Drupal::languageManager();
$this->linkStorage = \Drupal::service('xmlsitemap.link_storage');
$this->entityTypeManager = $this->container->get('entity_type.manager');
$this->state = $this->container->get('state');
$this->config = $this->container->get('config.factory')->getEditable('xmlsitemap.settings');
$this->moduleHandler = $this->container->get('module_handler');
$this->languageManager = $this->container->get('language_manager');
$this->linkStorage = $this->container->get('xmlsitemap.link_storage');
$this->time = $this->container->get('datetime.time');
// Create the Article and Page content types.
if ($this->profile != 'standard') {
......@@ -133,17 +158,6 @@ abstract class XmlSitemapTestBase extends WebTestBase {
return $this->assertFalse($match, $message ? $message : t('HTTP response not expected @code, actual @curl_code', ['@code' => $code, '@curl_code' => $curl_code]), t('Browser'));
}
/**
* Check the files directory is created (massive fails if not done).
*
* @todo This can be removed when https://www.drupal.org/node/654752 is fixed.
*/
protected function checkFilesDirectory() {
if (!xmlsitemap_check_directory()) {
$this->fail(t('Sitemap directory was found and writable for testing.'));
}
}
/**
* Retrieves an XML sitemap.
*
......@@ -231,13 +245,13 @@ abstract class XmlSitemapTestBase extends WebTestBase {
$link = $this->linkStorage->load($entity_type, $entity_id);
if (!$link) {
return $this->fail(t('Could not load sitemap link for @type @id.', ['@type' => $entity_type, '@id' => $entity_id]));
return $this->fail(sprintf('Could not load sitemap link for %s %s.', $entity_type, $entity_id));
}
foreach ($conditions as $key => $value) {
if ($value === NULL || $link[$key] === NULL) {
// For nullable fields, always check for identical values (===).
$this->assertIdentical($link[$key], $value, t('Identical values for @type @id link field @key.', [
$this->assertSame($value, $link[$key], t('Identical values for @type @id link field @key.', [
'@type' => $entity_type,
'@id' => $entity_id,
'@key' => $key,
......@@ -245,7 +259,7 @@ abstract class XmlSitemapTestBase extends WebTestBase {
}
else {
// Otherwise check simple equality (==).
$this->assertEqual($link[$key], $value, t('Equal values for @type @id link field @key - @a - @b.', [
$this->assertEquals($value, $link[$key], t('Equal values for @type @id link field @key - @a - @b.', [
'@type' => $entity_type,
'@id' => $entity_id,
'@key' => $key,
......@@ -263,13 +277,13 @@ abstract class XmlSitemapTestBase extends WebTestBase {
$link = $this->linkStorage->load($entity_type, $entity_id);
if (!$link) {
return $this->fail(t('Could not load sitemap link for @type @id.', ['@type' => $entity_type, '@id' => $entity_id]));
return $this->fail(sprintf('Could not load sitemap link for %s %s.', $entity_type, $entity_id));