cc82c827667348f82a299e7d01504a8509a99828
[yaffs-website] / web / core / modules / comment / tests / src / Kernel / Migrate / d7 / MigrateCommentFieldInstanceTest.php
1 <?php
2
3 namespace Drupal\Tests\comment\Kernel\Migrate\d7;
4
5 use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
6 use Drupal\Core\Field\FieldConfigInterface;
7 use Drupal\field\Entity\FieldConfig;
8 use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
9
10 /**
11  * Tests creation of comment reference fields for each comment type defined
12  * in Drupal 7.
13  *
14  * @group comment
15  */
16 class MigrateCommentFieldInstanceTest extends MigrateDrupal7TestBase {
17
18   public static $modules = ['node', 'comment', 'text', 'menu_ui'];
19
20   /**
21    * {@inheritdoc}
22    */
23   protected function setUp() {
24     parent::setUp();
25     $this->installConfig(static::$modules);
26     $this->executeMigrations([
27       'd7_node_type',
28       'd7_comment_type',
29       'd7_comment_field',
30       'd7_comment_field_instance',
31     ]);
32   }
33
34   /**
35    * Asserts a comment field entity.
36    *
37    * @param string $id
38    *   The entity ID.
39    * @param string $field_name
40    *   The field name.
41    * @param string $bundle
42    *   The bundle ID.
43    * @param int $default_mode
44    *   The field's default_mode setting.
45    * @param int $per_page
46    *   The field's per_page setting.
47    * @param bool $anonymous
48    *   The field's anonymous setting.
49    * @param int $form_location
50    *   The field's form_location setting.
51    * @param bool $preview
52    *   The field's preview setting.
53    */
54   protected function assertEntity($id, $field_name, $bundle, $default_mode, $per_page, $anonymous, $form_location, $preview) {
55     $entity = FieldConfig::load($id);
56     $this->assertTrue($entity instanceof FieldConfigInterface);
57     /** @var \Drupal\field\FieldConfigInterface $entity */
58     $this->assertIdentical('node', $entity->getTargetEntityTypeId());
59     $this->assertIdentical('Comments', $entity->label());
60     $this->assertTrue($entity->isRequired());
61     $this->assertIdentical($field_name, $entity->getFieldStorageDefinition()->getName());
62     $this->assertIdentical($bundle, $entity->getTargetBundle());
63     $this->assertTrue($entity->get('default_value')[0]['status']);
64     $this->assertEqual($default_mode, $entity->getSetting('default_mode'));
65     $this->assertIdentical($per_page, $entity->getSetting('per_page'));
66     $this->assertEqual($anonymous, $entity->getSetting('anonymous'));
67     // This assertion fails because 1 !== TRUE. It's extremely strange that
68     // the form_location setting is returning a boolean, but this appears to
69     // be a problem with the entity, not with the migration.
70     // $this->asserIdentical($form_location, $entity->getSetting('form_location'));
71     $this->assertEqual($preview, $entity->getSetting('preview'));
72   }
73
74   /**
75    * Tests the migrated fields.
76    */
77   public function testMigration() {
78     $this->assertEntity('node.page.comment_node_page', 'comment_node_page', 'page', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
79     $this->assertEntity('node.article.comment_node_article', 'comment_node_article', 'article', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
80     $this->assertEntity('node.blog.comment_node_blog', 'comment_node_blog', 'blog', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
81     $this->assertEntity('node.book.comment_node_book', 'comment_node_book', 'book', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
82     $this->assertEntity('node.forum.comment_node_forum', 'comment_node_forum', 'forum', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
83     $this->assertEntity('node.test_content_type.comment_node_test_content_type', 'comment_node_test_content_type', 'test_content_type', TRUE, 30, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
84   }
85
86 }