Mercurial > hg > isophonics-drupal-site
diff core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children |
line wrap: on
line diff
--- a/core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php Mon Apr 23 09:33:26 2018 +0100 +++ b/core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php Mon Apr 23 09:46:53 2018 +0100 @@ -2,10 +2,10 @@ namespace Drupal\Tests\migrate\Kernel; +use Drupal\entity_test\Entity\EntityTestMul; use Drupal\KernelTests\KernelTestBase; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\migrate\MigrateExecutable; -use Drupal\migrate\MigrateMessage; use Drupal\migrate\Plugin\migrate\destination\EntityContentBase; use Drupal\migrate\Plugin\MigrateIdMapInterface; use Drupal\migrate\Plugin\MigrationInterface; @@ -45,6 +45,11 @@ */ protected function setUp() { parent::setUp(); + + // Enable two required fields with default values: a single-value field and + // a multi-value field. + \Drupal::state()->set('entity_test.required_default_field', TRUE); + \Drupal::state()->set('entity_test.required_multi_default_field', TRUE); $this->installEntitySchema('entity_test_mul'); ConfigurableLanguage::createFromLangcode('en')->save(); @@ -191,7 +196,7 @@ ]; $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition); - $executable = new MigrateExecutable($migration, new MigrateMessage()); + $executable = new MigrateExecutable($migration); $result = $executable->import(); $this->assertEquals(MigrationInterface::RESULT_COMPLETED, $result); @@ -239,7 +244,7 @@ $migration = \Drupal::service('plugin.manager.migration') ->createStubMigration($definition); - $executable = new MigrateExecutable($migration, new MigrateMessage()); + $executable = new MigrateExecutable($migration); $executable->import(); /** @var \Drupal\migrate_entity_test\Entity\StringIdEntityTest $entity */ @@ -256,7 +261,7 @@ $migration = \Drupal::service('plugin.manager.migration') ->createStubMigration($definition); - $executable = new MigrateExecutable($migration, new MigrateMessage()); + $executable = new MigrateExecutable($migration); $executable->import(); /** @var \Drupal\migrate_entity_test\Entity\StringIdEntityTest $entity */ @@ -266,4 +271,34 @@ $this->assertNull($entity->version->value); } + /** + * Tests stub rows. + */ + public function testStubRows() { + // Create a destination. + $this->createDestination([]); + + // Import a stub row. + $row = new Row([], [], TRUE); + $row->setDestinationProperty('type', 'test'); + $ids = $this->destination->import($row); + $this->assertCount(1, $ids); + + // Make sure the entity was saved. + $entity = EntityTestMul::load(reset($ids)); + $this->assertInstanceOf(EntityTestMul::class, $entity); + // Make sure the default value was applied to the required fields. + $single_field_name = 'required_default_field'; + $single_default_value = $entity->getFieldDefinition($single_field_name)->getDefaultValueLiteral(); + $this->assertSame($single_default_value, $entity->get($single_field_name)->getValue()); + + $multi_field_name = 'required_multi_default_field'; + $multi_default_value = $entity->getFieldDefinition($multi_field_name)->getDefaultValueLiteral(); + $count = 3; + $this->assertCount($count, $multi_default_value); + for ($i = 0; $i < $count; ++$i) { + $this->assertSame($multi_default_value[$i], $entity->get($multi_field_name)->get($i)->getValue()); + } + } + }