You are here

public function TaxonomyTermUpdatePathTest::testPublishingStatusUpdateForTaxonomyTermViews in Drupal 8

Tests handling of the publishing status in taxonomy term views updates.

See also

taxonomy_post_update_handle_publishing_status_addition_in_views()

File

core/modules/taxonomy/tests/src/Functional/Update/TaxonomyTermUpdatePathTest.php, line 117

Class

TaxonomyTermUpdatePathTest
Tests the upgrade path for taxonomy terms.

Namespace

Drupal\Tests\taxonomy\Functional\Update

Code

public function testPublishingStatusUpdateForTaxonomyTermViews() {

  // Check that the test view was previously using the
  // 'content_translation_status' field.
  $config = \Drupal::config('views.view.test_taxonomy_term_view_with_content_translation_status');
  $display_options = $config
    ->get('display.default.display_options');
  $this
    ->assertEquals('content_translation_status', $display_options['fields']['content_translation_status']['field']);
  $this
    ->assertEquals('content_translation_status', $display_options['filters']['content_translation_status']['field']);
  $this
    ->assertEquals('content_translation_status', $display_options['sorts']['content_translation_status']['field']);

  // Check a test view without any filter.
  $config = \Drupal::config('views.view.test_taxonomy_term_view_without_content_translation_status');
  $display_options = $config
    ->get('display.default.display_options');
  $this
    ->assertEmpty($display_options['filters']);
  $this
    ->runUpdates();

  // Check that a view which had a field, filter and a sort on the
  // 'content_translation_status' field has been updated to use the new
  // 'status' field.
  $view = View::load('test_taxonomy_term_view_with_content_translation_status');
  foreach ($view
    ->get('display') as $display) {
    $this
      ->assertEquals('status', $display['display_options']['fields']['content_translation_status']['field']);
    $this
      ->assertEquals('status', $display['display_options']['sorts']['content_translation_status']['field']);
    $this
      ->assertEquals('status', $display['display_options']['filters']['content_translation_status']['field']);
  }

  // Check that a view without any filters has been updated to include a
  // filter for the 'status' field.
  $view = View::load('test_taxonomy_term_view_without_content_translation_status');
  foreach ($view
    ->get('display') as $display) {
    $this
      ->assertNotEmpty($display['display_options']['filters']);
    $this
      ->assertEquals('status', $display['display_options']['filters']['status']['field']);
  }
}