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
16 class EntityViewsDataUpdateTest extends UpdatePathTestBase {
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',
29 * Tests that field plugins are updated properly.
31 public function testUpdateHookN() {
34 // Load and initialize our test view.
35 $view = Views::getView('update_test');
36 $view->initHandlers();
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'];
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');
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');
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);
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);