sqlDumpTest.php

  1. 8.0.x tests/sqlDumpTest.php
  2. 6.x tests/sqlDumpTest.php
  3. 7.x tests/sqlDumpTest.php
  4. master tests/sqlDumpTest.php

Tests for sql-dump commands.

@group commands @group sql @group slow

Classes

Namesort descending Description
SqlDumpTest @file Tests for sql-dump commands.

File

tests/sqlDumpTest.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Tests for sql-dump commands.
  5. *
  6. * @group commands
  7. * @group sql
  8. * @group slow
  9. */
  10. class SqlDumpTest extends Drush_CommandTestCase {
  11. /**
  12. * Test that a dump file is created successfully.
  13. */
  14. function testSqlDump() {
  15. if ($this->db_driver() == 'sqlite') {
  16. $this->markTestSkipped('SQL Dump does not apply to SQLite.');
  17. return;
  18. }
  19. $this->sites = $this->setUpDrupal(1, TRUE);
  20. $root = $this->webroot();
  21. $uri = 'dev';
  22. $full_dump_file_path = UNISH_SANDBOX . DIRECTORY_SEPARATOR . 'full_db.sql';
  23. $options = array(
  24. 'result-file' => $full_dump_file_path,
  25. 'skip-tables-list' => 'role_permiss*',
  26. 'yes' => NULL,
  27. );
  28. $site_selection_options = array(
  29. 'root' => $root,
  30. 'uri' => $uri,
  31. );
  32. // First, do a test without any aliases, and dump the whole database
  33. $this->drush('sql-dump', array(), array_merge($options, $site_selection_options));
  34. $this->assertFileExists($full_dump_file_path);
  35. $full_dump_file = file_get_contents($full_dump_file_path);
  36. // Test that we have sane contents.
  37. $this->assertContains('sequences', $full_dump_file);
  38. // Test skip-files-list and wildcard expansion.
  39. $this->assertNotContains('role_permission', $full_dump_file);
  40. // Next, set up an alias file and run a couple of simulated
  41. // tests to see if options are propagated correctly.
  42. // Control: insure options are not set when not specified
  43. unset($options['skip-tables-list']);
  44. unlink($full_dump_file_path);
  45. $this->drush('sql-dump', array(), array_merge($options, $site_selection_options));
  46. $this->assertFileExists($full_dump_file_path);
  47. $full_dump_file = file_get_contents($full_dump_file_path);
  48. // Test that we have sane contents.
  49. $this->assertContains('sequences', $full_dump_file);
  50. // Test skip-files-list and wildcard expansion.
  51. $this->assertContains('role_permission', $full_dump_file);
  52. $aliasPath = UNISH_SANDBOX . '/aliases';
  53. mkdir($aliasPath);
  54. $aliasFile = $aliasPath . '/bar.aliases.drushrc.php';
  55. $aliasContents = <<<EOD
  56. <?php
  57. // Writtne by Unish. This file is safe to delete.
  58. \$aliases['test'] = array(
  59. 'root' => '$root',
  60. 'uri' => '$uri',
  61. 'site' => 'stage',
  62. 'command-specific' => array(
  63. 'sql-dump' => array(
  64. 'skip-tables-list' => 'role_permiss*',
  65. ),
  66. ),
  67. );
  68. EOD;
  69. file_put_contents($aliasFile, $aliasContents);
  70. $options['alias-path'] = $aliasPath;
  71. unlink($full_dump_file_path);
  72. // Now run again with an alias, and test to see if the option is there
  73. $this->drush('sql-dump', array(), array_merge($options), '@test');
  74. $this->assertFileExists($full_dump_file_path);
  75. $full_dump_file = file_get_contents($full_dump_file_path);
  76. // Test that we have sane contents.
  77. $this->assertContains('sequences', $full_dump_file);
  78. // Test skip-files-list and wildcard expansion.
  79. $this->assertNotContains('role_permission', $full_dump_file);
  80. // Repeat control test: options not recovered in absence of an alias.
  81. unlink($full_dump_file_path);
  82. $this->drush('sql-dump', array(), array_merge($options, $site_selection_options));
  83. $this->assertFileExists($full_dump_file_path);
  84. $full_dump_file = file_get_contents($full_dump_file_path);
  85. // Test that we have sane contents.
  86. $this->assertContains('sequences', $full_dump_file);
  87. // Test skip-files-list and wildcard expansion.
  88. $this->assertContains('role_permission', $full_dump_file);
  89. // Now run yet with @self, and test to see that Drush can recover the option
  90. // --skip-tables-list, defined in @test.
  91. unlink($full_dump_file_path);
  92. $this->drush('sql-dump', array(), array_merge($options, $site_selection_options), '@self');
  93. $this->assertFileExists($full_dump_file_path);
  94. $full_dump_file = file_get_contents($full_dump_file_path);
  95. // Test that we have sane contents.
  96. $this->assertContains('sequences', $full_dump_file);
  97. // Test skip-files-list and wildcard expansion.
  98. $this->assertNotContains('role_permission', $full_dump_file);
  99. }
  100. }