Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / dblog / tests / src / Functional / Update / DblogFiltersAndFieldsUpgradeTest.php
1 <?php
2
3 namespace Drupal\Tests\dblog\Functional\Update;
4
5 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
6 use Drupal\views\Views;
7 use Drupal\Core\Serialization\Yaml;
8
9 /**
10  * Tests the upgrade path for views field and filter handlers.
11  *
12  * @see dblog_update_8400()
13  *
14  * @group Update
15  * @group legacy
16  */
17 class DblogFiltersAndFieldsUpgradeTest extends UpdatePathTestBase {
18
19   /**
20    * {@inheritdoc}
21    */
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',
26     ];
27   }
28
29   /**
30    * Tests that field and filter handlers are updated properly.
31    */
32   public function testDblogUpgradePath() {
33
34     $this->runUpdates();
35
36     $view = Views::getView('dblog_2851293');
37     $data = $view->storage->toArray();
38     $fields = $data['display']['default']['display_options']['fields'];
39
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']);
43
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']);
47
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')));
53     $config_view->save();
54
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'];
60
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']);
64
65     // Now save the view. This trigger dblog_view_presave().
66     $view->save();
67
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'];
72
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']);
76   }
77
78 }