ViewsConfigUpdaterTest.php in Drupal 9
File
core/modules/views/tests/src/Kernel/ViewsConfigUpdaterTest.php
View source
<?php
namespace Drupal\Tests\views\Kernel;
use Drupal\Core\Config\FileStorage;
use Drupal\views\ViewsConfigUpdater;
class ViewsConfigUpdaterTest extends ViewsKernelTestBase {
protected $configUpdater;
protected static $modules = [
'views_config_entity_test',
];
protected function setUp($import_test_views = TRUE) : void {
parent::setUp();
$this->configUpdater = $this->container
->get('class_resolver')
->getInstanceFromDefinition(ViewsConfigUpdater::class);
}
protected function loadTestView($view_id) {
$config_dir = $this
->getModulePath('views') . '/tests/fixtures/update';
$file_storage = new FileStorage($config_dir);
$values = $file_storage
->read($view_id);
$test_view = $this->container
->get('entity_type.manager')
->getStorage('view')
->create($values);
return $test_view;
}
public function testNeedsEntityLinkUrlUpdate() {
$test_view = $this
->loadTestView('views.view.node_link_update_test');
$this->configUpdater
->setDeprecationsEnabled(FALSE);
$needs_update = $this->configUpdater
->needsEntityLinkUrlUpdate($test_view);
$this
->assertTrue($needs_update);
}
public function testNeedsEntityLinkUrlUpdateDeprecation() {
$this
->expectDeprecation('The entity link url update for the "node_link_update_test" view is deprecated in drupal:9.0.0 and is removed from drupal:10.0.0. Module-provided Views configuration should be updated to accommodate the changes described at https://www.drupal.org/node/2857891.');
$test_view = $this
->loadTestView('views.view.node_link_update_test');
$needs_update = $this->configUpdater
->needsEntityLinkUrlUpdate($test_view);
$this
->assertTrue($needs_update);
}
public function testNeedsOperatorUpdateDefaults() {
$test_view = $this
->loadTestView('views.view.test_exposed_filters');
$this->configUpdater
->setDeprecationsEnabled(FALSE);
$needs_update = $this->configUpdater
->needsOperatorDefaultsUpdate($test_view);
$this
->assertTrue($needs_update);
}
public function testNeedsOperatorDefaultsUpdateDeprecation() {
$this
->expectDeprecation('The operator defaults update for the "test_exposed_filters" view is deprecated in drupal:9.0.0 and is removed from drupal:10.0.0. Module-provided Views configuration should be updated to accommodate the changes described at https://www.drupal.org/node/2869168.');
$test_view = $this
->loadTestView('views.view.test_exposed_filters');
$needs_update = $this->configUpdater
->needsOperatorDefaultsUpdate($test_view);
$this
->assertTrue($needs_update);
}
public function testNeedsFieldNamesForMultivalueBaseFieldsUpdate() {
$test_view = $this
->loadTestView('views.view.test_user_multi_value');
$this->configUpdater
->setDeprecationsEnabled(FALSE);
$needs_update = $this->configUpdater
->needsMultivalueBaseFieldUpdate($test_view);
$this
->assertTrue($needs_update);
}
public function testNeedsFieldNamesForMultivalueBaseUpdateFieldsDeprecation() {
$this
->expectDeprecation('The multivalue base field update for the "test_user_multi_value" view is deprecated in drupal:9.0.0 and is removed from drupal:10.0.0. Module-provided Views configuration should be updated to accommodate the changes described at https://www.drupal.org/node/2900684.');
$test_view = $this
->loadTestView('views.view.test_user_multi_value');
$needs_update = $this->configUpdater
->needsMultivalueBaseFieldUpdate($test_view);
$this
->assertTrue($needs_update);
}
public function testUpdateAll() {
$this
->expectDeprecation('The entity link url update for the "node_link_update_test" view is deprecated in drupal:9.0.0 and is removed from drupal:10.0.0. Module-provided Views configuration should be updated to accommodate the changes described at https://www.drupal.org/node/2857891.');
$this
->expectDeprecation('The operator defaults update for the "test_exposed_filters" view is deprecated in drupal:9.0.0 and is removed from drupal:10.0.0. Module-provided Views configuration should be updated to accommodate the changes described at https://www.drupal.org/node/2869168.');
$this
->expectDeprecation('The multivalue base field update for the "test_user_multi_value" view is deprecated in drupal:9.0.0 and is removed from drupal:10.0.0. Module-provided Views configuration should be updated to accommodate the changes described at https://www.drupal.org/node/2900684.');
$view_ids = [
'views.view.node_link_update_test',
'views.view.test_exposed_filters',
'views.view.test_user_multi_value',
];
foreach ($view_ids as $view_id) {
$test_view = $this
->loadTestView($view_id);
$this
->assertTrue($this->configUpdater
->updateAll($test_view), "View {$view_id} should be updated.");
}
}
}