sqlSyncTest.php

  1. 8.0.x tests/sqlSyncTest.php
  2. 6.x tests/sqlSyncTest.php
  3. 7.x tests/sqlSyncTest.php
  4. 4.x tests/sqlSyncTest.php
  5. 5.x tests/sqlSyncTest.php
  6. master tests/sqlSyncTest.php
  • For now we only test sql-sync in simulated mode.

*

  • Future: Using two copies of Drupal, we could test
  • overwriting one site with another.

Classes

Namesort descending Description
sqlSyncTest @group slow @group commands @group sql

File

tests/sqlSyncTest.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * For now we only test sql-sync in simulated mode.
  5. *
  6. * Future: Using two copies of Drupal, we could test
  7. * overwriting one site with another.
  8. */
  9. /**
  10. * @group slow
  11. * @group commands
  12. * @group sql
  13. */
  14. class sqlSyncTest extends Drush_CommandTestCase {
  15. /**
  16. * Covers the following responsibilities.
  17. * - A user created on the source site is copied to the destination site.
  18. * - The email address of the copied user is sanitized on the destination site.
  19. *
  20. * General handling of site aliases will be in sitealiasTest.php.
  21. */
  22. public function testLocalSqlSync() {
  23. if ($this->db_driver() == 'sqlite') {
  24. $this->markTestSkipped('SQL Sync does not apply to SQLite.');
  25. return;
  26. }
  27. $sites = $this->setUpDrupal(2, TRUE);
  28. return $this->localSqlSync();
  29. }
  30. /**
  31. * Do the same test as above, but use Drupal 6 sites instead of Drupal 7.
  32. */
  33. public function testLocalSqlSyncD6() {
  34. if (UNISH_DRUPAL_MAJOR_VERSION != 6) {
  35. $this->markTestSkipped('This test class is designed for Drupal 6.');
  36. return;
  37. }
  38. chdir(UNISH_TMP); // Avoids perm denied Windows error.
  39. $this->setUpBeforeClass();
  40. $sites = $this->setUpDrupal(2, TRUE, '6');
  41. return $this->localSqlSync();
  42. }
  43. public function localSqlSync() {
  44. $dump_dir = UNISH_SANDBOX . "/dump-dir";
  45. if (!is_dir($dump_dir)) {
  46. mkdir($dump_dir);
  47. }
  48. // Create a user in the staging site
  49. $name = 'joe.user';
  50. $mail = "joe.user@myhome.com";
  51. $options = array(
  52. 'root' => $this->webroot(),
  53. 'uri' => 'stage',
  54. 'yes' => NULL,
  55. );
  56. $this->drush('user-create', array($name), $options + array('password' => 'password', 'mail' => $mail));
  57. // Copy stage to dev with --sanitize.
  58. $sync_options = array(
  59. 'sanitize' => NULL,
  60. 'yes' => NULL,
  61. 'dump-dir' => $dump_dir,
  62. // @todo test wildcards expansion from within sql-sync.
  63. // 'skip-tables-list' => 'role_permiss*',
  64. );
  65. $this->drush('sql-sync', array('@stage', '@dev'), $sync_options);
  66. // Confirm that the sample user has the correct email address on the staging site
  67. $this->drush('user-information', array($name), $options + array('pipe' => NULL));
  68. $output = $this->getOutput();
  69. $row = str_getcsv($output);
  70. $uid = $row[1];
  71. $this->assertEquals($mail, $row[2], 'email address is unchanged on source site.');
  72. $this->assertEquals($name, $row[0]);
  73. $options = array(
  74. 'root' => $this->webroot(),
  75. 'uri' => 'dev',
  76. 'yes' => NULL,
  77. );
  78. // Confirm that the sample user's email address has been sanitized on the dev site
  79. $this->drush('user-information', array($name), $options + array('pipe' => NULL));
  80. $output = $this->getOutput();
  81. $row = str_getcsv($output);
  82. $uid = $row[1];
  83. $this->assertEquals("user+$uid@localhost.localdomain", $row[2], 'email address was sanitized on destination site.');
  84. $this->assertEquals($name, $row[0]);
  85. // @todo Confirm that the role_permissions table no longer exists in dev site (i.e. wildcard expansion works in sql-sync).
  86. // $this->drush('sql-query', array('SELECT * FROM role_permission'), $options, NULL, NULL, self::EXIT_ERROR);
  87. // Copy stage to dev with --sanitize and a fixed sanitized email
  88. $sync_options = array(
  89. 'sanitize' => NULL,
  90. 'yes' => NULL,
  91. 'dump-dir' => $dump_dir,
  92. 'sanitize-email' => 'user@mysite.org',
  93. );
  94. $this->drush('sql-sync', array('@stage', '@dev'), $sync_options);
  95. $options = array(
  96. 'root' => $this->webroot(),
  97. 'uri' => 'dev',
  98. 'yes' => NULL,
  99. );
  100. // Confirm that the sample user's email address has been sanitized on the dev site
  101. $this->drush('user-information', array($name), $options + array('pipe' => NULL));
  102. $output = $this->getOutput();
  103. $row = str_getcsv($output);
  104. $uid = $row[1];
  105. $this->assertEquals("user@mysite.org", $row[2], 'email address was sanitized (fixed email) on destination site.');
  106. $this->assertEquals($name, $row[0]);
  107. }
  108. }