3 namespace Drupal\Tests\views\Functional\Update;
5 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
6 use Drupal\views\Views;
9 * Tests the upgrade path for views field plugins.
11 * @see https://www.drupal.org/node/2455125
15 class EntityViewsDataUpdateTest extends UpdatePathTestBase {
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',
28 * Tests that field plugins are updated properly.
30 public function testUpdateHookN() {
33 // Load and initialize our test view.
34 $view = Views::getView('update_test');
35 $view->initHandlers();
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'];
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');
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');
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);
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);