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. public function localSqlSync() {
  32. // Create a user in the staging site
  33. $name = 'joe.user';
  34. $mail = "joe.user@myhome.com";
  35. $options = array(
  36. 'root' => $this->webroot(),
  37. 'uri' => 'stage',
  38. 'yes' => NULL,
  39. );
  40. $this->drush('user-create', array($name), $options + array('password' => 'password', 'mail' => $mail));
  41. // Copy stage to dev with --sanitize.
  42. $sync_options = array(
  43. 'sanitize' => NULL,
  44. 'yes' => NULL,
  45. // Test wildcards expansion from within sql-sync. Also avoid D8 persisten entity cache.
  46. 'structure-tables-list' => 'cache,cache*',
  47. );
  48. $this->drush('sql-sync', array('@stage', '@dev'), $sync_options);
  49. // Confirm that the sample user has the correct email address on the staging site
  50. $this->drush('user-information', array($name), $options + array('pipe' => NULL));
  51. $output = $this->getOutput();
  52. $row = str_getcsv($output);
  53. $uid = $row[1];
  54. $this->assertEquals($mail, $row[2], 'email address is unchanged on source site.');
  55. $this->assertEquals($name, $row[0]);
  56. $options = array(
  57. 'root' => $this->webroot(),
  58. 'uri' => 'dev',
  59. 'yes' => NULL,
  60. );
  61. // Confirm that the sample user's email address has been sanitized on the dev site
  62. $this->drush('user-information', array($name), $options + array('pipe' => NULL));
  63. $output = $this->getOutput();
  64. $row = str_getcsv($output);
  65. $uid = $row[1];
  66. $this->assertEquals("user+$uid@localhost.localdomain", $row[2], 'email address was sanitized on destination site.');
  67. $this->assertEquals($name, $row[0]);
  68. // @todo Confirm that the role_permissions table no longer exists in dev site (i.e. wildcard expansion works in sql-sync).
  69. // $this->drush('sql-query', array('SELECT * FROM role_permission'), $options, NULL, NULL, self::EXIT_ERROR);
  70. // Copy stage to dev with --sanitize and a fixed sanitized email
  71. $sync_options = array(
  72. 'sanitize' => NULL,
  73. 'yes' => NULL,
  74. 'sanitize-email' => 'user@mysite.org',
  75. // Test wildcards expansion from within sql-sync. Also avoid D8 persistent entity cache.
  76. 'structure-tables-list' => 'cache,cache*',
  77. );
  78. $this->drush('sql-sync', array('@stage', '@dev'), $sync_options);
  79. $options = array(
  80. 'root' => $this->webroot(),
  81. 'uri' => 'dev',
  82. 'yes' => NULL,
  83. );
  84. // Confirm that the sample user's email address has been sanitized on the dev site
  85. $this->drush('user-information', array($name), $options + array('pipe' => NULL));
  86. $output = $this->getOutput();
  87. $row = str_getcsv($output);
  88. $uid = $row[1];
  89. $this->assertEquals("user@mysite.org", $row[2], 'email address was sanitized (fixed email) on destination site.');
  90. $this->assertEquals($name, $row[0]);
  91. }
  92. }