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

Classes

Namesort descending Description
sqlSyncTest

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. */
  13. class sqlSyncTest extends Drush_CommandTestCase {
  14. /*
  15. * Covers the following responsibilities.
  16. * - A user created on the source site is copied to the destination site.
  17. * - The email address of the copied user is sanitized on the destination site.
  18. *
  19. * General handling of site aliases will be in sitealiasTest.php.
  20. */
  21. public function testLocalSqlSync() {
  22. if (strpos(UNISH_DB_URL, 'sqlite') !== FALSE) {
  23. $this->markTestSkipped('SQL Sync does not apply to SQLite.');
  24. return;
  25. }
  26. $sites = $this->setUpDrupal(2, TRUE);
  27. return $this->localSqlSync();
  28. }
  29. /**
  30. * Do the same test as above, but use Drupal 6 sites instead of Drupal 7.
  31. */
  32. public function testLocalSqlSyncD6() {
  33. if (UNISH_DRUPAL_MAJOR_VERSION != 6) {
  34. $this->markTestSkipped('This test class is designed for Drupal 6.');
  35. return;
  36. }
  37. chdir(UNISH_TMP); // Avoids perm denied Windows error.
  38. $this->setUpBeforeClass();
  39. $sites = $this->setUpDrupal(2, TRUE, '6');
  40. return $this->localSqlSync();
  41. }
  42. public function localSqlSync() {
  43. $dump_dir = UNISH_SANDBOX . "/dump-dir";
  44. if (!is_dir($dump_dir)) {
  45. mkdir($dump_dir);
  46. }
  47. // Create a user in the staging site
  48. $name = 'joe.user';
  49. $mail = "joe.user@myhome.com";
  50. $options = array(
  51. 'root' => $this->webroot(),
  52. 'uri' => 'stage',
  53. 'yes' => NULL,
  54. );
  55. $this->drush('user-create', array($name), $options + array('password' => 'password', 'mail' => $mail));
  56. // Copy stage to dev with --sanitize
  57. $sync_options = array(
  58. 'sanitize' => NULL,
  59. 'yes' => NULL,
  60. 'dump-dir' => $dump_dir
  61. );
  62. $this->drush('sql-sync', array('@stage', '@dev'), $sync_options);
  63. // Confirm that the sample user has the correct email address on the staging site
  64. $this->drush('user-information', array($name), $options + array('pipe' => NULL));
  65. $output = $this->getOutput();
  66. $row = str_getcsv($output);
  67. $uid = $row[1];
  68. $this->assertEquals($mail, $row[2], 'email address is unchanged on source site.');
  69. $this->assertEquals($name, $row[0]);
  70. $options = array(
  71. 'root' => $this->webroot(),
  72. 'uri' => 'dev',
  73. 'yes' => NULL,
  74. );
  75. // Confirm that the sample user's email address has been sanitized on the dev site
  76. $this->drush('user-information', array($name), $options + array('pipe' => NULL));
  77. $output = $this->getOutput();
  78. $row = str_getcsv($output);
  79. $uid = $row[1];
  80. $this->assertEquals("user+$uid@localhost", $row[2], 'email address was sanitized on destination site.');
  81. $this->assertEquals($name, $row[0]);
  82. // Copy stage to dev with --sanitize and a fixed sanitized email
  83. $sync_options = array(
  84. 'sanitize' => NULL,
  85. 'yes' => NULL,
  86. 'dump-dir' => $dump_dir,
  87. 'sanitize-email' => 'user@localhost',
  88. );
  89. $this->drush('sql-sync', array('@stage', '@dev'), $sync_options);
  90. $options = array(
  91. 'root' => $this->webroot(),
  92. 'uri' => 'dev',
  93. 'yes' => NULL,
  94. );
  95. // Confirm that the sample user's email address has been sanitized on the dev site
  96. $this->drush('user-information', array($name), $options + array('pipe' => NULL));
  97. $output = $this->getOutput();
  98. $row = str_getcsv($output);
  99. $uid = $row[1];
  100. $this->assertEquals("user@localhost", $row[2], 'email address was sanitized (fixed email) on destination site.');
  101. $this->assertEquals($name, $row[0]);
  102. }
  103. }