expandWildcardTablesUnitTest.php

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

Namespace

Unish

Classes

Namesort descending Description
WildcardUnitCase Unit tests for drush_sql_expand_wildcard_tables and drush_sql_filter_tables.

File

tests/expandWildcardTablesUnitTest.php
View source
  1. <?php
  2. namespace Unish;
  3. /**
  4. * Unit tests for drush_sql_expand_wildcard_tables and
  5. * drush_sql_filter_tables.
  6. *
  7. * @group base
  8. * @group sql
  9. */
  10. class WildcardUnitCase extends UnitUnishTestCase {
  11. public static function setUpBeforeClass() {
  12. parent::setUpBeforeClass();
  13. require_once(dirname(__FILE__) . '/../commands/sql/sql.drush.inc');
  14. }
  15. /**
  16. * Tests drush_sql_expand_wildcard_tables().
  17. *
  18. * @see drush_sql_expand_wildcard_tables().
  19. */
  20. public function testExpandWildcardTables() {
  21. // Array of tables to search for.
  22. $wildcard_input = array(
  23. 'cache*',
  24. );
  25. // Mock array of tables to test with. This is
  26. // also the expected result.
  27. $db_tables = array(
  28. 'cache',
  29. 'cache_bootstrap',
  30. 'cache_field',
  31. 'cache_filter',
  32. 'cache_form',
  33. 'cache_menu',
  34. 'cache_page',
  35. 'cache_path',
  36. 'cache_update',
  37. 'example',
  38. );
  39. $expanded_db_tables = drush_sql_expand_wildcard_tables($wildcard_input, $db_tables);
  40. // We expect all but the last table to match.
  41. array_pop($db_tables);
  42. $this->assertEquals($db_tables, $expanded_db_tables);
  43. }
  44. /**
  45. * Tests drush_sql_filter_tables().
  46. *
  47. * @see drush_sql_filter_tables().
  48. */
  49. public function testFilterTables() {
  50. // Array of tables to search for.
  51. $wildcard_input = array(
  52. 'cache',
  53. 'cache_*',
  54. );
  55. // Mock array of tables to test with.
  56. $db_tables = array(
  57. 'cache',
  58. 'cache_bootstrap',
  59. 'cache_field',
  60. 'cache_filter',
  61. 'cache_form',
  62. 'cache_menu',
  63. 'cache_page',
  64. 'cache_path',
  65. 'cache_update',
  66. );
  67. $expected_result = array(
  68. 'cache',
  69. );
  70. $actual_result = drush_sql_filter_tables($wildcard_input, $db_tables);
  71. $this->assertEquals($expected_result, $actual_result);
  72. }
  73. }