function MigrateCommentTypeTest::testNoCommentTypeMigration

Same name in this branch
  1. 9 core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTypeTest.php \Drupal\Tests\comment\Kernel\Migrate\d6\MigrateCommentTypeTest::testNoCommentTypeMigration()
Same name and namespace in other branches
  1. 10 core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTypeTest.php \Drupal\Tests\comment\Kernel\Migrate\d6\MigrateCommentTypeTest::testNoCommentTypeMigration()
  2. 10 core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTypeTest.php \Drupal\Tests\comment\Kernel\Migrate\d7\MigrateCommentTypeTest::testNoCommentTypeMigration()
  3. 11.x core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTypeTest.php \Drupal\Tests\comment\Kernel\Migrate\d6\MigrateCommentTypeTest::testNoCommentTypeMigration()
  4. 11.x core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTypeTest.php \Drupal\Tests\comment\Kernel\Migrate\d7\MigrateCommentTypeTest::testNoCommentTypeMigration()

Tests comment type migration without node or / and comment on source.

Usually, MigrateDumpAlterInterface::migrateDumpAlter() should be used when the source fixture needs to be changed in a Migrate kernel test, but that would end in three additional tests and an extra overhead in maintenance.

@dataProvider providerTestNoCommentTypeMigration

Parameters

string[] $disabled_source_modules: List of the modules to disable in the source Drupal database.

string[][] $expected_messages: List of the expected migration messages, keyed by the message type. Message type should be "status" "warning" or "error".

File

core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTypeTest.php, line 81

Class

MigrateCommentTypeTest
Tests the migration of comment types from Drupal 7.

Namespace

Drupal\Tests\comment\Kernel\Migrate\d7

Code

public function testNoCommentTypeMigration(array $disabled_source_modules, array $expected_messages) {
    if (!empty($disabled_source_modules)) {
        $this->sourceDatabase
            ->update('system')
            ->condition('name', $disabled_source_modules, 'IN')
            ->fields([
            'status' => 0,
        ])
            ->execute();
    }
    $this->startCollectingMessages();
    $this->migrateCommentTypes();
    $expected_messages += [
        'status' => [],
        'warning' => [],
        'error' => [],
    ];
    $actual_messages = $this->migrateMessages + [
        'status' => [],
        'warning' => [],
        'error' => [],
    ];
    foreach ($expected_messages as $type => $expected_messages_by_type) {
        $this->assertSameSize($expected_messages_by_type, $actual_messages[$type]);
        // Cast the actual messages to string.
        $actual_messages_by_type = array_reduce($actual_messages[$type], function (array $carry, $actual_message) {
            $carry[] = (string) $actual_message;
            return $carry;
        }, []);
        $missing_expected_messages_by_type = array_diff($expected_messages_by_type, $actual_messages_by_type);
        $unexpected_messages_by_type = array_diff($actual_messages_by_type, $expected_messages_by_type);
        $this->assertEmpty($unexpected_messages_by_type, sprintf('No additional messages are present with type "%s". This expectation is wrong, because there are additional messages present: "%s"', $type, implode('", "', $unexpected_messages_by_type)));
        $this->assertEmpty($missing_expected_messages_by_type, sprintf('Every expected messages are present with type "%s". This expectation is wrong, because the following messages aren\'t present: "%s"', $type, implode('", "', $missing_expected_messages_by_type)));
    }
    $this->assertEmpty(CommentType::loadMultiple());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.