EntityRevisionTest.php
Same filename in this branch
Same filename in other branches
- 9 core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php
- 9 core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityRevisionTest.php
- 9 core/modules/migrate/tests/src/Kernel/Plugin/EntityRevisionTest.php
- 8.9.x core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php
- 8.9.x core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityRevisionTest.php
- 8.9.x core/modules/migrate/tests/src/Kernel/Plugin/EntityRevisionTest.php
- 11.x core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php
- 11.x core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityRevisionTest.php
- 11.x core/modules/migrate/tests/src/Kernel/Plugin/EntityRevisionTest.php
Namespace
Drupal\Tests\migrate\Unit\Plugin\migrate\destinationFile
-
core/
modules/ migrate/ tests/ src/ Unit/ Plugin/ migrate/ destination/ EntityRevisionTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\migrate\Unit\Plugin\migrate\destination;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\FieldTypePluginManagerInterface;
use Drupal\Core\Session\AccountSwitcherInterface;
use Drupal\migrate\MigrateException;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Plugin\migrate\destination\EntityRevision;
use Drupal\migrate\Row;
/**
* Tests entity revision destination functionality.
*
* @coversDefaultClass \Drupal\migrate\Plugin\migrate\destination\EntityRevision
* @group migrate
*/
class EntityRevisionTest extends EntityTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->migration = $this->prophesize(MigrationInterface::class);
$this->storage = $this->prophesize(EntityStorageInterface::class);
$this->entityType = $this->prophesize(EntityTypeInterface::class);
$this->entityType
->getSingularLabel()
->willReturn('foo');
$this->entityType
->getPluralLabel()
->willReturn('bar');
$this->storage
->getEntityType()
->willReturn($this->entityType
->reveal());
$this->storage
->getEntityTypeId()
->willReturn('foo');
}
/**
* Tests that revision destination fails for unrevisionable entities.
*/
public function testUnrevisionable() : void {
$this->entityType
->getKey('id')
->willReturn('id');
$this->entityType
->getKey('revision')
->willReturn('');
$this->entityFieldManager
->getBaseFieldDefinitions('foo')
->willReturn([
'id' => BaseFieldDefinitionTest::create('integer'),
]);
$destination = new EntityRevisionTestDestination([], '', [], $this->migration
->reveal(), $this->storage
->reveal(), [], $this->entityFieldManager
->reveal(), $this->prophesize(FieldTypePluginManagerInterface::class)
->reveal(), $this->prophesize(AccountSwitcherInterface::class)
->reveal());
$this->expectException(MigrateException::class);
$this->expectExceptionMessage('The "foo" entity type does not support revisions.');
$destination->getIds();
}
/**
* Tests that translation destination fails for untranslatable entities.
*/
public function testUntranslatable() : void {
$this->entityType
->getKey('id')
->willReturn('id');
$this->entityType
->getKey('revision')
->willReturn('vid');
$this->entityType
->getKey('langcode')
->willReturn('');
$this->entityFieldManager
->getBaseFieldDefinitions('foo')
->willReturn([
'id' => BaseFieldDefinitionTest::create('integer'),
'vid' => BaseFieldDefinitionTest::create('integer'),
]);
$destination = new EntityRevisionTestDestination([
'translations' => TRUE,
], '', [], $this->migration
->reveal(), $this->storage
->reveal(), [], $this->entityFieldManager
->reveal(), $this->prophesize(FieldTypePluginManagerInterface::class)
->reveal(), $this->prophesize(AccountSwitcherInterface::class)
->reveal());
$this->expectException(MigrateException::class);
$this->expectExceptionMessage('The "foo" entity type does not support translations.');
$destination->getIds();
}
}
/**
* Stub class for testing EntityRevision methods.
*/
class EntityRevisionTestDestination extends EntityRevision {
private $entity = NULL;
public function setEntity($entity) {
$this->entity = $entity;
}
protected function getEntity(Row $row, array $old_destination_id_values) {
return $this->entity;
}
public static function getEntityTypeId($plugin_id) {
return 'foo';
}
}
Classes
Title | Deprecated | Summary |
---|---|---|
EntityRevisionTest | Tests entity revision destination functionality. | |
EntityRevisionTestDestination | Stub class for testing EntityRevision methods. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.