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()
16 class DblogFiltersAndFieldsUpgradeTest extends UpdatePathTestBase {
21 protected function setDatabaseDumpFiles() {
22 $this->databaseDumpFiles = [
23 __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
24 __DIR__ . '/../../../fixtures/update/dblog-2851293.php',
29 * Tests that field and filter handlers are updated properly.
31 public function testDblogUpgradePath() {
35 $view = Views::getView('dblog_2851293');
36 $data = $view->storage->toArray();
37 $fields = $data['display']['default']['display_options']['fields'];
39 // The 'wid' and 'uid' fields should use the standard plugin now.
40 $this->assertEqual('standard', $fields['wid']['plugin_id']);
41 $this->assertEqual('standard', $fields['uid']['plugin_id']);
43 $filters = $data['display']['default']['display_options']['filters'];
44 // The 'type' filter should use the dblog_types plugin now.
45 $this->assertEqual('dblog_types', $filters['type']['plugin_id']);
47 // Now that the view had been converted, try the same approach but using
48 // dblog_view_presave()
49 $config_factory = \Drupal::configFactory();
50 $config_view = $config_factory->getEditable('views.view.dblog_2851293');
51 $config_view->setData(Yaml::decode(file_get_contents('core/modules/dblog/tests/modules/dblog_test_views/test_views/views.view.dblog_2851293.yml')));
54 // Make sure we have a not upgraded view.
55 $view = Views::getView('dblog_2851293');
56 $data = $view->storage->toArray();
57 $fields = $data['display']['default']['display_options']['fields'];
58 $filters = $data['display']['default']['display_options']['filters'];
60 $this->assertEqual('numeric', $fields['wid']['plugin_id']);
61 $this->assertEqual('numeric', $fields['uid']['plugin_id']);
62 $this->assertEqual('in_operator', $filters['type']['plugin_id']);
64 // Now save the view. This trigger dblog_view_presave().
67 // Finally check the same convertion proccess ran.
68 $data = $view->storage->toArray();
69 $fields = $data['display']['default']['display_options']['fields'];
70 $filters = $data['display']['default']['display_options']['filters'];
72 $this->assertEqual('standard', $fields['wid']['plugin_id']);
73 $this->assertEqual('standard', $fields['uid']['plugin_id']);
74 $this->assertEqual('dblog_types', $filters['type']['plugin_id']);