Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / node / tests / src / Kernel / Migrate / d7 / MigrateNodeTypeTest.php
1 <?php
2
3 namespace Drupal\Tests\node\Kernel\Migrate\d7;
4
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\field\FieldConfigInterface;
7 use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
8 use Drupal\node\Entity\NodeType;
9 use Drupal\node\NodeTypeInterface;
10
11 /**
12  * Upgrade node types to node.type.*.yml.
13  *
14  * @group node
15  */
16 class MigrateNodeTypeTest extends MigrateDrupal7TestBase {
17
18   /**
19    * Modules to enable.
20    *
21    * @var array
22    */
23   public static $modules = ['node', 'text', 'filter', 'menu_ui'];
24
25   /**
26    * {@inheritdoc}
27    */
28   protected function setUp() {
29     parent::setUp();
30     $this->installConfig(['node']);
31     $this->executeMigration('d7_node_type');
32   }
33
34   /**
35    * Tests a single node type.
36    *
37    * @dataProvider testNodeTypeDataProvider
38    *
39    * @param string $id
40    *   The node type ID.
41    * @param string $label
42    *   The expected label.
43    * @param string $description
44    *   The expected node type description.
45    * @param string $help
46    *   The expected help text.
47    */
48   protected function assertEntity($id, $label, $description, $help, $display_submitted, $new_revision, $expected_available_menus, $expected_parent, $body_label = NULL) {
49     /** @var \Drupal\node\NodeTypeInterface $entity */
50     $entity = NodeType::load($id);
51     $this->assertTrue($entity instanceof NodeTypeInterface);
52     $this->assertIdentical($label, $entity->label());
53     $this->assertIdentical($description, $entity->getDescription());
54
55     $this->assertIdentical($help, $entity->getHelp());
56
57     $this->assertIdentical($display_submitted, $entity->displaySubmitted(), 'Submission info is displayed');
58     $this->assertIdentical($new_revision, $entity->isNewRevision(), 'Is a new revision');
59
60     if ($body_label) {
61       /** @var \Drupal\field\FieldConfigInterface $body */
62       $body = FieldConfig::load('node.' . $id . '.body');
63       $this->assertTrue($body instanceof FieldConfigInterface);
64       $this->assertIdentical($body_label, $body->label());
65     }
66
67     $this->assertSame($expected_available_menus, $entity->getThirdPartySetting('menu_ui', 'available_menus'));
68     $this->assertSame($expected_parent, $entity->getThirdPartySetting('menu_ui', 'parent'));
69   }
70
71   /**
72    * Tests Drupal 7 node type to Drupal 8 migration.
73    */
74   public function testNodeType() {
75     $expected_available_menus = ['main-menu'];
76     $expected_parent = 'main-menu:0:';
77
78     $this->assertEntity('article', 'Article', 'Use <em>articles</em> for time-sensitive content like news, press releases or blog posts.', 'Help text for articles', TRUE, FALSE, $expected_available_menus, $expected_parent, "Body");
79     $this->assertEntity('blog', 'Blog entry', 'Use for multi-user blogs. Every user gets a personal blog.', 'Blog away, good sir!', TRUE, FALSE, $expected_available_menus, $expected_parent, 'Body');
80     // book's display_submitted flag is not set, so it will default to TRUE.
81     $this->assertEntity('book', 'Book page', '<em>Books</em> have a built-in hierarchical navigation. Use for handbooks or tutorials.', '', TRUE, TRUE, $expected_available_menus, $expected_parent, "Body");
82     $this->assertEntity('forum', 'Forum topic', 'A <em>forum topic</em> starts a new discussion thread within a forum.', 'No name-calling, no flame wars. Be nice.', TRUE, FALSE, $expected_available_menus, $expected_parent, 'Body');
83     $this->assertEntity('page', 'Basic page', "Use <em>basic pages</em> for your static content, such as an 'About us' page.", 'Help text for basic pages', FALSE, FALSE, $expected_available_menus, $expected_parent, "Body");
84     // This node type does not carry a body field.
85     $expected_available_menus = [
86       'main-menu',
87       'management',
88       'navigation',
89       'user-menu',
90     ];
91     $this->assertEntity('test_content_type', 'Test content type', 'This is the description of the test content type.', 'Help text for test content type', FALSE, TRUE, $expected_available_menus, $expected_parent);
92   }
93
94 }