tmgmt.upgrade.alpha1.test 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /*
  3. * @file
  4. * Contains tests for Translation management
  5. */
  6. /**
  7. * Upgrade tests.
  8. */
  9. class TMGMTUpgradeAlpha1TestCase extends DrupalWebTestCase {
  10. protected $profile = 'testing';
  11. static function getInfo() {
  12. return array(
  13. 'name' => t('Upgrade tests Alpha1'),
  14. 'description' => t('Tests the upgrade path from 7.x-1.0-alpha1'),
  15. 'group' => t('Translation Management'),
  16. );
  17. }
  18. function setUp() {
  19. // Enable all dependencies.
  20. parent::setUp(array('entity', 'views', 'translation', 'locale'));
  21. // Create the tmgmt tables and fill them.
  22. module_load_include('inc', 'tmgmt', 'tests/tmgmt_alpha1_dump.sql');
  23. // @todo: Figure out why this is necessary.
  24. $enabled_modules = db_query("SELECT name FROM {system} where status = 1 and type = 'module'")->fetchCol();
  25. foreach ($enabled_modules as $enabled_module) {
  26. module_load_install($enabled_module);
  27. // Set the schema version to the number of the last update provided
  28. // by the module.
  29. $versions = drupal_get_schema_versions($enabled_module);
  30. $version = $versions ? max($versions) : SCHEMA_INSTALLED;
  31. db_update('system')
  32. ->condition('name', $enabled_module)
  33. ->fields(array('schema_version' => $version))
  34. ->execute();
  35. }
  36. // Set schema version to 0 and then install the tmgmt modules, to simulate
  37. // an enabling.
  38. db_update('system')
  39. ->condition('name', array('tmgmt', 'tmgmt_ui', 'tmgmt_field', 'tmgmt_node', 'tmgmt_test', 'tmgmt_node_ui'))
  40. ->fields(array(
  41. 'schema_version' => 0,
  42. ))
  43. ->execute();
  44. module_enable(array('tmgmt', 'tmgmt_ui', 'tmgmt_field', 'tmgmt_node', 'tmgmt_test', 'tmgmt_node_ui'));
  45. // Log in as a user that can run update.php
  46. $admin = $this->drupalCreateUser(array('administer software updates'));
  47. $this->drupalLogin($admin);
  48. $this->performUpgrade();
  49. }
  50. /**
  51. * Verifies that the data has been migrated properly
  52. */
  53. function testUpgradePath() {
  54. // Log in as a user with enough permissions.
  55. $translator = $this->drupalCreateUser(array('administer tmgmt'));
  56. $this->drupalLogin($translator);
  57. // Go to a job and check the review form.
  58. $this->drupalGet('admin/tmgmt/jobs/1');
  59. // Make sure the #status values have been set accordingly.
  60. $this->assertRaw(t('Accepted: @accepted, reviewed: @reviewed, translated: @translated, pending: @pending.', array('@accepted' => 0, '@reviewed' => 0, '@translated' => 2, '@pending' => 0)));
  61. // Extract the word count field and make sure it's correct.
  62. $word_count = $this->xpath('//td[contains(@class, :class)]', array(':class' => 'views-field-word-count-1'));
  63. $this->assertEqual(6, trim((string)reset($word_count)));
  64. $this->clickLink(t('review'));
  65. // Needs review icon.
  66. $this->assertRaw('tmgmt-ui-icon-yellow tmgmt-ui-state-translated');
  67. // Translated values.
  68. $this->assertRaw('de_Test content');
  69. $this->assertRaw('de_This is the body.');
  70. // Reject button.
  71. $this->assertRaw('✗');
  72. // Check that accepted count has been updated correctly.
  73. $this->drupalGet('admin/tmgmt/jobs/2');
  74. // Make sure the #status values have been set accordingly.
  75. $this->assertRaw(t('Accepted: @accepted, reviewed: @reviewed, translated: @translated, pending: @pending.', array('@accepted' => 2, '@reviewed' => 0, '@translated' => 0, '@pending' => 0)));
  76. }
  77. /**
  78. * Perform the upgrade.
  79. *
  80. * Copied and adapted from UpgradePathTestCase::performUpgrade().
  81. *
  82. * @param $register_errors
  83. * Register the errors during the upgrade process as failures.
  84. * @return
  85. * TRUE if the upgrade succeeded, FALSE otherwise.
  86. */
  87. protected function performUpgrade($register_errors = TRUE) {
  88. $update_url = $GLOBALS['base_url'] . '/update.php';
  89. // Load the first update screen.
  90. $this->drupalGet($update_url, array('external' => TRUE));
  91. if (!$this->assertResponse(200)) {
  92. return FALSE;
  93. }
  94. // Continue.
  95. $this->drupalPost(NULL, array(), t('Continue'));
  96. if (!$this->assertResponse(200)) {
  97. return FALSE;
  98. }
  99. // The test should pass if there are no pending updates.
  100. $content = $this->drupalGetContent();
  101. if (strpos($content, t('No pending updates.')) !== FALSE) {
  102. $this->pass(t('No pending updates and therefore no upgrade process to test.'));
  103. $this->pendingUpdates = FALSE;
  104. return TRUE;
  105. }
  106. // Go!
  107. $this->drupalPost(NULL, array(), t('Apply pending updates'));
  108. if (!$this->assertResponse(200)) {
  109. return FALSE;
  110. }
  111. // Check for errors during the update process.
  112. foreach ($this->xpath('//li[@class=:class]', array(':class' => 'failure')) as $element) {
  113. $message = strip_tags($element->asXML());
  114. $this->upgradeErrors[] = $message;
  115. if ($register_errors) {
  116. $this->fail($message);
  117. }
  118. }
  119. if (!empty($this->upgradeErrors)) {
  120. // Upgrade failed, the installation might be in an inconsistent state,
  121. // don't process.
  122. return FALSE;
  123. }
  124. // Check if there still are pending updates.
  125. $this->drupalGet($update_url, array('external' => TRUE));
  126. $this->drupalPost(NULL, array(), t('Continue'));
  127. if (!$this->assertText(t('No pending updates.'), t('No pending updates at the end of the update process.'))) {
  128. return FALSE;
  129. }
  130. // Clear caches.
  131. $this->checkPermissions(array(), TRUE);
  132. }
  133. }