3 namespace Drupal\Tests\dblog\Functional\Update;
5 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
6 use Drupal\views\Views;
7 use Drupal\Core\Serialization\Yaml;
10 * Tests the upgrade path for views field and filter handlers.
12 * @see dblog_update_8400()
17 class DblogFiltersAndFieldsUpgradeTest extends UpdatePathTestBase {
22 protected function setDatabaseDumpFiles() {
23 $this->databaseDumpFiles = [
24 __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
25 __DIR__ . '/../../../fixtures/update/dblog-2851293.php',
30 * Tests that field and filter handlers are updated properly.
32 public function testDblogUpgradePath() {
36 $view = Views::getView('dblog_2851293');
37 $data = $view->storage->toArray();
38 $fields = $data['display']['default']['display_options']['fields'];
40 // The 'wid' and 'uid' fields should use the standard plugin now.
41 $this->assertEqual('standard', $fields['wid']['plugin_id']);
42 $this->assertEqual('standard', $fields['uid']['plugin_id']);
44 $filters = $data['display']['default']['display_options']['filters'];
45 // The 'type' filter should use the dblog_types plugin now.
46 $this->assertEqual('dblog_types', $filters['type']['plugin_id']);
48 // Now that the view had been converted, try the same approach but using
49 // dblog_view_presave()
50 $config_factory = \Drupal::configFactory();
51 $config_view = $config_factory->getEditable('views.view.dblog_2851293');
52 $config_view->setData(Yaml::decode(file_get_contents('core/modules/dblog/tests/modules/dblog_test_views/test_views/views.view.dblog_2851293.yml')));
55 // Make sure we have a not upgraded view.
56 $view = Views::getView('dblog_2851293');
57 $data = $view->storage->toArray();
58 $fields = $data['display']['default']['display_options']['fields'];
59 $filters = $data['display']['default']['display_options']['filters'];
61 $this->assertEqual('numeric', $fields['wid']['plugin_id']);
62 $this->assertEqual('numeric', $fields['uid']['plugin_id']);
63 $this->assertEqual('in_operator', $filters['type']['plugin_id']);
65 // Now save the view. This trigger dblog_view_presave().
68 // Finally check the same conversion process ran.
69 $data = $view->storage->toArray();
70 $fields = $data['display']['default']['display_options']['fields'];
71 $filters = $data['display']['default']['display_options']['filters'];
73 $this->assertEqual('standard', $fields['wid']['plugin_id']);
74 $this->assertEqual('standard', $fields['uid']['plugin_id']);
75 $this->assertEqual('dblog_types', $filters['type']['plugin_id']);