2de6568e47e600f74f4281bfd8149cf0389cc963
[yaffs-website] / web / core / modules / views / tests / src / Functional / Update / EntityViewsDataUpdateTest.php
1 <?php
2
3 namespace Drupal\Tests\views\Functional\Update;
4
5 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
6 use Drupal\views\Views;
7
8 /**
9  * Tests the upgrade path for views field plugins.
10  *
11  * @see https://www.drupal.org/node/2455125
12  *
13  * @group Update
14  */
15 class EntityViewsDataUpdateTest extends UpdatePathTestBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   protected function setDatabaseDumpFiles() {
21     $this->databaseDumpFiles = [
22       __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
23       __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.views-entity-views-data-2455125.php',
24     ];
25   }
26
27   /**
28    * Tests that field plugins are updated properly.
29    */
30   public function testUpdateHookN() {
31     $this->runUpdates();
32
33     // Load and initialize our test view.
34     $view = Views::getView('update_test');
35     $view->initHandlers();
36
37     // Extract the fields from the test view that were updated.
38     /** @var \Drupal\views\Plugin\views\field\EntityField $field */
39     $created = $view->field['created'];
40     /** @var \Drupal\views\Plugin\views\field\EntityField $field */
41     $created_1 = $view->field['created_1'];
42     /** @var \Drupal\views\Plugin\views\field\EntityField $field */
43     $created_2 = $view->field['created_2'];
44
45     // Make sure the plugins were converted from date to field.
46     $this->assertEqual($created->getPluginId(), 'field', 'created has correct plugin_id');
47     $this->assertEqual($created_1->getPluginId(), 'field', 'created has correct plugin_id');
48     $this->assertEqual($created_2->getPluginId(), 'field', 'created has correct plugin_id');
49
50     // Check options on 'created'.
51     $options = $created->options;
52     $this->assertEqual($options['type'], 'timestamp');
53     $this->assertFalse(array_key_exists('date_format', $options));
54     $this->assertFalse(array_key_exists('custom_date_format', $options));
55     $this->assertFalse(array_key_exists('timezone', $options));
56     $this->assertEqual($options['settings']['date_format'], 'long');
57     $this->assertEqual($options['settings']['custom_date_format'], '');
58     $this->assertEqual($options['settings']['timezone'], 'Africa/Abidjan');
59
60     // Check options on 'created'.
61     $options = $created_1->options;
62     $this->assertEqual($options['type'], 'timestamp_ago');
63     $this->assertFalse(array_key_exists('date_format', $options));
64     $this->assertFalse(array_key_exists('custom_date_format', $options));
65     $this->assertFalse(array_key_exists('timezone', $options));
66     $this->assertEqual($options['settings']['future_format'], '@interval');
67     $this->assertEqual($options['settings']['past_format'], '@interval');
68     $this->assertEqual($options['settings']['granularity'], 2);
69
70     // Check options on 'created'.
71     $options = $created_2->options;
72     $this->assertEqual($options['type'], 'timestamp_ago');
73     $this->assertFalse(array_key_exists('date_format', $options));
74     $this->assertFalse(array_key_exists('custom_date_format', $options));
75     $this->assertFalse(array_key_exists('timezone', $options));
76     $this->assertEqual($options['settings']['future_format'], '@interval hence');
77     $this->assertEqual($options['settings']['past_format'], '@interval ago');
78     $this->assertEqual($options['settings']['granularity'], 2);
79   }
80
81 }