public function MigrateSqlIdMapTest::testMessageSave in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php \Drupal\Tests\migrate\Unit\MigrateSqlIdMapTest::testMessageSave()
Tests the SQL ID map save message method.
File
- core/
modules/ migrate/ tests/ src/ Unit/ MigrateSqlIdMapTest.php, line 278 - Contains \Drupal\Tests\migrate\Unit\MigrateSqlIdMapTest.
Class
- MigrateSqlIdMapTest
- Tests the SQL ID map plugin.
Namespace
Drupal\Tests\migrate\UnitCode
public function testMessageSave() {
$message = 'Hello world.';
$expected_results = [
1 => [
'message' => $message,
'level' => MigrationInterface::MESSAGE_ERROR,
],
2 => [
'message' => $message,
'level' => MigrationInterface::MESSAGE_WARNING,
],
3 => [
'message' => $message,
'level' => MigrationInterface::MESSAGE_NOTICE,
],
4 => [
'message' => $message,
'level' => MigrationInterface::MESSAGE_INFORMATIONAL,
],
];
$id_map = $this
->getIdMap();
foreach ($expected_results as $key => $expected_result) {
$id_map
->saveMessage([
'source_id_property' => $key,
], $message, $expected_result['level']);
}
foreach ($id_map
->getMessageIterator() as $message_row) {
$key = $message_row->sourceid1;
$this
->assertEquals($expected_results[$key]['message'], $message_row->message);
$this
->assertEquals($expected_results[$key]['level'], $message_row->level);
}
// Insert with default level.
$message_default = 'Hello world default.';
$id_map
->saveMessage([
'source_id_property' => 5,
], $message_default);
$messages = $id_map
->getMessageIterator([
'source_id_property' => 5,
]);
$count = 0;
foreach ($messages as $key => $message_row) {
$count = 1;
$this
->assertEquals($message_default, $message_row->message);
$this
->assertEquals(MigrationInterface::MESSAGE_ERROR, $message_row->level);
}
$this
->assertEquals($count, 1);
// Retrieve messages with a specific level.
$messages = $id_map
->getMessageIterator([], MigrationInterface::MESSAGE_WARNING);
$count = 0;
foreach ($messages as $key => $message_row) {
$count = 1;
$this
->assertEquals(MigrationInterface::MESSAGE_WARNING, $message_row->level);
}
$this
->assertEquals($count, 1);
}