Commit 115b40c9 authored by catch's avatar catch

Issue #2134951 by xjm: Remove upgrade path tests.

parent 217d9713
<?php
/**
* @file
* Definition of Drupal\contact\Tests\ContactUpgradePathTest.
*/
namespace Drupal\contact\Tests;
use Drupal\system\Tests\Upgrade\UpgradePathTestBase;
/**
* Tests upgrade of contact.
*/
class ContactUpgradePathTest extends UpgradePathTestBase {
public static function getInfo() {
return array(
'name' => 'Contact upgrade test',
'description' => 'Tests upgrade of contact to the configuration system.',
'group' => 'Contact',
);
}
public function setUp() {
$this->databaseDumpFiles = array(
drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.bare.standard_all.database.php.gz',
drupal_get_path('module', 'contact') . '/tests/drupal-7.contact.database.php',
);
parent::setUp();
}
/**
* Tests upgrade of contact table to configuration entities.
*/
public function testContactUpgrade() {
$default_contact_category = db_query('SELECT cid FROM {contact} WHERE selected = 1')->fetchField();
$this->assertTrue(db_table_exists('contact'), 'Contact table exists.');
$this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
// Test that the contact form is available.
$this->assertFalse(db_table_exists('contact'), 'Contact table has been deleted.');
$this->drupalGet('contact');
$this->assertText(t('Your e-mail address'));
// Ensure that the Drupal 7 default contact category has been created.
$contact_category = entity_load('contact_category', '1');
$this->assertTrue(isset($contact_category->uuid), 'Converted contact category has a UUID');
$this->assertEqual($contact_category->label, 'Website feedback');
$this->assertEqual($contact_category->reply, '');
$this->assertEqual($contact_category->weight, 0);
$this->assertEqual($contact_category->recipients, array('admin@example.com'));
// Test that the custom contact category has been updated.
$contact_category = entity_load('contact_category', '2');
$this->assertTrue(isset($contact_category->uuid), 'Converted contact category has a UUID');
$this->assertEqual($contact_category->label, 'Upgrade test');
$this->assertEqual($contact_category->reply, 'Test reply');
$this->assertEqual($contact_category->weight, 1);
$this->assertEqual($contact_category->recipients, array('test1@example.com', 'test2@example.com'));
// Ensure that the default category has been maintained.
$this->assertEqual(\Drupal::config('contact.settings')->get('default_category'), $default_contact_category, 'Default category upgraded.');
// Check that no default config imported on upgrade.
$this->assertFalse(entity_load('contact_category', 'feedback'));
}
}
<?php
/**
* @file
* Contains \Drupal\rdf\Tests\RdfMappingUpgradePathTest.
*/
namespace Drupal\rdf\Tests;
use Drupal\system\Tests\Upgrade\UpgradePathTestBase;
/**
* Tests the upgrade path of RDF mappings.
*/
class RdfMappingUpgradePathTest extends UpgradePathTestBase {
public static function getInfo() {
return array(
'name' => 'RDF mapping upgrade test',
'description' => 'Upgrade tests with RDF mapping data.',
'group' => 'RDF',
);
}
public function setUp() {
// Path to the database dump files.
$this->databaseDumpFiles = array(
drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.bare.standard_all.database.php.gz',
drupal_get_path('module', 'rdf') . '/tests/drupal-7.rdf.database.php',
);
parent::setUp();
}
/**
* Tests to see if RDF mappings were upgraded.
*/
public function testRdfMappingUpgrade() {
$this->assertTrue(db_table_exists('rdf_mapping'), 'RDF mapping table exists.');
$this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
$this->_testUnalteredMappingUpgrade();
$this->_testAlteredMappingUpgrade();
$this->_testReverseRelationUpgrade();
}
/**
* Helper function to test upgrade of unaltered mappings.
*/
protected function _testUnalteredMappingUpgrade() {
$config = rdf_get_mapping('node', 'page');
// Test bundle mapping.
$mapping = $config->getBundleMapping();
$expected_mapping = array(
'types' => array('foaf:Document'),
);
$this->assertEqual($mapping, $expected_mapping, 'Unaltered bundle mapping upgraded correctly.');
// Test field mapping - property.
$mapping = $config->getFieldMapping('title');
$expected_mapping = array(
'properties' => array('dc:title'),
);
$this->assertEqual($mapping, $expected_mapping, 'Unaltered field mapping upgraded correctly.');
// Test field mapping - property with datatype and callback.
$mapping = $config->getFieldMapping('created');
$expected_mapping = array(
'properties' => array('dc:date', 'dc:created'),
'datatype' => 'xsd:dateTime',
'datatype_callback' => array('callable' => 'date_iso8601'),
);
$this->assertEqual($mapping, $expected_mapping, 'Unaltered field mapping with datatype and datatype callback upgraded correctly.');
// Test field mapping - rel.
$mapping = $config->getFieldMapping('uid');
$expected_mapping = array(
'properties' => array('sioc:has_creator'),
'mapping_type' => 'rel',
);
$this->assertEqual($mapping, $expected_mapping, 'Unaltered field mapping with rel mapping type upgraded correctly.');
}
/**
* Helper function to test upgrade of altered mappings.
*/
protected function _testAlteredMappingUpgrade() {
$config = rdf_get_mapping('node', 'article');
// Test bundle mapping.
$mapping = $config->getBundleMapping();
$expected_mapping = array(
'types' => array('foo:Type'),
);
$this->assertEqual($mapping, $expected_mapping, 'Overriden bundle mapping upgraded correctly.');
// Test field mapping.
$mapping = $config->getFieldMapping('field_image');
$expected_mapping = array(
'properties' => array('foo:image'),
);
$this->assertEqual($expected_mapping, $mapping, 'Overriden field mapping is upgraded correctly.');
// Test field mapping.
$mapping = $config->getFieldMapping('changed');
$expected_mapping = array();
$this->assertEqual($expected_mapping, $mapping, 'Empty field mapping from overriden mapping is upgraded correctly.');
}
/**
* Helper function to test handling of deprecated reverse relation mappings.
*/
protected function _testReverseRelationUpgrade() {
// Test field mapping - rev.
$config = rdf_get_mapping('node', 'rev_test');
$mapping = $config->getFieldMapping('field_rev');
$expected_mapping = array();
$this->assertEqual($mapping, $expected_mapping, 'Reverse relation mapping has been dropped.');
}
}
<?php
/**
* @file
* Contains \Drupal\search\Tests\SearchUpgradePathTest.
*/
namespace Drupal\search\Tests;
use Drupal\system\Tests\Upgrade\UpgradePathTestBase;
/**
* Tests the upgrade path of search configuration and tables.
*/
class SearchUpgradePathTest extends UpgradePathTestBase {
public static function getInfo() {
return array(
'name' => 'Search module upgrade test',
'description' => 'Upgrade tests for search module configuration and tables.',
'group' => 'Search',
);
}
public function setUp() {
// Path to the database dump files.
$this->databaseDumpFiles = array(
drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.bare.standard_all.database.php.gz',
drupal_get_path('module', 'search') . '/tests/upgrade/drupal-7.search.database.php',
);
parent::setUp();
}
/**
* Tests to see if search configuration and tables were upgraded.
*/
public function testSearchUpgrade() {
$this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
$this->assertFalse(db_table_exists('search_node_links'), 'search_node_links table was dropped.');
$config = \Drupal::config('search.settings');
// The starting database has user module as the only active search.
$this->assertEqual($config->get('active_plugins'), array('user_search' => 'user_search'));
$exists = db_query('SELECT 1 FROM {variable} WHERE name = :name', array(':name' => 'search_active_modules'))->fetchField();
$this->assertFalse($exists, 'The search_active_modules variable was deleted by the update');
// The starting database has user module as the default.
$this->assertEqual($config->get('default_plugin'), 'user_search');
}
}
<?php
/**
* @file
* Contains \Drupal\system\Tests\Upgrade\ActionUpgradePathTest.
*/
namespace Drupal\system\Tests\Upgrade;
/**
* Tests the upgrade path of actions.
*/
class ActionUpgradePathTest extends UpgradePathTestBase {
public static function getInfo() {
return array(
'name' => 'Action upgrade test',
'description' => 'Upgrade tests with action data.',
'group' => 'Upgrade path',
);
}
public function setUp() {
// Path to the database dump files.
$this->databaseDumpFiles = array(
drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.bare.minimal.database.php.gz',
);
parent::setUp();
}
/**
* Tests to see if actions were upgrade.
*/
public function testActionUpgrade() {
$this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
$this->drupalGet('admin/people');
$elements = $this->xpath('//select[@name="action"]/option');
$this->assertTrue(!empty($elements), 'The user actions were upgraded.');
}
}
<?php
/**
* @file
* Contains \Drupal\system\Tests\Upgrade\BareMinimalAnonymousUpgradePathTest.
*/
namespace Drupal\system\Tests\Upgrade;
/**
* Tests the upgrade path without prior creation of config directions.
*/
class BareMinimalAnonymousUpgradePathTest extends BareMinimalUpgradePathTest {
public static function getInfo() {
return array(
'name' => 'Basic minimal profile upgrade, free access',
'description' => 'Basic upgrade path tests for a minimal profile install with a bare database and update_free_access set to TRUE.',
'group' => 'Upgrade path',
);
}
/**
* Overrides \Drupal\system\Tests\Upgrade\UpgradePathTestBase::setUp().
*/
public function setUp() {
parent::setUp();
// Override $update_free_access in settings.php to allow the anonymous user
// to run updates.
$settings['settings'] = array(
'update_free_access' => (object) array(
'value' => TRUE,
'required' => TRUE,
),
'install_profile' => (object) array(
'value' => $this->profile,
'required' => TRUE,
),
);
$this->writeSettings($settings);
}
/**
* Overrides \Drupal\system\Tests\Upgrade\UpgradePathTestBase::prepareD8Session().
*/
protected function prepareD8Session() {
// There is no active session, so nothing needs to be done here.
}
/**
* Overrides \Drupal\system\Tests\Upgrade\UpgradePathTestBase::assertSessionKept().
*/
protected function finishUpgradeSession() {
// There is no active session, so nothing needs to be done here.
}
}
<?php
/**
* @file
* Contains \Drupal\system\Tests\Upgrade\BareMinimalNoConfigUpgradePathTest.
*/
namespace Drupal\system\Tests\Upgrade;
/**
* Tests the database upgrade path without creating config directories.
*/
class BareMinimalNoConfigUpgradePathTest extends BareMinimalUpgradePathTest {
/**
* The installation profile used in the upgrade test.
*/
protected $profile = 'minimal';
public static function getInfo() {
return array(
'name' => 'Basic minimal profile upgrade, no config',
'description' => 'Basic upgrade path tests for a minimal profile install with a bare database and config directory not pre-created.',
'group' => 'Upgrade path',
);
}
/**
* Overrides \Drupal\system\Tests\Upgrade\UpgradePathTestBase::setUp().
*/
public function setUp() {
parent::setUp();
// Override $conf_path and $config_directories in settings.php.
$settings['conf_path'] = (object) array(
'value' => $this->public_files_directory,
'required' => TRUE,
);
$settings['config_directories'] = (object) array(
'value' => array(),
'required' => TRUE,
);
$settings['settings'] = array(
'install_profile' => (object) array(
'value' => $this->profile,
'required' => TRUE,
),
);
$this->writeSettings($settings);
}
/**
* Overrides \Drupal\system\Tests\Upgrade\UpgradePathTestBase::refreshVariables().
*/
protected function refreshVariables() {
// Refresh the variables only if the site was already upgraded.
if ($this->upgradedSite) {
// update.php puts the new, randomized config directries in this file.
include $this->public_files_directory . '/settings.php';
$GLOBALS['config_directories'] = array();
foreach ($config_directories as $type => $data) {
// update.php runs as the child site, so writes the paths relative to
// that "$conf_path/files", but here, we're running as the parent site,
// so need to make the paths relative to our "conf_path()/files".
//
// Example:
// - Parent site conf_path(): 'sites/default'
// - Child site $conf_path: 'sites/default/files/simpletest/123456'
// - Child site $data['path']: 'config_xyz'
// - Desired result: 'simpletest/123456/files/config_xyz'
//
// @see config_get_config_directory()
$GLOBALS['config_directories'][$type]['path'] = substr($conf_path, strlen(conf_path() . '/files/')) . '/files/' . $data['path'];
}
parent::refreshVariables();
}
}
}
<?php
/**
* @file
* Contains \Drupal\system\Tests\Upgrade\BareMinimalUpgradePathTest.
*/
namespace Drupal\system\Tests\Upgrade;
use Drupal\Core\Session\UserSession;
/**
* Performs major version release upgrade tests on a bare database.
*
* Loads an installation of Drupal 7.x and runs the upgrade process on it.
*
* The install contains the minimal profile modules (without any generated
* content) so that an upgrade from of a site under this profile may be tested.
*/
class BareMinimalUpgradePathTest extends UpgradePathTestBase {
public static function getInfo() {
return array(
'name' => 'Basic minimal profile upgrade path, bare database',
'description' => 'Basic upgrade path tests for a minimal profile install with a bare database.',
'group' => 'Upgrade path',
);
}
public function setUp() {
// Path to the database dump files.
$this->databaseDumpFiles = array(
drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.bare.minimal.database.php.gz',
);
parent::setUp();
}
/**
* Tests a successful major version release upgrade.
*/
public function testBasicMinimalUpgrade() {
$this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
// Hit the frontpage.
$this->drupalGet('');
$this->assertResponse(200);
// Verify that we are still logged in.
$this->finishUpgradeSession();
$user = new UserSession(array(
'uid' => 1,
'name' => 'admin',
'pass_raw' => 'drupal',
));
$this->drupalLogin($user);
// The previous login should've triggered a password rehash, so login one
// more time to make sure the new hash is readable.
$this->drupalLogout();
$this->drupalLogin($user);
// Test that the site name is correctly displayed.
$this->assertText('drupal', 'The site name is correctly displayed.');
// Verify that the main admin sections are available.
$this->drupalGet('admin');
$this->assertText(t('Content'));
$this->assertText(t('Appearance'));
$this->assertText(t('People'));
$this->assertText(t('Configuration'));
$this->assertText(t('Reports'));
$this->assertText(t('Structure'));
$this->assertText(t('Extend'));
// Confirm that no {menu_links} entry exists for user/autocomplete.
$result = db_query('SELECT COUNT(*) FROM {menu_links} WHERE link_path = :user_autocomplete', array(':user_autocomplete' => 'user/autocomplete'))->fetchField();
$this->assertFalse($result, 'No {menu_links} entry exists for user/autocomplete');
// Verify that all required modules are enabled.
$enabled = $this->container->get('module_handler')->getModuleList();
$required = array_filter(system_rebuild_module_data(), function ($data) {
return !empty($data->info['required']);
});
$this->assertEqual(array_diff_key($required, $enabled), array());
// Verify that image.module was correctly installed.
$this->assertEqual('thumbnail', \Drupal::config('image.style.thumbnail')->get('name'));
// Make sure that the default mail configuration has been converted.
$this->assertEqual(array('default' => 'Drupal\Core\Mail\PhpMail'), \Drupal::config('system.mail')->get('interface'), 'Default mail configuration set.');
}
/**
* Asserts that the session was kept during update. Also, log out.
*/
protected function finishUpgradeSession() {
$this->drupalGet('user');
$this->clickLink(t('Edit'));
$this->assertEqual($this->getUrl(), url('user/1/edit', array('absolute' => TRUE)), 'We are still logged in as admin at the end of the upgrade.');
$this->drupalLogout();
}
}
<?php
/**
* @file
* Definition of Drupal\system\Tests\Upgrade\BareStandardUpgradePathTest.
*/
namespace Drupal\system\Tests\Upgrade;
use Drupal\Core\Session\UserSession;
/**
* Performs major version release upgrade tests on a bare database.
*
* Loads an installation of Drupal 7.x and runs the upgrade process on it.
*
* The install contains the standard profile (plus all optional) modules
* without any content so that an update from any of the modules under this
* profile installation can be wholly tested.
*/
class BareStandardUpgradePathTest extends UpgradePathTestBase {
public static function getInfo() {
return array(
'name' => 'Basic standard + all profile upgrade path, bare database',
'description' => 'Basic upgrade path tests for a standard profile install with all enabled modules and a bare database.',
'group' => 'Upgrade path',
);
}
public function setUp() {
// Path to the database dump files.
$this->databaseDumpFiles = array(
drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.bare.standard_all.database.php.gz',
);
parent::setUp();
}
/**
* Tests a successful major version release upgrade.
*/
public function testBasicStandardUpgrade() {
$this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
// Hit the frontpage.
$this->drupalGet('');
$this->assertResponse(200);
// Verify that we are still logged in.
$this->drupalGet('user');
$this->clickLink(t('Edit'));
$this->assertEqual($this->getUrl(), url('user/1/edit', array('absolute' => TRUE)), 'We are still logged in as admin at the end of the upgrade.');
// Logout and verify that we can login back in with our initial password.
$this->drupalLogout();
$user = new UserSession(array(
'uid' => 1,
'name' => 'admin',
'pass_raw' => 'drupal',
));
$this->drupalLogin($user);
// The previous login should've triggered a password rehash, so login one
// more time to make sure the new hash is readable.
$this->drupalLogout();
$this->drupalLogin($user);
// Test that the site name is correctly displayed.
$this->assertText('drupal', 'The site name is correctly displayed.');
// Verify that the main admin sections are available.
$this->drupalGet('admin');
$this->assertText(t('Content'));
$this->assertText(t('Appearance'));
$this->assertText(t('People'));
$this->assertText(t('Configuration'));
$this->assertText(t('Reports'));
$this->assertText(t('Structure'));
$this->assertText(t('Extend'));
// Confirm that no {menu_links} entry exists for user/autocomplete.
$result = db_query('SELECT COUNT(*) FROM {menu_links} WHERE link_path = :user_autocomplete', array(':user_autocomplete' => 'user/autocomplete'))->fetchField();
$this->assertFalse($result, 'No {menu_links} entry exists for user/autocomplete');
// Verify that the blog node type has been assigned to node module.
$blog_type = node_type_load('blog');
$this->assertEqual($blog_type->module, 'node', "Content type 'blog' has been reassigned from the blog module to the node module.");
$this->assertEqual($blog_type->base, 'node_content', "The base string used to construct callbacks corresponding to content type 'Blog' has been reassigned to 'node_content'.");
}
}
<?php
/**
* @file
* Definition of Drupal\system\Tests\Upgrade\BlockUpgradePathTest.
*/
namespace Drupal\system\Tests\Upgrade;
/**
* Tests upgrading a bare database.
*
* Loads a bare installation of Drupal 7 and runs the upgrade process on it.
*/
class BlockUpgradePathTest extends UpgradePathTestBase {
public static function getInfo() {
return array(
'name' => 'Block upgrade test',
'description' => 'Upgrade tests with block data.',
'group' => 'Upgrade path',
);
}
public function setUp() {
$this->databaseDumpFiles = array(
drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.bare.minimal.database.php.gz',
);
parent::setUp();
}
/**
* Tests block title length after successful upgrade.
*/
public function testBlockUpgradeTitleLength() {
$this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
// WebTestBase::drupalPlaceBlock() uses the API directly, which doesn't
// output validation errors or success messages, so create the blocks from
// the UI.
// Add a block instance with a 255-character title.
// Confirm that the custom block has been created, and title matches input.
$settings = array(
'settings[label]' => $this->randomName(255),
'id' => strtolower($this->randomName(8)),
'region' => 'sidebar_first',
);
$this->drupalPostForm('admin/structure/block/add/system_powered_by_block/' . \Drupal::config('system.theme')->get('default'), $settings, t('Save block'));
$this->assertText($settings['settings[label]'], 'Block with title longer than 64 characters successfully created.');
// Try to add a block with a title over 255 characters.
$settings = array(
'settings[label]' => $this->randomName(256),
'id' => strtolower($this->randomName(8)),
'region' => 'sidebar_first',