function ViewsDataTest::testFetchBaseTables

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Unit/ViewsDataTest.php \Drupal\Tests\views\Unit\ViewsDataTest::testFetchBaseTables()
  2. 10 core/modules/views/tests/src/Unit/ViewsDataTest.php \Drupal\Tests\views\Unit\ViewsDataTest::testFetchBaseTables()
  3. 11.x core/modules/views/tests/src/Unit/ViewsDataTest.php \Drupal\Tests\views\Unit\ViewsDataTest::testFetchBaseTables()

Tests the fetchBaseTables() method.

File

core/modules/views/tests/src/Unit/ViewsDataTest.php, line 149

Class

ViewsDataTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21views%21src%21ViewsData.php/class/ViewsData/8.9.x" title="Class to manage and lazy load cached views data." class="local">\Drupal\views\ViewsData</a> @group views

Namespace

Drupal\Tests\views\Unit

Code

public function testFetchBaseTables() {
    $this->setupMockedModuleHandler();
    $data = $this->viewsData
        ->getAll();
    $base_tables = $this->viewsData
        ->fetchBaseTables();
    // Ensure that 'provider' is set for each base table.
    foreach (array_keys($base_tables) as $base_table) {
        $this->assertEquals('views_test_data', $data[$base_table]['table']['provider']);
    }
    // Test the number of tables returned and their order.
    $this->assertCount(6, $base_tables, 'The correct amount of base tables were returned.');
    $base_tables_keys = array_keys($base_tables);
    for ($i = 1; $i < count($base_tables); ++$i) {
        $prev = $base_tables[$base_tables_keys[$i - 1]];
        $current = $base_tables[$base_tables_keys[$i]];
        $this->assertTrue($prev['weight'] <= $current['weight'] && $prev['title'] <= $prev['title'], 'The tables are sorted as expected.');
    }
    // Test the values returned for each base table.
    $defaults = [
        'title' => '',
        'help' => '',
        'weight' => 0,
    ];
    foreach ($base_tables as $base_table => $info) {
        // Merge in default values as in fetchBaseTables().
        $expected = $data[$base_table]['table']['base'] += $defaults;
        foreach ($defaults as $key => $default) {
            $this->assertSame($info[$key], $expected[$key]);
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.