Updated Drupal to 8.6. This goes with the following updates because it's possible...
[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  * @group legacy
15  */
16 class EntityViewsDataUpdateTest 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__ . '/../../../../../system/tests/fixtures/update/drupal-8.views-entity-views-data-2455125.php',
25     ];
26   }
27
28   /**
29    * Tests that field plugins are updated properly.
30    */
31   public function testUpdateHookN() {
32     $this->runUpdates();
33
34     // Load and initialize our test view.
35     $view = Views::getView('update_test');
36     $view->initHandlers();
37
38     // Extract the fields from the test view that were updated.
39     /** @var \Drupal\views\Plugin\views\field\EntityField $field */
40     $created = $view->field['created'];
41     /** @var \Drupal\views\Plugin\views\field\EntityField $field */
42     $created_1 = $view->field['created_1'];
43     /** @var \Drupal\views\Plugin\views\field\EntityField $field */
44     $created_2 = $view->field['created_2'];
45
46     // Make sure the plugins were converted from date to field.
47     $this->assertEqual($created->getPluginId(), 'field', 'created has correct plugin_id');
48     $this->assertEqual($created_1->getPluginId(), 'field', 'created has correct plugin_id');
49     $this->assertEqual($created_2->getPluginId(), 'field', 'created has correct plugin_id');
50
51     // Check options on 'created'.
52     $options = $created->options;
53     $this->assertEqual($options['type'], 'timestamp');
54     $this->assertFalse(array_key_exists('date_format', $options));
55     $this->assertFalse(array_key_exists('custom_date_format', $options));
56     $this->assertFalse(array_key_exists('timezone', $options));
57     $this->assertEqual($options['settings']['date_format'], 'long');
58     $this->assertEqual($options['settings']['custom_date_format'], '');
59     $this->assertEqual($options['settings']['timezone'], 'Africa/Abidjan');
60
61     // Check options on 'created'.
62     $options = $created_1->options;
63     $this->assertEqual($options['type'], 'timestamp_ago');
64     $this->assertFalse(array_key_exists('date_format', $options));
65     $this->assertFalse(array_key_exists('custom_date_format', $options));
66     $this->assertFalse(array_key_exists('timezone', $options));
67     $this->assertEqual($options['settings']['future_format'], '@interval');
68     $this->assertEqual($options['settings']['past_format'], '@interval');
69     $this->assertEqual($options['settings']['granularity'], 2);
70
71     // Check options on 'created'.
72     $options = $created_2->options;
73     $this->assertEqual($options['type'], 'timestamp_ago');
74     $this->assertFalse(array_key_exists('date_format', $options));
75     $this->assertFalse(array_key_exists('custom_date_format', $options));
76     $this->assertFalse(array_key_exists('timezone', $options));
77     $this->assertEqual($options['settings']['future_format'], '@interval hence');
78     $this->assertEqual($options['settings']['past_format'], '@interval ago');
79     $this->assertEqual($options['settings']['granularity'], 2);
80   }
81
82 }