db backup prior to drupal security update
[yaffs-website] / web / core / modules / comment / tests / src / Kernel / Migrate / MigrateCommentStubTest.php
1 <?php
2
3 namespace Drupal\Tests\comment\Kernel\Migrate;
4
5 use Drupal\comment\Entity\CommentType;
6 use Drupal\migrate\MigrateException;
7 use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
8 use Drupal\migrate_drupal\Tests\StubTestTrait;
9 use Drupal\node\Entity\NodeType;
10
11 /**
12  * Test stub creation for comment entities.
13  *
14  * @group comment
15  */
16 class MigrateCommentStubTest extends MigrateDrupalTestBase {
17
18   use StubTestTrait;
19
20   /**
21    * {@inheritdoc}
22    */
23   public static $modules = ['comment', 'node'];
24
25   /**
26    * {@inheritdoc}
27    */
28   protected function setUp() {
29     parent::setUp();
30     $this->installEntitySchema('comment');
31     $this->installEntitySchema('node');
32     // Make sure uid 0 is created (default uid for comments is 0).
33     $storage = \Drupal::entityManager()->getStorage('user');
34     // Insert a row for the anonymous user.
35     $storage
36       ->create([
37         'uid' => 0,
38         'status' => 0,
39         'name' => '',
40       ])
41       ->save();
42     // Need at least one node type and comment type present.
43     NodeType::create([
44       'type' => 'testnodetype',
45       'name' => 'Test node type',
46     ])->save();
47     CommentType::create([
48       'id' => 'testcommenttype',
49       'label' => 'Test comment type',
50       'target_entity_type_id' => 'node',
51     ])->save();
52   }
53
54   /**
55    * Tests creation of comment stubs.
56    */
57   public function testStub() {
58     try {
59       // We expect an exception, because there's no node to reference.
60       $this->performStubTest('comment');
61       $this->fail('Expected exception has not been thrown.');
62     }
63     catch (MigrateException $e) {
64       $this->assertIdentical($e->getMessage(),
65         'Stubbing failed, unable to generate value for field entity_id');
66     }
67
68     // The stub should pass when there's a node to point to.
69     $this->createStub('node');
70     $this->performStubTest('comment');
71   }
72
73 }