e512f5f5d82edc8b649c83f32d3e739d83acf71e
[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  */
16 class DblogFiltersAndFieldsUpgradeTest extends UpdatePathTestBase {
17
18   /**
19    * {@inheritdoc}
20    */
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',
25     ];
26   }
27
28   /**
29    * Tests that field and filter handlers are updated properly.
30    */
31   public function testDblogUpgradePath() {
32
33     $this->runUpdates();
34
35     $view = Views::getView('dblog_2851293');
36     $data = $view->storage->toArray();
37     $fields = $data['display']['default']['display_options']['fields'];
38
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']);
42
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']);
46
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')));
52     $config_view->save();
53
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'];
59
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']);
63
64     // Now save the view. This trigger dblog_view_presave().
65     $view->save();
66
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'];
71
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']);
75   }
76
77 }