function EntityViewsDataUpdateTest::testUpdateHookN

Tests that field plugins are updated properly.

File

core/modules/views/tests/src/Functional/Update/EntityViewsDataUpdateTest.php, line 31

Class

EntityViewsDataUpdateTest
Tests the upgrade path for views field plugins.

Namespace

Drupal\Tests\views\Functional\Update

Code

public function testUpdateHookN() {
  $this->runUpdates();
  // Load and initialize our test view.
  $view = Views::getView('update_test');
  $view->initHandlers();
  // Extract the fields from the test view that were updated.
  /** @var \Drupal\views\Plugin\views\field\EntityField $field */
  $created = $view->field['created'];
  /** @var \Drupal\views\Plugin\views\field\EntityField $field */
  $created_1 = $view->field['created_1'];
  /** @var \Drupal\views\Plugin\views\field\EntityField $field */
  $created_2 = $view->field['created_2'];
  // Make sure the plugins were converted from date to field.
  $this->assertEqual($created->getPluginId(), 'field', 'created has correct plugin_id');
  $this->assertEqual($created_1->getPluginId(), 'field', 'created has correct plugin_id');
  $this->assertEqual($created_2->getPluginId(), 'field', 'created has correct plugin_id');
  // Check options on 'created'.
  $options = $created->options;
  $this->assertEqual($options['type'], 'timestamp');
  $this->assertFalse(array_key_exists('date_format', $options));
  $this->assertFalse(array_key_exists('custom_date_format', $options));
  $this->assertFalse(array_key_exists('timezone', $options));
  $this->assertEqual($options['settings']['date_format'], 'long');
  $this->assertEqual($options['settings']['custom_date_format'], '');
  $this->assertEqual($options['settings']['timezone'], 'Africa/Abidjan');
  // Check options on 'created'.
  $options = $created_1->options;
  $this->assertEqual($options['type'], 'timestamp_ago');
  $this->assertFalse(array_key_exists('date_format', $options));
  $this->assertFalse(array_key_exists('custom_date_format', $options));
  $this->assertFalse(array_key_exists('timezone', $options));
  $this->assertEqual($options['settings']['future_format'], '@interval');
  $this->assertEqual($options['settings']['past_format'], '@interval');
  $this->assertEqual($options['settings']['granularity'], 2);
  // Check options on 'created'.
  $options = $created_2->options;
  $this->assertEqual($options['type'], 'timestamp_ago');
  $this->assertFalse(array_key_exists('date_format', $options));
  $this->assertFalse(array_key_exists('custom_date_format', $options));
  $this->assertFalse(array_key_exists('timezone', $options));
  $this->assertEqual($options['settings']['future_format'], '@interval hence');
  $this->assertEqual($options['settings']['past_format'], '@interval ago');
  $this->assertEqual($options['settings']['granularity'], 2);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.