function EntityViewsMultiValueBaseFieldDataUpdateTest::testUpdateMultiValueBaseFields

Tests multi-value base field views data is updated correctly.

@covers ::needsMultivalueBaseFieldUpdate

File

core/modules/views/tests/src/Functional/Update/EntityViewsMultiValueBaseFieldDataUpdateTest.php, line 34

Class

EntityViewsMultiValueBaseFieldDataUpdateTest
Tests the upgrade path for views multi-value base field data.

Namespace

Drupal\Tests\views\Functional\Update

Code

public function testUpdateMultiValueBaseFields() {
    $this->runUpdates();
    $view = Views::getView('test_user_multi_value');
    $display = $view->storage
        ->get('display');
    // Check each handler type present in the configuration to make sure the
    // field got updated correctly.
    foreach ([
        'fields',
        'filters',
        'arguments',
    ] as $type) {
        $handler_config = $display['default']['display_options'][$type]['roles'];
        // The ID should remain unchanged. Otherwise the update handler could
        // overwrite a separate handler config.
        $this->assertEqual('roles', $handler_config['id']);
        // The field should be updated from 'roles' to the correct column name.
        $this->assertEqual('roles_target_id', $handler_config['field']);
        // Check the table is still correct.
        $this->assertEqual('user__roles', $handler_config['table']);
        // The plugin ID should be updated as well.
        $this->assertEqual($type === 'arguments' ? 'user__roles_rid' : 'user_roles', $handler_config['plugin_id']);
        if ($type === 'filters') {
            // The filter value should have been converted to an array.
            $this->assertTrue(is_array($handler_config['value']));
            // The filter operator should have been mapped from single to multiple.
            $this->assertEquals('or', $handler_config['operator']);
        }
    }
}

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