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.

Namespace

Unish

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