EntityContentBaseTest.php in Zircon Profile 8
File
core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php
View source
<?php
namespace Drupal\Tests\migrate\Unit\Plugin\migrate\destination;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\FieldTypePluginManagerInterface;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
use Drupal\migrate\Plugin\MigrateIdMapInterface;
use Drupal\migrate\Row;
use Drupal\Tests\UnitTestCase;
class EntityContentBaseTest extends UnitTestCase {
protected $migration;
protected $storage;
protected $entityManager;
public function setUp() {
parent::setUp();
$this->migration = $this
->prophesize(MigrationInterface::class);
$this->storage = $this
->prophesize(EntityStorageInterface::class);
$this->entityManager = $this
->prophesize(EntityManagerInterface::class);
}
public function testImport() {
$bundles = [];
$destination = new EntityTestDestination([], '', [], $this->migration
->reveal(), $this->storage
->reveal(), $bundles, $this->entityManager
->reveal(), $this
->prophesize(FieldTypePluginManagerInterface::class)
->reveal());
$entity = $this
->prophesize(ContentEntityInterface::class);
$entity
->save()
->shouldBeCalledTimes(1);
$entity
->id()
->willReturn(5);
$destination
->setEntity($entity
->reveal());
$this
->assertEquals([
5,
], $destination
->import(new Row([], [])));
$this
->assertEquals(MigrateIdMapInterface::ROLLBACK_DELETE, $destination
->rollbackAction());
}
public function testImportEntityLoadFailure() {
$bundles = [];
$destination = new EntityTestDestination([], '', [], $this->migration
->reveal(), $this->storage
->reveal(), $bundles, $this->entityManager
->reveal(), $this
->prophesize(FieldTypePluginManagerInterface::class)
->reveal());
$destination
->setEntity(FALSE);
$destination
->import(new Row([], []));
}
}
class EntityTestDestination extends EntityContentBase {
private $entity = NULL;
public function setEntity($entity) {
$this->entity = $entity;
}
protected function getEntity(Row $row, array $old_destination_id_values) {
return $this->entity;
}
}