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

Namespace

Unish

Classes

Namesort descending Description
SqlDumpTest Tests for sql-dump commands.

File

tests/sqlDumpTest.php
View source
  1. <?php
  2. namespace Unish;
  3. /**
  4. * Tests for sql-dump commands.
  5. *
  6. * @group commands
  7. * @group sql
  8. * @group slow
  9. */
  10. class SqlDumpTest extends CommandUnishTestCase {
  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->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. // Last 5 entries are for D8+
  26. 'skip-tables-list' => 'hist*,cache*,router,config*,watchdog,key_valu*',
  27. 'yes' => NULL,
  28. );
  29. $site_selection_options = array(
  30. 'root' => $root,
  31. 'uri' => $uri,
  32. );
  33. // Test --extra option
  34. if ($this->db_driver() == 'mysql') {
  35. $this->drush('sql-dump', array(), array_merge($options, $site_selection_options, array('extra' => '--skip-add-drop-table')));
  36. $this->assertFileExists($full_dump_file_path);
  37. $full_dump_file = file_get_contents($full_dump_file_path);
  38. $this->assertNotContains('DROP TABLE IF EXISTS', $full_dump_file);
  39. }
  40. // First, do a test without any aliases, and dump the whole database
  41. $this->drush('sql-dump', array(), array_merge($options, $site_selection_options));
  42. $this->assertFileExists($full_dump_file_path);
  43. $full_dump_file = file_get_contents($full_dump_file_path);
  44. // Test that we have sane contents.
  45. $this->assertContains('queue', $full_dump_file);
  46. // Test skip-files-list and wildcard expansion.
  47. $this->assertNotContains('history', $full_dump_file);
  48. // Next, set up an alias file and run a couple of simulated
  49. // tests to see if options are propagated correctly.
  50. // Control: insure options are not set when not specified
  51. unset($options['skip-tables-list']);
  52. unlink($full_dump_file_path);
  53. $this->drush('sql-dump', array(), array_merge($options, $site_selection_options));
  54. $this->assertFileExists($full_dump_file_path);
  55. $full_dump_file = file_get_contents($full_dump_file_path);
  56. // Test that we have sane contents.
  57. $this->assertContains('queue', $full_dump_file);
  58. // Test skip-files-list and wildcard expansion.
  59. $this->assertContains('history', $full_dump_file);
  60. $aliasPath = UNISH_SANDBOX . '/aliases';
  61. mkdir($aliasPath);
  62. $aliasFile = $aliasPath . '/bar.aliases.drushrc.php';
  63. $aliasContents = <<<EOD
  64. <?php
  65. // Written by Unish. This file is safe to delete.
  66. \$aliases['test'] = array(
  67. 'root' => '$root',
  68. 'uri' => '$uri',
  69. 'site' => 'stage',
  70. 'command-specific' => array(
  71. 'sql-dump' => array(
  72. 'skip-tables-list' => 'hist*,cache*,router,config*,watchdog,key_valu*',
  73. ),
  74. ),
  75. );
  76. EOD;
  77. file_put_contents($aliasFile, $aliasContents);
  78. $options['alias-path'] = $aliasPath;
  79. unlink($full_dump_file_path);
  80. // Now run again with an alias, and test to see if the option is there
  81. $this->drush('sql-dump', array(), array_merge($options), '@test');
  82. $this->assertFileExists($full_dump_file_path);
  83. $full_dump_file = file_get_contents($full_dump_file_path);
  84. // Test that we have sane contents.
  85. $this->assertContains('queue', $full_dump_file);
  86. // Test skip-files-list and wildcard expansion.
  87. $this->assertNotContains('history', $full_dump_file);
  88. // Repeat control test: options not recovered in absence of an alias.
  89. unlink($full_dump_file_path);
  90. $this->drush('sql-dump', array(), array_merge($options, $site_selection_options));
  91. $this->assertFileExists($full_dump_file_path);
  92. $full_dump_file = file_get_contents($full_dump_file_path);
  93. // Test that we have sane contents.
  94. $this->assertContains('queue', $full_dump_file);
  95. // Test skip-files-list and wildcard expansion.
  96. $this->assertContains('history', $full_dump_file);
  97. // Now run yet with @self, and test to see that Drush can recover the option
  98. // --skip-tables-list, defined in @test.
  99. unlink($full_dump_file_path);
  100. $this->drush('sql-dump', array(), array_merge($options, $site_selection_options), '@self');
  101. $this->assertFileExists($full_dump_file_path);
  102. $full_dump_file = file_get_contents($full_dump_file_path);
  103. // Test that we have sane contents.
  104. $this->assertContains('queue', $full_dump_file);
  105. // Test skip-files-list and wildcard expansion.
  106. $this->assertNotContains('history', $full_dump_file);
  107. }
  108. }