Verified Commit 79925d2c authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3269091 by gambry, yogeshmpawar, jonathanshaw, joachim, alexpott:...

Issue #3269091 by gambry, yogeshmpawar, jonathanshaw, joachim, alexpott: Undocumented behaviour for Schema::findTables() when an underscore is used
parent 708f501c
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -180,7 +180,12 @@ public function tableExists($table) {
   * Finds all tables that are like the specified base table name.
   *
   * @param string $table_expression
   *   An SQL expression, for example "cache_%" (without the quotes).
   *   A case-insensitive pattern against which table names are compared. Both
   *   '_' and '%' are treated like wildcards in MySQL 'LIKE' expressions, where
   *   '_' matches any single character and '%' matches an arbitrary number of
   *   characters (including zero characters). So 'foo%bar' matches table names
   *   like 'foobar', 'fooXBar', 'fooXBaR',  or 'fooXxBar'; whereas 'foo_bar'
   *   matches 'fooXBar' and 'fooXBaR' but not 'fooBar' or 'fooXxxBar'.
   *
   * @return array
   *   Both the keys and the values are the matching tables.
+55 −0
Original line number Diff line number Diff line
@@ -1307,6 +1307,61 @@ public function testFindTables() {
      'test_2_table',
    ];
    $this->assertEquals($expected, $tables, 'Two tables were found.');

    // Check '_' and '%' wildcards.
    $test_schema->createTable('test3table', $table_specification);
    $test_schema->createTable('test4', $table_specification);
    $test_schema->createTable('testTable', $table_specification);
    $test_schema->createTable('test', $table_specification);

    $tables = $test_schema->findTables('test%');
    sort($tables);
    $expected = [
      'test',
      'test3table',
      'test4',
      'testTable',
      'test_1_table',
      'test_2_table',
    ];
    $this->assertEquals($expected, $tables, 'All "test" prefixed tables were found.');

    $tables = $test_schema->findTables('test_%');
    sort($tables);
    $expected = [
      'test3table',
      'test4',
      'testTable',
      'test_1_table',
      'test_2_table',
    ];
    $this->assertEquals($expected, $tables, 'All "/^test..*?/" tables were found.');

    $tables = $test_schema->findTables('test%table');
    sort($tables);
    $expected = [
      'test3table',
      'testTable',
      'test_1_table',
      'test_2_table',
    ];
    $this->assertEquals($expected, $tables, 'All "/^test.*?table/" tables were found.');

    $tables = $test_schema->findTables('test_%table');
    sort($tables);
    $expected = [
      'test3table',
      'test_1_table',
      'test_2_table',
    ];
    $this->assertEquals($expected, $tables, 'All "/^test..*?table/" tables were found.');

    $tables = $test_schema->findTables('test_');
    sort($tables);
    $expected = [
      'test4',
    ];
    $this->assertEquals($expected, $tables, 'All "/^test./" tables were found.');
  }

  /**