Commit cff36515 authored by andrei.dincu's avatar andrei.dincu
Browse files

Issue #2249723 by andrei.dincu: Stop using ->container in tests

parent 3f896dea
......@@ -28,8 +28,8 @@ class XmlSitemapFunctionalTest extends XmlSitemapTestBase {
parent::setUp();
$this->admin_user = $this->drupalCreateUser(array('access content', 'administer site configuration', 'administer xmlsitemap', 'access administration pages', 'access site reports', 'administer permissions', 'view the administration theme'));
$this->state = $this->container->get('state');
$this->config = $this->container->get('config.factory');
$this->state = \Drupal::state();
$this->config = \Drupal::configFactory()->get('xmlsitemap.settings');
}
/**
......@@ -82,6 +82,8 @@ class XmlSitemapFunctionalTest extends XmlSitemapTestBase {
$this->drupalLogin($this->admin_user);
$this->state->set('xmlsitemap_generated_last', REQUEST_TIME);
$this->state->set('xmlsitemap_rebuild_needed', TRUE);
$this->drupalGet('admin/config/search/xmlsitemap/rebuild');
$this->assertText("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->assertXMLSitemapProblems(t('The XML sitemap data is out of sync and needs to be completely rebuilt.'));
$this->clickLink(t('completely rebuilt'));
$this->assertResponse(200);
......@@ -89,7 +91,7 @@ class XmlSitemapFunctionalTest extends XmlSitemapTestBase {
$this->assertNoXMLSitemapProblems();
//Test the regenerate flag (and cron hasn't run in a while).
$this->state->set('xmlsitemap_regenerate_needed', TRUE);
$this->state->set('xmlsitemap_generated_last', REQUEST_TIME - $this->config->get('xmlsitemap.settings')->get('cron_threshold_warning') - 100);
$this->state->set('xmlsitemap_generated_last', REQUEST_TIME - $this->config->get('cron_threshold_warning') - 100);
$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);
......
......@@ -32,9 +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');
$this->state = \Drupal::state();
$this->entityManager = \Drupal::entityManager();
$this->config = \Drupal::configFactory()->get('xmlsitemap.settings');
if ($this->profile != 'standard') {
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page', 'settings' => array(
// Set proper default options for the page content type.
......@@ -53,15 +53,15 @@ class XmlSitemapMenuFunctionalTest extends XmlSitemapTestBase {
$user_role->save();
$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);
$this->config->set('xmlsitemap_entity_menu_link', TRUE);
$this->config->set('xmlsitemap_entity_menu', TRUE);
foreach ($bundles['menu_link'] as $bundle_id => $bundle) {
$this->config->get('xmlsitemap.settings')->set('xmlsitemap_entity_menu_link_bundle_' . $bundle_id, TRUE);
$this->config->set('xmlsitemap_entity_menu_link_bundle_' . $bundle_id, TRUE);
}
foreach ($bundles['menu'] as $bundle_id => $bundle) {
$this->config->get('xmlsitemap.settings')->set('xmlsitemap_entity_menu_bundle_' . $bundle_id, TRUE);
$this->config->set('xmlsitemap_entity_menu_bundle_' . $bundle_id, TRUE);
}
$this->config->get('xmlsitemap.settings')->save();
$this->config->save();
$this->admin_user = $this->drupalCreateUser(array('administer menu', 'administer xmlsitemap'));
$this->normal_user = $this->drupalCreateUser(array('access content'));
......@@ -78,9 +78,9 @@ class XmlSitemapMenuFunctionalTest extends XmlSitemapTestBase {
);
$this->drupalPostForm('admin/structure/menu/add', $edit, '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();
$this->config->set('xmlsitemap_entity_menu_bundle_' . $edit['id'], TRUE);
$this->config->set('xmlsitemap_entity_menu_link_bundle_' . $edit['id'], TRUE);
$this->config->save();
$menu = Menu::load($edit['id']);
......@@ -96,13 +96,13 @@ class XmlSitemapMenuFunctionalTest extends XmlSitemapTestBase {
public function tearDown() {
$bundles = $this->entityManager->getAllBundleInfo();
$this->config->get('xmlsitemap.settings')->delete('xmlsitemap_entity_menu_link');
$this->config->get('xmlsitemap.settings')->delete('xmlsitemap_entity_menu');
$this->config->delete('xmlsitemap_entity_menu_link');
$this->config->delete('xmlsitemap_entity_menu');
foreach ($bundles['menu_link'] as $bundle_id => $bundle) {
$this->config->get('xmlsitemap.settings')->delete('xmlsitemap_entity_menu_link_bundle_' . $bundle_id);
$this->config->delete('xmlsitemap_entity_menu_link_bundle_' . $bundle_id);
}
foreach ($bundles['menu'] as $bundle_id => $bundle) {
$this->config->get('xmlsitemap.settings')->delete('xmlsitemap_entity_menu_bundle_' . $bundle_id);
$this->config->delete('xmlsitemap_entity_menu_bundle_' . $bundle_id);
}
parent::tearDown();
......
......@@ -39,14 +39,14 @@ class XmlSitemapMultilingualNodeTest extends XmlSitemapMultilingualTestBase {
$this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
}
$this->config = $this->container->get('config.factory');
$this->config = \Drupal::configFactory()->get('xmlsitemap.settings');
$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);
$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();
$this->config->set('xmlsitemap_entity_node', 1);
$this->config->set('xmlsitemap_entity_node_bundle_article', 1);
$this->config->set('xmlsitemap_entity_node_bundle_page', 1);
$this->config->save();
// allow anonymous user to view user profiles
$user_role = entity_load('user_role', DRUPAL_ANONYMOUS_RID);
......
......@@ -28,7 +28,7 @@ class XmlSitemapMultilingualTest extends XmlSitemapMultilingualTestBase {
public function setUp() {
parent::setUp();
$this->config = $this->container->get('config.factory');
$this->config = \Drupal::configFactory()->get('xmlsitemap.settings');
$this->drupalLogin($this->admin_user);
$edit = array(
'site_default_language' => 'en',
......@@ -51,14 +51,14 @@ class XmlSitemapMultilingualTest extends XmlSitemapMultilingualTestBase {
$link_en = $this->addSitemapLink(array('language' => 'en'));
$link_fr = $this->addSitemapLink(array('language' => 'fr'));
$this->config->get('xmlsitemap.settings')->set('i18n_selection_mode', 'off')->save();
$this->config->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);
$this->config->get('xmlsitemap.settings')->set('i18n_selection_mode', 'simple')->save();
$this->config->set('i18n_selection_mode', 'simple')->save();
$this->regenerateSitemap();
$this->drupalGetSitemap(array('language' => 'en'));
$this->assertRawSitemapLinks($node, $node_en, $link, $link_en);
......@@ -67,7 +67,7 @@ class XmlSitemapMultilingualTest extends XmlSitemapMultilingualTestBase {
$this->assertRawSitemapLinks($node, $node_fr, $link, $link_fr);
$this->assertNoRawSitemapLinks($node_en, $link_en);
$this->config->get('xmlsitemap.settings')->set('i18n_selection_mode', 'mixed')->save();
$this->config->set('i18n_selection_mode', 'mixed')->save();
$this->regenerateSitemap();
$this->drupalGetSitemap(array('language' => 'en'));
$this->assertRawSitemapLinks($node, $node_en, $link, $link_en);
......@@ -75,7 +75,7 @@ class XmlSitemapMultilingualTest extends XmlSitemapMultilingualTestBase {
$this->drupalGet('fr/sitemap.xml');
$this->assertRawSitemapLinks($node, $node_en, $node_fr, $link, $link_en, $link_fr);
$this->config->get('xmlsitemap.settings')->set('i18n_selection_mode', 'default')->save();
$this->config->set('i18n_selection_mode', 'default')->save();
$this->regenerateSitemap();
$this->drupalGetSitemap(array('language' => 'en'));
$this->assertRawSitemapLinks($node, $node_en, $link, $link_en);
......@@ -86,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.
$this->config->get('xmlsitemap.settings')->set('i18n_selection_mode', 'strict')->save();
$this->config->set('i18n_selection_mode', 'strict')->save();
$this->regenerateSitemap();
$this->drupalGetSitemap(array('language' => 'en'));
$this->assertRawSitemapLinks($node_en, $link, $link_en);
......
......@@ -27,8 +27,8 @@ 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->languageManager = \Drupal::languageManager();
$this->entityManager = \Drupal::entityManager();
$this->admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'administer site configuration', 'administer xmlsitemap', 'access content'));
$this->drupalLogin($this->admin_user);
......
......@@ -49,11 +49,11 @@ class XmlSitemapNodeFunctionalTest extends XmlSitemapTestBase {
$user_role->grantPermission('access content');
$user_role->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();
$this->config = \Drupal::configFactory()->get('xmlsitemap.settings');
$this->config->set('xmlsitemap_entity_node', 1);
$this->config->set('xmlsitemap_entity_node_bundle_article', 1);
$this->config->set('xmlsitemap_entity_node_bundle_page', 1);
$this->config->save();
xmlsitemap_link_bundle_settings_save('node', 'page', array('status' => 1, 'priority' => 0.6));
}
......@@ -141,7 +141,7 @@ class XmlSitemapNodeFunctionalTest extends XmlSitemapTestBase {
*/
public function testCron() {
$limit = 5;
$this->config->get('xmlsitemap.settings')->set('batch_limit', $limit)->save();
$this->config->set('batch_limit', $limit)->save();
$nodes = array();
for ($i = 1; $i <= ($limit + 1); $i++) {
......
......@@ -30,10 +30,10 @@ class XmlSitemapTaxonomyFunctionalTest extends XmlSitemapTestBase {
public function setUp() {
parent::setUp();
$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();
$this->config = \Drupal::configFactory()->get('xmlsitemap.settings');
$this->config->set('xmlsitemap_entity_taxonomy_vocabulary', TRUE);
$this->config->set('xmlsitemap_entity_taxonomy_vocabulary_bundle_taxonomy_vocabulary', TRUE);
$this->config->save();
// allow anonymous user to view user profiles
$user_role = entity_load('user_role', DRUPAL_ANONYMOUS_RID);
......
......@@ -23,9 +23,9 @@ abstract class XmlSitemapTestBase extends WebTestBase {
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');
$this->state = \Drupal::state();
$this->config = \Drupal::configFactory()->get('xmlsitemap.settings');
$this->moduleHandler = \Drupal::moduleHandler();
}
public function tearDown() {
......@@ -211,7 +211,7 @@ abstract class XmlSitemapTestBase extends WebTestBase {
$this->state->set($variable, FALSE);
}
else {
$this->config->get('xmlsitemap.settings')->set($variable, FALSE)->save();
$this->config->set($variable, FALSE)->save();
}
}
......
......@@ -28,8 +28,8 @@ 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');
$this->state = \Drupal::state();
$this->config = \Drupal::configFactory()->get('xmlsitemap.settings');
}
public function testAssertFlag() {
......@@ -82,7 +82,7 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
*/
public function testGetChunkCount() {
// Set a low chunk size for testing.
$this->config->get('xmlsitemap.settings')->set('chunk_size', 4)->save();
$this->config->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();
......@@ -291,7 +291,7 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
*/
public function testMinimumLifetime() {
$this->drupalLogin($this->admin_user);
$this->config->get('xmlsitemap.settings')->set('minimum_lifetime', 300)->save();
$this->config->set('minimum_lifetime', 300)->save();
$this->regenerateSitemap();
$link = $this->addSitemapLink(array('loc' => 'lifetime-test'));
......
......@@ -27,7 +27,7 @@ class XmlSitemapUserFunctionalTest extends XmlSitemapTestBase {
public function setUp($modules = array()) {
parent::setUp();
$this->config = $this->container->get('config.factory');
$this->config = \Drupal::configFactory()->get('xmlsitemap.settings');
// allow anonymous user to view user profiles
$user_role = entity_load('user_role', DRUPAL_ANONYMOUS_RID);
......@@ -35,9 +35,9 @@ class XmlSitemapUserFunctionalTest extends XmlSitemapTestBase {
$user_role->save();
// set xmlsitemap_entity_user state variable to TRUE to add user links into sitemap
$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();
$this->config->set('xmlsitemap_entity_user', TRUE);
$this->config->set('xmlsitemap_entity_user_bundle_user', TRUE);
$this->config->save();
// Save the user settings before creating the users.
xmlsitemap_link_bundle_settings_save('user', 'user', array('status' => 0, 'priority' => 0.5));
......
......@@ -32,8 +32,8 @@ class XmlSitemapCustomFunctionalTest extends XmlSitemapTestBase {
public function setUp() {
parent::setUp();
$this->languageManager = $this->container->get('language_manager');
$this->aliasStorage = $this->container->get('path.alias_storage');
$this->languageManager = \Drupal::languageManager();
$this->aliasStorage = \Drupal::service('path.alias_storage');
$this->admin_user = $this->drupalCreateUser(array('access content', 'administer xmlsitemap'));
$this->drupalLogin($this->admin_user);
}
......
......@@ -36,8 +36,8 @@ class XmlSitemapEnginesFunctionalTest extends XmlSitemapTestBase {
*/
public function setUp() {
parent::setUp();
$this->entityManager = $this->container->get('entity.manager');
$this->state = $this->container->get('state');
$this->entityManager = \Drupal::entityManager();
$this->state = \Drupal::state();
$this->admin_user = $this->drupalCreateUser(array('access content', 'administer xmlsitemap'));
$this->drupalLogin($this->admin_user);
......
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