MigrateViewModesTest.php 1.66 KB
Newer Older
1 2
<?php

3
namespace Drupal\Tests\field\Kernel\Migrate\d7;
4 5 6

use Drupal\Core\Entity\Entity\EntityViewMode;
use Drupal\Core\Entity\EntityViewModeInterface;
7
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
8 9 10 11 12 13 14 15

/**
 * Tests migration of D7 view modes.
 *
 * @group field
 */
class MigrateViewModesTest extends MigrateDrupal7TestBase {

16
  public static $modules = ['comment', 'node', 'taxonomy', 'text'];
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this->installEntitySchema('comment');
    $this->installEntitySchema('node');
    $this->executeMigration('d7_view_modes');
  }

  /**
   * Asserts various aspects of a view mode entity.
   *
   * @param string $id
   *   The entity ID.
   * @param string $label
   *   The expected label of the view mode.
   * @param string $entity_type
   *   The expected entity type ID which owns the view mode.
   */
  protected function assertEntity($id, $label, $entity_type) {
    /** @var \Drupal\Core\Entity\EntityViewModeInterface $view_mode */
    $view_mode = EntityViewMode::load($id);
    $this->assertTrue($view_mode instanceof EntityViewModeInterface);
    $this->assertIdentical($label, $view_mode->label());
    $this->assertIdentical($entity_type, $view_mode->getTargetType());
  }

  /**
   * Tests migration of D7 view mode variables to D8 config entities.
   */
  public function testMigration() {
    $this->assertEntity('comment.full', 'Full', 'comment');
    $this->assertEntity('node.teaser', 'Teaser', 'node');
    $this->assertEntity('node.full', 'Full', 'node');
53
    $this->assertEntity('node.custom', 'custom', 'node');
54 55 56 57
    $this->assertEntity('user.full', 'Full', 'user');
  }

}