Commit 3f896dea authored by andrei.dincu's avatar andrei.dincu
Browse files

Issue #2249723 by andrei.dincu: Update all tests and get object services as...

Issue #2249723 by andrei.dincu: Update all tests and get object services as variables instead of calling \Drupal::* every time
parent b3fa9221
......@@ -13,11 +13,9 @@ namespace Drupal\xmlsitemap\Tests;
class XmlSitemapFunctionalTest extends XmlSitemapTestBase {
public static $modules = array('xmlsitemap', 'path', 'node', 'system', 'user', 'help', 'menu_test');
protected $state;
protected $config;
public static function getInfo() {
return array(
'name' => 'XML sitemap interface tests',
......
......@@ -16,7 +16,10 @@ class XmlSitemapMenuFunctionalTest extends XmlSitemapTestBase {
protected $normal_user;
protected $menu_items = array();
public static $modules = array('node','xmlsitemap', 'menu_link', 'menu_ui');
public static $modules = array('node', 'xmlsitemap', 'menu_link', 'menu_ui');
protected $state;
protected $config;
protected $entityManager;
public static function getInfo() {
return array(
......@@ -29,6 +32,9 @@ class XmlSitemapMenuFunctionalTest extends XmlSitemapTestBase {
public function setUp() {
parent::setUp();
$this->state = $this->container->get('state');
$this->entityManager = $this->container->get('entity.manager');
$this->config = $this->container->get('config.factory');
if ($this->profile != 'standard') {
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page', 'settings' => array(
// Set proper default options for the page content type.
......@@ -46,16 +52,16 @@ class XmlSitemapMenuFunctionalTest extends XmlSitemapTestBase {
$user_role->grantPermission('access content');
$user_role->save();
$bundles = \Drupal::entityManager()->getAllBundleInfo();
\Drupal::config('xmlsitemap.settings')->set('xmlsitemap_entity_menu_link', TRUE);
\Drupal::config('xmlsitemap.settings')->set('xmlsitemap_entity_menu', TRUE);
$bundles = $this->entityManager->getAllBundleInfo();
$this->config->get('xmlsitemap.settings')->set('xmlsitemap_entity_menu_link', TRUE);
$this->config->get('xmlsitemap.settings')->set('xmlsitemap_entity_menu', TRUE);
foreach ($bundles['menu_link'] as $bundle_id => $bundle) {
\Drupal::config('xmlsitemap.settings')->set('xmlsitemap_entity_menu_link_bundle_' . $bundle_id, TRUE);
$this->config->get('xmlsitemap.settings')->set('xmlsitemap_entity_menu_link_bundle_' . $bundle_id, TRUE);
}
foreach ($bundles['menu'] as $bundle_id => $bundle) {
\Drupal::config('xmlsitemap.settings')->set('xmlsitemap_entity_menu_bundle_' . $bundle_id, TRUE);
$this->config->get('xmlsitemap.settings')->set('xmlsitemap_entity_menu_bundle_' . $bundle_id, TRUE);
}
\Drupal::config('xmlsitemap.settings')->save();
$this->config->get('xmlsitemap.settings')->save();
$this->admin_user = $this->drupalCreateUser(array('administer menu', 'administer xmlsitemap'));
$this->normal_user = $this->drupalCreateUser(array('access content'));
......@@ -72,9 +78,9 @@ class XmlSitemapMenuFunctionalTest extends XmlSitemapTestBase {
);
$this->drupalPostForm('admin/structure/menu/add', $edit, 'Save');
\Drupal::config('xmlsitemap.settings')->set('xmlsitemap_entity_menu_bundle_' . $edit['id'], TRUE);
\Drupal::config('xmlsitemap.settings')->set('xmlsitemap_entity_menu_link_bundle_' . $edit['id'], TRUE);
\Drupal::config('xmlsitemap.settings')->save();
$this->config->get('xmlsitemap.settings')->set('xmlsitemap_entity_menu_bundle_' . $edit['id'], TRUE);
$this->config->get('xmlsitemap.settings')->set('xmlsitemap_entity_menu_link_bundle_' . $edit['id'], TRUE);
$this->config->get('xmlsitemap.settings')->save();
$menu = Menu::load($edit['id']);
......@@ -89,14 +95,14 @@ class XmlSitemapMenuFunctionalTest extends XmlSitemapTestBase {
}
public function tearDown() {
$bundles = \Drupal::entityManager()->getAllBundleInfo();
\Drupal::config('xmlsitemap.settings')->delete('xmlsitemap_entity_menu_link');
\Drupal::config('xmlsitemap.settings')->delete('xmlsitemap_entity_menu');
$bundles = $this->entityManager->getAllBundleInfo();
$this->config->get('xmlsitemap.settings')->delete('xmlsitemap_entity_menu_link');
$this->config->get('xmlsitemap.settings')->delete('xmlsitemap_entity_menu');
foreach ($bundles['menu_link'] as $bundle_id => $bundle) {
\Drupal::config('xmlsitemap.settings')->delete('xmlsitemap_entity_menu_link_bundle_' . $bundle_id);
$this->config->get('xmlsitemap.settings')->delete('xmlsitemap_entity_menu_link_bundle_' . $bundle_id);
}
foreach ($bundles['menu'] as $bundle_id => $bundle) {
\Drupal::config('xmlsitemap.settings')->delete('xmlsitemap_entity_menu_bundle_' . $bundle_id);
$this->config->get('xmlsitemap.settings')->delete('xmlsitemap_entity_menu_bundle_' . $bundle_id);
}
parent::tearDown();
......
......@@ -15,6 +15,7 @@ use Drupal\Core\Language\LanguageInterface;
class XmlSitemapMultilingualNodeTest extends XmlSitemapMultilingualTestBase {
public static $modules = array('xmlsitemap', 'language', 'content_translation', 'node', 'locale', 'config_translation', 'system');
protected $config;
public static function getInfo() {
return array(
......@@ -38,13 +39,14 @@ class XmlSitemapMultilingualNodeTest extends XmlSitemapMultilingualTestBase {
$this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
}
$this->config = $this->container->get('config.factory');
$this->admin_user = $this->drupalCreateUser(array('administer nodes', 'administer languages', 'administer content types', 'access administration pages', 'create page content', 'edit own page content'));
$this->drupalLogin($this->admin_user);
\Drupal::config('xmlsitemap.settings')->set('xmlsitemap_entity_node', 1);
\Drupal::config('xmlsitemap.settings')->set('xmlsitemap_entity_node_bundle_article', 1);
\Drupal::config('xmlsitemap.settings')->set('xmlsitemap_entity_node_bundle_page', 1);
\Drupal::config('xmlsitemap.settings')->save();
$this->config->get('xmlsitemap.settings')->set('xmlsitemap_entity_node', 1);
$this->config->get('xmlsitemap.settings')->set('xmlsitemap_entity_node_bundle_article', 1);
$this->config->get('xmlsitemap.settings')->set('xmlsitemap_entity_node_bundle_page', 1);
$this->config->get('xmlsitemap.settings')->save();
// allow anonymous user to view user profiles
$user_role = entity_load('user_role', DRUPAL_ANONYMOUS_RID);
......
......@@ -15,6 +15,7 @@ use Drupal\Core\Language\LanguageInterface;
class XmlSitemapMultilingualTest extends XmlSitemapMultilingualTestBase {
public static $modules = array('language', 'xmlsitemap', 'node', 'locale', 'content_translation', 'system');
protected $config;
public static function getInfo() {
return array(
......@@ -27,6 +28,7 @@ class XmlSitemapMultilingualTest extends XmlSitemapMultilingualTestBase {
public function setUp() {
parent::setUp();
$this->config = $this->container->get('config.factory');
$this->drupalLogin($this->admin_user);
$edit = array(
'site_default_language' => 'en',
......@@ -49,14 +51,14 @@ class XmlSitemapMultilingualTest extends XmlSitemapMultilingualTestBase {
$link_en = $this->addSitemapLink(array('language' => 'en'));
$link_fr = $this->addSitemapLink(array('language' => 'fr'));
\Drupal::config('xmlsitemap.settings')->set('i18n_selection_mode', 'off')->save();
$this->config->get('xmlsitemap.settings')->set('i18n_selection_mode', 'off')->save();
$this->regenerateSitemap();
$this->drupalGetSitemap(array('language' => 'en'));
$this->assertRawSitemapLinks($node, $node_en, $node_fr, $link, $link_en, $link_fr);
$this->drupalGet('fr/sitemap.xml');
$this->assertRawSitemapLinks($node, $node_en, $node_fr, $link, $link_en, $link_fr);
\Drupal::config('xmlsitemap.settings')->set('i18n_selection_mode', 'simple')->save();
$this->config->get('xmlsitemap.settings')->set('i18n_selection_mode', 'simple')->save();
$this->regenerateSitemap();
$this->drupalGetSitemap(array('language' => 'en'));
$this->assertRawSitemapLinks($node, $node_en, $link, $link_en);
......@@ -65,7 +67,7 @@ class XmlSitemapMultilingualTest extends XmlSitemapMultilingualTestBase {
$this->assertRawSitemapLinks($node, $node_fr, $link, $link_fr);
$this->assertNoRawSitemapLinks($node_en, $link_en);
\Drupal::config('xmlsitemap.settings')->set('i18n_selection_mode', 'mixed')->save();
$this->config->get('xmlsitemap.settings')->set('i18n_selection_mode', 'mixed')->save();
$this->regenerateSitemap();
$this->drupalGetSitemap(array('language' => 'en'));
$this->assertRawSitemapLinks($node, $node_en, $link, $link_en);
......@@ -73,7 +75,7 @@ class XmlSitemapMultilingualTest extends XmlSitemapMultilingualTestBase {
$this->drupalGet('fr/sitemap.xml');
$this->assertRawSitemapLinks($node, $node_en, $node_fr, $link, $link_en, $link_fr);
\Drupal::config('xmlsitemap.settings')->set('i18n_selection_mode', 'default')->save();
$this->config->get('xmlsitemap.settings')->set('i18n_selection_mode', 'default')->save();
$this->regenerateSitemap();
$this->drupalGetSitemap(array('language' => 'en'));
$this->assertRawSitemapLinks($node, $node_en, $link, $link_en);
......@@ -84,7 +86,7 @@ class XmlSitemapMultilingualTest extends XmlSitemapMultilingualTestBase {
// With strict mode, the language neutral node should not be found, but the
// language neutral non-node should be.
\Drupal::config('xmlsitemap.settings')->set('i18n_selection_mode', 'strict')->save();
$this->config->get('xmlsitemap.settings')->set('i18n_selection_mode', 'strict')->save();
$this->regenerateSitemap();
$this->drupalGetSitemap(array('language' => 'en'));
$this->assertRawSitemapLinks($node_en, $link, $link_en);
......
......@@ -17,6 +17,8 @@ abstract class XmlSitemapMultilingualTestBase extends XmlSitemapTestBase {
protected $admin_user;
public static $modules = array('language', 'xmlsitemap', 'node', 'locale', 'content_translation', 'system');
protected $languageManager;
protected $entityManager;
/**
* Set up an administrative user account and testing keys.
......@@ -25,10 +27,12 @@ abstract class XmlSitemapMultilingualTestBase extends XmlSitemapTestBase {
// Call parent::setUp() allowing test cases to pass further modules.
parent::setUp();
$this->languageManager = $this->container->get('language_manager');
$this->entityManager = $this->container->get('entity.manager');
$this->admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'administer site configuration', 'administer xmlsitemap', 'access content'));
$this->drupalLogin($this->admin_user);
if (!\Drupal::languageManager()->getLanguage('fr')) {
if (!$this->languageManager->getLanguage('fr')) {
// Add a new language.
$language = new Language(array(
'id' => 'fr',
......@@ -37,7 +41,7 @@ abstract class XmlSitemapMultilingualTestBase extends XmlSitemapTestBase {
language_save($language);
}
if (!\Drupal::languageManager()->getLanguage('en')) {
if (!$this->languageManager->getLanguage('en')) {
// Add a new language.
$language = new Language(array(
'id' => 'en',
......@@ -51,10 +55,10 @@ abstract class XmlSitemapMultilingualTestBase extends XmlSitemapTestBase {
$previous_sitemap->delete();
}
$sitemap = \Drupal::entityManager()->getStorage('xmlsitemap')->create(array());
$sitemap = $this->entityManager->getStorage('xmlsitemap')->create(array());
$sitemap->context = array('language' => 'en');
xmlsitemap_sitemap_save($sitemap);
$sitemap = \Drupal::entityManager()->getStorage('xmlsitemap')->create(array());
$sitemap = $this->entityManager->getStorage('xmlsitemap')->create(array());
$sitemap->context = array('language' => 'fr');
xmlsitemap_sitemap_save($sitemap);
}
......
......@@ -17,6 +17,7 @@ class XmlSitemapNodeFunctionalTest extends XmlSitemapTestBase {
public static $modules = array('node', 'xmlsitemap');
protected $normal_user;
protected $nodes = array();
protected $config;
public static function getInfo() {
return array(
......@@ -48,10 +49,11 @@ class XmlSitemapNodeFunctionalTest extends XmlSitemapTestBase {
$user_role->grantPermission('access content');
$user_role->save();
\Drupal::config('xmlsitemap.settings')->set('xmlsitemap_entity_node', 1);
\Drupal::config('xmlsitemap.settings')->set('xmlsitemap_entity_node_bundle_article', 1);
\Drupal::config('xmlsitemap.settings')->set('xmlsitemap_entity_node_bundle_page', 1);
\Drupal::config('xmlsitemap.settings')->save();
$this->config = $this->container->get('config.factory');
$this->config->get('xmlsitemap.settings')->set('xmlsitemap_entity_node', 1);
$this->config->get('xmlsitemap.settings')->set('xmlsitemap_entity_node_bundle_article', 1);
$this->config->get('xmlsitemap.settings')->set('xmlsitemap_entity_node_bundle_page', 1);
$this->config->get('xmlsitemap.settings')->save();
xmlsitemap_link_bundle_settings_save('node', 'page', array('status' => 1, 'priority' => 0.6));
}
......@@ -139,7 +141,7 @@ class XmlSitemapNodeFunctionalTest extends XmlSitemapTestBase {
*/
public function testCron() {
$limit = 5;
\Drupal::config('xmlsitemap.settings')->set('batch_limit', $limit)->save();
$this->config->get('xmlsitemap.settings')->set('batch_limit', $limit)->save();
$nodes = array();
for ($i = 1; $i <= ($limit + 1); $i++) {
......
......@@ -17,6 +17,7 @@ class XmlSitemapTaxonomyFunctionalTest extends XmlSitemapTestBase {
public static $modules = array('taxonomy', 'xmlsitemap');
protected $normal_user;
protected $nodes = array();
protected $config;
public static function getInfo() {
return array(
......@@ -29,9 +30,10 @@ class XmlSitemapTaxonomyFunctionalTest extends XmlSitemapTestBase {
public function setUp() {
parent::setUp();
\Drupal::config('xmlsitemap.settings')->set('xmlsitemap_entity_taxonomy_vocabulary', TRUE);
\Drupal::config('xmlsitemap.settings')->set('xmlsitemap_entity_taxonomy_vocabulary_bundle_taxonomy_vocabulary', TRUE);
\Drupal::config('xmlsitemap.settings')->save();
$this->config = $this->container->get('config.factory');
$this->config->get('xmlsitemap.settings')->set('xmlsitemap_entity_taxonomy_vocabulary', TRUE);
$this->config->get('xmlsitemap.settings')->set('xmlsitemap_entity_taxonomy_vocabulary_bundle_taxonomy_vocabulary', TRUE);
$this->config->get('xmlsitemap.settings')->save();
// allow anonymous user to view user profiles
$user_role = entity_load('user_role', DRUPAL_ANONYMOUS_RID);
......
......@@ -16,10 +16,16 @@ abstract class XmlSitemapTestBase extends WebTestBase {
public static $modules = array('xmlsitemap');
protected $admin_user;
protected $state;
protected $config;
protected $moduleHandler;
public function setUp() {
array_unshift(self::$modules, 'xmlsitemap');
parent::setUp();
$this->state = $this->container->get('state');
$this->config = $this->container->get('config.factory');
$this->moduleHandler = $this->container->get('module_handler');
}
public function tearDown() {
......@@ -84,10 +90,10 @@ abstract class XmlSitemapTestBase extends WebTestBase {
* Regenerate the sitemap by setting the regenerate flag and running cron.
*/
protected function regenerateSitemap() {
\Drupal::state()->set('xmlsitemap_regenerate_needed', TRUE);
\Drupal::state()->set('xmlsitemap_generated_last', 0);
$this->state->set('xmlsitemap_regenerate_needed', TRUE);
$this->state->set('xmlsitemap_generated_last', 0);
$this->cronRun();
$this->assertTrue(\Drupal::state()->get('xmlsitemap_generated_last') && !\Drupal::state()->get('xmlsitemap_regenerate_needed'), t('XML sitemaps regenerated and flag cleared.'));
$this->assertTrue($this->state->get('xmlsitemap_generated_last') && !$this->state->get('xmlsitemap_regenerate_needed'), t('XML sitemaps regenerated and flag cleared.'));
}
protected function assertSitemapLink($entity_type, $entity_id = NULL) {
......@@ -202,10 +208,10 @@ abstract class XmlSitemapTestBase extends WebTestBase {
if ($reset_if_true && $value) {
$state_variables = xmlsitemap_state_variables();
if (isset($state_variables[$variable])) {
\Drupal::state()->set($variable, FALSE);
$this->state->set($variable, FALSE);
}
else {
\Drupal::config('xmlsitemap.settings')->set($variable, FALSE)->save();
$this->config->get('xmlsitemap.settings')->set($variable, FALSE)->save();
}
}
......@@ -233,7 +239,7 @@ abstract class XmlSitemapTestBase extends WebTestBase {
protected function getWatchdogMessages(array $conditions = array(), $reset = FALSE) {
static $seen_ids = array();
if (!\Drupal::moduleHandler()->moduleExists('dblog') || $reset) {
if (!$this->moduleHandler->moduleExists('dblog') || $reset) {
$seen_ids = array();
return array();
}
......
......@@ -13,6 +13,8 @@ namespace Drupal\xmlsitemap\Tests;
class XmlSitemapUnitTest extends XmlSitemapTestBase {
public static $modules = array('xmlsitemap', 'node', 'system');
protected $state;
protected $config;
public static function getInfo() {
return array(
......@@ -26,10 +28,12 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
parent::setUp();
$this->admin_user = $this->drupalCreateUser(array('access content', 'administer site configuration', 'administer xmlsitemap'));
$this->state = $this->container->get('state');
$this->config = $this->container->get('config.factory');
}
public function testAssertFlag() {
\Drupal::state()->set('xmlsitemap_rebuild_needed', TRUE);
$this->state->set('xmlsitemap_rebuild_needed', TRUE);
$this->assertTrue(xmlsitemap_var('xmlsitemap_rebuild_needed'));
$this->assertTrue($this->assertFlag('xmlsitemap_rebuild_needed', TRUE, FALSE));
$this->assertTrue(xmlsitemap_var('xmlsitemap_rebuild_needed'));
......@@ -78,7 +82,7 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
*/
public function testGetChunkCount() {
// Set a low chunk size for testing.
\Drupal::config('xmlsitemap.settings')->set('chunk_size', 4)->save();
$this->config->get('xmlsitemap.settings')->set('chunk_size', 4)->save();
// Make the total number of links just equal to the chunk size.
$count = db_query("SELECT COUNT(id) FROM {xmlsitemap}")->fetchField();
......@@ -205,7 +209,7 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
$link1 = $this->addSitemapLink(array('loc' => 'testing1', 'status' => 0));
$link2 = $this->addSitemapLink(array('loc' => 'testing1', 'status' => 1));
$link3 = $this->addSitemapLink(array('status' => 0));
\Drupal::state()->set('xmlsitemap_regenerate_needed', FALSE);
$this->state->set('xmlsitemap_regenerate_needed', FALSE);
// Test delete multiple links.
// Test that the regenerate flag is set when visible links are deleted.
......@@ -231,7 +235,7 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
$links[1] = $this->addSitemapLink(array('subtype' => 'group1'));
$links[2] = $this->addSitemapLink(array('subtype' => 'group1'));
$links[3] = $this->addSitemapLink(array('subtype' => 'group2'));
\Drupal::state()->set('xmlsitemap_regenerate_needed', FALSE);
$this->state->set('xmlsitemap_regenerate_needed', FALSE);
// id | type | subtype | language | access | status | priority
// 1 | testing | group1 | '' | 1 | 1 | 0.5
// 2 | testing | group1 | '' | 1 | 1 | 0.5
......@@ -287,7 +291,7 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
*/
public function testMinimumLifetime() {
$this->drupalLogin($this->admin_user);
\Drupal::config('xmlsitemap.settings')->set('minimum_lifetime', 300)->save();
$this->config->get('xmlsitemap.settings')->set('minimum_lifetime', 300)->save();
$this->regenerateSitemap();
$link = $this->addSitemapLink(array('loc' => 'lifetime-test'));
......@@ -296,7 +300,7 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
$this->assertResponse(200);
$this->assertNoRaw('lifetime-test');
\Drupal::state()->set('xmlsitemap_generated_last', REQUEST_TIME - 400);
$this->state->set('xmlsitemap_generated_last', REQUEST_TIME - 400);
$this->cronRun();
$this->drupalGetSitemap();
$this->assertRaw('lifetime-test');
......
......@@ -15,6 +15,7 @@ class XmlSitemapUserFunctionalTest extends XmlSitemapTestBase {
protected $normal_user;
protected $accounts = array();
public static $modules = array('xmlsitemap', 'user', 'node', 'system');
protected $config;
public static function getInfo() {
return array(
......@@ -26,6 +27,7 @@ class XmlSitemapUserFunctionalTest extends XmlSitemapTestBase {
public function setUp($modules = array()) {
parent::setUp();
$this->config = $this->container->get('config.factory');
// allow anonymous user to view user profiles
$user_role = entity_load('user_role', DRUPAL_ANONYMOUS_RID);
......@@ -33,9 +35,9 @@ class XmlSitemapUserFunctionalTest extends XmlSitemapTestBase {
$user_role->save();
// set xmlsitemap_entity_user state variable to TRUE to add user links into sitemap
\Drupal::config('xmlsitemap.settings')->set('xmlsitemap_entity_user', TRUE);
\Drupal::config('xmlsitemap.settings')->set('xmlsitemap_entity_user_bundle_user', TRUE);
\Drupal::config('xmlsitemap.settings')->save();
$this->config->get('xmlsitemap.settings')->set('xmlsitemap_entity_user', TRUE);
$this->config->get('xmlsitemap.settings')->set('xmlsitemap_entity_user_bundle_user', TRUE);
$this->config->get('xmlsitemap.settings')->save();
// Save the user settings before creating the users.
xmlsitemap_link_bundle_settings_save('user', 'user', array('status' => 0, 'priority' => 0.5));
......
......@@ -16,26 +16,33 @@ class XmlSitemapCustomFunctionalTest extends XmlSitemapTestBase {
public static $modules = array('xmlsitemap_custom', 'path', 'node');
protected $languageManager;
protected $aliasStorage;
public static function getInfo() {
return array(
'name' => 'XML sitemap custom interface tests',
'description' => 'Functional tests for the XML sitemap custom module.',
'group' => 'XML sitemap',
);
}
public function setUp() {
parent::setUp();
$this->languageManager = $this->container->get('language_manager');
$this->aliasStorage = $this->container->get('path.alias_storage');
$this->admin_user = $this->drupalCreateUser(array('access content', 'administer xmlsitemap'));
$this->drupalLogin($this->admin_user);
}
public function testCustomLinks() {
$language = \Drupal::languageManager()->getCurrentLanguage();
$language = $this->languageManager->getCurrentLanguage();
// Set a path alias for the node page.
$alias = array('source' => 'system/files', 'alias' => 'public-files');
\Drupal::service('path.alias_storage')->save('system/files', 'public-files', $language->getId());
$this->aliasStorage->save('system/files', 'public-files', $language->getId());
$this->drupalGet('admin/config/search/xmlsitemap/custom');
$this->clickLink(t('Add custom link'));
......@@ -78,7 +85,7 @@ class XmlSitemapCustomFunctionalTest extends XmlSitemapTestBase {
// Test a valid file.
$edit['loc'] = 'core/misc/drupal.js';
$this->drupalPostForm('admin/config/search/xmlsitemap/custom/add', $edit, t('Save'));
$this->assertText(t('The custom link for @link was saved.',array('@link' => $edit['loc'])));
$this->assertText(t('The custom link for @link was saved.', array('@link' => $edit['loc'])));
$links = xmlsitemap_link_load_multiple(array('type' => 'custom', 'loc' => $edit['loc']));
$this->assertEqual(count($links), 1, t('Custom link saved in the database.'));
......
......@@ -17,6 +17,9 @@ class XmlSitemapEnginesFunctionalTest extends XmlSitemapTestBase {
protected $submit_url;
public static $modules = array('system', 'path', 'node', 'dblog', 'xmlsitemap', 'xmlsitemap_engines', 'xmlsitemap_engines_test');
protected $entityManager;
protected $state;
/**
* {@inheritdoc}
*/
......@@ -33,13 +36,14 @@ class XmlSitemapEnginesFunctionalTest extends XmlSitemapTestBase {
*/
public function setUp() {
parent::setUp();
$this->entityManager = $this->container->get('entity.manager');
$this->state = $this->container->get('state');
$this->admin_user = $this->drupalCreateUser(array('access content', 'administer xmlsitemap'));
$this->drupalLogin($this->admin_user);
// @todo For some reason the test client does not have clean URLs while
// the test runner does, so it causes mismatches in watchdog assertions
// later.
//variable_set('clean_url', 0);
$this->submit_url = url('ping', array('absolute' => TRUE, 'query' => array('sitemap' => ''))) . '[sitemap]';
}
......@@ -47,13 +51,13 @@ class XmlSitemapEnginesFunctionalTest extends XmlSitemapTestBase {
* Check if sitemaps are sent to searching engines
*/
public function submitEngines() {
\Drupal::state()->setMultiple(array(
$this->state->setMultiple(array(
'xmlsitemap_engines_submit_last' => REQUEST_TIME - 10000,
'xmlsitemap_engines_minimum_lifetime' => 0
));
\Drupal::state()->set('xmlsitemap_generated_last', REQUEST_TIME - 100);
$this->state->set('xmlsitemap_generated_last', REQUEST_TIME - 100);
xmlsitemap_engines_cron();
$this->assertTrue(\Drupal::state()->get('xmlsitemap_engines_submit_last') > (REQUEST_TIME - 100), 'Submitted the sitemaps to search engines. {}');
$this->assertTrue($this->state->get('xmlsitemap_engines_submit_last') > (REQUEST_TIME - 100), 'Submitted the sitemaps to search engines. {}');
}
/**
......@@ -73,7 +77,7 @@ class XmlSitemapEnginesFunctionalTest extends XmlSitemapTestBase {
$sitemaps = array();
$context = array(1);
$sitemap = \Drupal::entityManager()->getStorage('xmlsitemap')->create(array(
$sitemap = $this->entityManager->getStorage('xmlsitemap')->create(array(
'id' => xmlsitemap_sitemap_get_context_hash($context),
));
$sitemap->setContext(serialize($context));
......@@ -86,7 +90,7 @@ class XmlSitemapEnginesFunctionalTest extends XmlSitemapTestBase {
$sitemaps[] = $sitemap;
$context = array(2);
$sitemap = \Drupal::entityManager()->getStorage('xmlsitemap')->create(array(
$sitemap = $this->entityManager->getStorage('xmlsitemap')->create(array(
'id' => xmlsitemap_sitemap_get_context_hash($context),
));
$sitemap->setContext(serialize($context));
......@@ -130,12 +134,6 @@ class XmlSitemapEnginesFunctionalTest extends XmlSitemapTestBase {
$this->drupalPostForm('admin/config/search/xmlsitemap/engines', $edit, t('Save configuration'));
$this->assertText(t('The configuration options have been saved.'));
//$this->submitEngines();
//$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Submitted the sitemap to %url and received response @code.', 'variables' => array('%url' => $url, '@code' => '404')));
//$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'No valid sitemap parameter provided.'));
//$this->assertWatchdogMessage(array('type' => 'page not found', 'message' => 'ping'));
$edit = array('xmlsitemap_engines_custom_urls' => $this->submit_url);
$this->drupalPostForm('admin/config/search/xmlsitemap/engines', $edit, t('Save configuration'));
$this->assertText(t('The configuration options have been saved.'));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment