View source
<?php
class TMGMTUpgradeAlpha1TestCase extends DrupalWebTestCase {
protected $profile = 'testing';
static function getInfo() {
return array(
'name' => t('Upgrade tests Alpha1'),
'description' => t('Tests the upgrade path from 7.x-1.0-alpha1'),
'group' => t('Translation Management'),
);
}
function setUp() {
parent::setUp(array(
'entity',
'views',
'translation',
'locale',
));
$this
->pass('Test disabled due to https://www.drupal.org/project/drupalci_testbot/issues/2971824.');
return;
module_load_include('inc', 'tmgmt', 'tests/tmgmt_alpha1_dump.sql');
$enabled_modules = db_query("SELECT name FROM {system} where status = 1 and type = 'module'")
->fetchCol();
foreach ($enabled_modules as $enabled_module) {
module_load_install($enabled_module);
$versions = drupal_get_schema_versions($enabled_module);
$version = $versions ? max($versions) : SCHEMA_INSTALLED;
db_update('system')
->condition('name', $enabled_module)
->fields(array(
'schema_version' => $version,
))
->execute();
}
db_update('system')
->condition('name', array(
'tmgmt',
'tmgmt_ui',
'tmgmt_field',
'tmgmt_node',
'tmgmt_test',
'tmgmt_node_ui',
))
->fields(array(
'schema_version' => 0,
))
->execute();
module_enable(array(
'tmgmt',
'tmgmt_ui',
'tmgmt_field',
'tmgmt_node',
'tmgmt_test',
'tmgmt_node_ui',
));
$admin = $this
->drupalCreateUser(array(
'administer software updates',
));
$this
->drupalLogin($admin);
$this
->performUpgrade();
}
function testUpgradePath() {
return;
$translator = $this
->drupalCreateUser(array(
'administer tmgmt',
));
$this
->drupalLogin($translator);
$this
->drupalGet('admin/tmgmt/jobs/1');
$this
->assertRaw(t('Accepted: @accepted, reviewed: @reviewed, translated: @translated, pending: @pending.', array(
'@accepted' => 0,
'@reviewed' => 0,
'@translated' => 2,
'@pending' => 0,
)));
$word_count = $this
->xpath('//td[contains(@class, :class)]', array(
':class' => 'views-field-word-count-1',
));
$this
->assertEqual(6, trim((string) reset($word_count)));
$this
->clickLink(t('review'));
$this
->assertRaw('tmgmt-ui-icon-yellow tmgmt-ui-state-translated');
$this
->assertRaw('de_Test content');
$this
->assertRaw('de_This is the body.');
$this
->assertRaw('✗');
$this
->drupalGet('admin/tmgmt/jobs/2');
$this
->assertRaw(t('Accepted: @accepted, reviewed: @reviewed, translated: @translated, pending: @pending.', array(
'@accepted' => 2,
'@reviewed' => 0,
'@translated' => 0,
'@pending' => 0,
)));
}
protected function performUpgrade($register_errors = TRUE) {
$update_url = $GLOBALS['base_url'] . '/update.php';
$this
->drupalGet($update_url, array(
'external' => TRUE,
));
if (!$this
->assertResponse(200)) {
return FALSE;
}
$this
->drupalPost(NULL, array(), t('Continue'));
if (!$this
->assertResponse(200)) {
return FALSE;
}
$content = $this
->drupalGetContent();
if (strpos($content, t('No pending updates.')) !== FALSE) {
$this
->pass(t('No pending updates and therefore no upgrade process to test.'));
$this->pendingUpdates = FALSE;
return TRUE;
}
$this
->drupalPost(NULL, array(), t('Apply pending updates'));
if (!$this
->assertResponse(200)) {
return FALSE;
}
foreach ($this
->xpath('//li[@class=:class]', array(
':class' => 'failure',
)) as $element) {
$message = strip_tags($element
->asXML());
$this->upgradeErrors[] = $message;
if ($register_errors) {
$this
->fail($message);
}
}
if (!empty($this->upgradeErrors)) {
return FALSE;
}
$this
->drupalGet($update_url, array(
'external' => TRUE,
));
$this
->drupalPost(NULL, array(), t('Continue'));
if (!$this
->assertText(t('No pending updates.'), t('No pending updates at the end of the update process.'))) {
return FALSE;
}
$this
->checkPermissions(array(), TRUE);
}
}