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. // First, do a test without any aliases, and dump the whole database
  34. $this->drush('sql-dump', array(), array_merge($options, $site_selection_options));
  35. $this->assertFileExists($full_dump_file_path);
  36. $full_dump_file = file_get_contents($full_dump_file_path);
  37. // Test that we have sane contents.
  38. $this->assertContains('batch', $full_dump_file);
  39. // Test skip-files-list and wildcard expansion.
  40. $this->assertNotContains('history', $full_dump_file);
  41. // Next, set up an alias file and run a couple of simulated
  42. // tests to see if options are propagated correctly.
  43. // Control: insure options are not set when not specified
  44. unset($options['skip-tables-list']);
  45. unlink($full_dump_file_path);
  46. $this->drush('sql-dump', array(), array_merge($options, $site_selection_options));
  47. $this->assertFileExists($full_dump_file_path);
  48. $full_dump_file = file_get_contents($full_dump_file_path);
  49. // Test that we have sane contents.
  50. $this->assertContains('batch', $full_dump_file);
  51. // Test skip-files-list and wildcard expansion.
  52. $this->assertContains('history', $full_dump_file);
  53. $aliasPath = UNISH_SANDBOX . '/aliases';
  54. mkdir($aliasPath);
  55. $aliasFile = $aliasPath . '/bar.aliases.drushrc.php';
  56. $aliasContents = <<<EOD
  57. <?php
  58. // Written by Unish. This file is safe to delete.
  59. \$aliases['test'] = array(
  60. 'root' => '$root',
  61. 'uri' => '$uri',
  62. 'site' => 'stage',
  63. 'command-specific' => array(
  64. 'sql-dump' => array(
  65. 'skip-tables-list' => 'hist*,cache*,router,config*,watchdog,key_valu*',
  66. ),
  67. ),
  68. );
  69. EOD;
  70. file_put_contents($aliasFile, $aliasContents);
  71. $options['alias-path'] = $aliasPath;
  72. unlink($full_dump_file_path);
  73. // Now run again with an alias, and test to see if the option is there
  74. $this->drush('sql-dump', array(), array_merge($options), '@test');
  75. $this->assertFileExists($full_dump_file_path);
  76. $full_dump_file = file_get_contents($full_dump_file_path);
  77. // Test that we have sane contents.
  78. $this->assertContains('batch', $full_dump_file);
  79. // Test skip-files-list and wildcard expansion.
  80. $this->assertNotContains('history', $full_dump_file);
  81. // Repeat control test: options not recovered in absence of an alias.
  82. unlink($full_dump_file_path);
  83. $this->drush('sql-dump', array(), array_merge($options, $site_selection_options));
  84. $this->assertFileExists($full_dump_file_path);
  85. $full_dump_file = file_get_contents($full_dump_file_path);
  86. // Test that we have sane contents.
  87. $this->assertContains('batch', $full_dump_file);
  88. // Test skip-files-list and wildcard expansion.
  89. $this->assertContains('history', $full_dump_file);
  90. // Now run yet with @self, and test to see that Drush can recover the option
  91. // --skip-tables-list, defined in @test.
  92. unlink($full_dump_file_path);
  93. $this->drush('sql-dump', array(), array_merge($options, $site_selection_options), '@self');
  94. $this->assertFileExists($full_dump_file_path);
  95. $full_dump_file = file_get_contents($full_dump_file_path);
  96. // Test that we have sane contents.
  97. $this->assertContains('batch', $full_dump_file);
  98. // Test skip-files-list and wildcard expansion.
  99. $this->assertNotContains('history', $full_dump_file);
  100. }
  101. }