Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / drush / drush / tests / ExpandWildcardTablesUnitTest.php
1 <?php
2
3 namespace Unish;
4
5 use \Drush\Sql\SqlTableSelectionTrait;
6
7 /**
8   * Unit tests for expandWildcardTables() and filterTables().
9   *
10   * @group base
11   * @group sql
12   */
13 class WildcardUnitCase extends \PHPUnit_Framework_TestCase
14 {
15
16     use SqlTableSelectionTrait;
17
18   /**
19    * Tests drush_sql_expand_wildcard_tables().
20    *
21    * @see drush_sql_expand_wildcard_tables().
22    */
23     public function testExpandWildcardTables()
24     {
25         // Array of tables to search for.
26         $wildcard_input = [
27         'cache*',
28         ];
29         // Mock array of tables to test with. This is
30         // also the expected result.
31         $db_tables = [
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 = $this->expandWildcardTables($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     {
57         // Array of tables to search for.
58         $wildcard_input = [
59         'cache',
60         'cache_*',
61         ];
62         // Mock array of tables to test with.
63         $db_tables = [
64         'cache',
65         'cache_bootstrap',
66         'cache_field',
67         'cache_filter',
68         'cache_form',
69         'cache_menu',
70         'cache_page',
71         'cache_path',
72         'cache_update',
73         ];
74         $expected_result = [
75         'cache',
76         ];
77
78         $actual_result = $this->filterTables($wildcard_input, $db_tables);
79         $this->assertEquals($expected_result, $actual_result);
80     }
81 }