function MigrateEntityContentValidationTest::test2
Same name in other branches
- 9 core/modules/migrate/tests/src/Kernel/MigrateEntityContentValidationTest.php \Drupal\Tests\migrate\Kernel\MigrateEntityContentValidationTest::test2()
- 8.9.x core/modules/migrate/tests/src/Kernel/MigrateEntityContentValidationTest.php \Drupal\Tests\migrate\Kernel\MigrateEntityContentValidationTest::test2()
- 10 core/modules/migrate/tests/src/Kernel/MigrateEntityContentValidationTest.php \Drupal\Tests\migrate\Kernel\MigrateEntityContentValidationTest::test2()
Tests an import with invalid data and checks error messages.
File
-
core/
modules/ migrate/ tests/ src/ Kernel/ MigrateEntityContentValidationTest.php, line 122
Class
- MigrateEntityContentValidationTest
- Tests validation of an entity during migration.
Namespace
Drupal\Tests\migrate\KernelCode
public function test2() : void {
$long_username = $this->randomString(61);
$username_constraint = new UserNameConstraint();
$this->runImport([
'source' => [
'plugin' => 'embedded_data',
'data_rows' => [
[
'id' => 1,
'name' => $long_username,
],
[
'id' => 2,
'name' => $this->randomString(32),
],
[
'id' => 3,
'name' => $this->randomString(32),
],
],
'ids' => [
'id' => [
'type' => 'integer',
],
],
],
'process' => [
'name' => 'name',
],
'destination' => [
'plugin' => 'entity:user',
'validate' => TRUE,
],
]);
$this->assertSame(sprintf('1: [user]: name=%s||name=%s||mail=Email field is required.', $username_constraint->illegalMessage, t($username_constraint->tooLongMessage, [
'%name' => $long_username,
'%max' => 60,
])), $this->messages[0], 'First message should have 3 validation errors.');
$this->assertSame(sprintf('2: [user]: name=%s||mail=Email field is required.', $username_constraint->illegalMessage), $this->messages[1], 'Second message should have 2 validation errors.');
$this->assertSame(sprintf('3: [user]: name=%s||mail=Email field is required.', $username_constraint->illegalMessage), $this->messages[2], 'Third message should have 2 validation errors.');
$this->assertArrayNotHasKey(3, $this->messages, 'Fourth message should not exist.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.