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