0a7e9dcc0dd33556051e31fb8a51d5796be6ab09
[yaffs-website] / web / core / modules / field / tests / src / Kernel / Migrate / d7 / MigrateViewModesTest.php
1 <?php
2
3 namespace Drupal\Tests\field\Kernel\Migrate\d7;
4
5 use Drupal\Core\Entity\Entity\EntityViewMode;
6 use Drupal\Core\Entity\EntityViewModeInterface;
7 use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
8
9 /**
10  * Tests migration of D7 view modes.
11  *
12  * @group field
13  */
14 class MigrateViewModesTest extends MigrateDrupal7TestBase {
15
16   public static $modules = ['comment', 'node', 'taxonomy'];
17
18   /**
19    * {@inheritdoc}
20    */
21   protected function setUp() {
22     parent::setUp();
23     $this->installEntitySchema('comment');
24     $this->installEntitySchema('node');
25     $this->executeMigration('d7_view_modes');
26   }
27
28   /**
29    * Asserts various aspects of a view mode entity.
30    *
31    * @param string $id
32    *   The entity ID.
33    * @param string $label
34    *   The expected label of the view mode.
35    * @param string $entity_type
36    *   The expected entity type ID which owns the view mode.
37    */
38   protected function assertEntity($id, $label, $entity_type) {
39     /** @var \Drupal\Core\Entity\EntityViewModeInterface $view_mode */
40     $view_mode = EntityViewMode::load($id);
41     $this->assertTrue($view_mode instanceof EntityViewModeInterface);
42     $this->assertIdentical($label, $view_mode->label());
43     $this->assertIdentical($entity_type, $view_mode->getTargetType());
44   }
45
46   /**
47    * Tests migration of D7 view mode variables to D8 config entities.
48    */
49   public function testMigration() {
50     $this->assertEntity('comment.full', 'Full', 'comment');
51     $this->assertEntity('node.teaser', 'Teaser', 'node');
52     $this->assertEntity('node.full', 'Full', 'node');
53     $this->assertEntity('node.custom', 'custom', 'node');
54     $this->assertEntity('user.full', 'Full', 'user');
55   }
56
57 }