Update to Drupal 8.0-dev-2015-11-17. Commits through da81cd220, Tue Nov 17 15:53:49 2015 +0000, Issue #2617224 by Wim Leers: Move around/fix some documentation.
This commit is contained in:
parent
4afb23bbd3
commit
7784f4c23d
929 changed files with 19798 additions and 5304 deletions
|
@ -9,8 +9,12 @@ namespace Drupal\Tests\migrate\Unit;
|
|||
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\MigrateSkipRowException;
|
||||
use Drupal\migrate\Plugin\migrate\source\SourcePluginBase;
|
||||
use Drupal\migrate\Plugin\MigrateIdMapInterface;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
|
||||
|
@ -128,6 +132,7 @@ class MigrateSourceTest extends MigrateTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::__construct
|
||||
* @expectedException \Drupal\migrate\MigrateException
|
||||
*/
|
||||
public function testHighwaterTrackChangesIncompatible() {
|
||||
|
@ -138,6 +143,8 @@ class MigrateSourceTest extends MigrateTestCase {
|
|||
|
||||
/**
|
||||
* Test that the source count is correct.
|
||||
*
|
||||
* @covers ::count
|
||||
*/
|
||||
public function testCount() {
|
||||
// Mock the cache to validate set() receives appropriate arguments.
|
||||
|
@ -221,6 +228,144 @@ class MigrateSourceTest extends MigrateTestCase {
|
|||
$this->assertTrue(is_a($source->current(), 'Drupal\migrate\Row'), 'Incoming row timestamp is greater than current highwater mark so we have a row.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test basic row preparation.
|
||||
*
|
||||
* @covers ::prepareRow
|
||||
*/
|
||||
public function testPrepareRow() {
|
||||
$this->migrationConfiguration['id'] = 'test_migration';
|
||||
|
||||
// Get a new migration with an id.
|
||||
$migration = $this->getMigration();
|
||||
$source = new StubSourcePlugin([], '', [], $migration);
|
||||
$row = new Row([], []);
|
||||
|
||||
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
|
||||
$module_handler->invokeAll('migrate_prepare_row', [$row, $source, $migration])
|
||||
->willReturn([TRUE, TRUE])
|
||||
->shouldBeCalled();
|
||||
$module_handler->invokeAll('migrate_' . $migration->id() . '_prepare_row', [$row, $source, $migration])
|
||||
->willReturn([TRUE, TRUE])
|
||||
->shouldBeCalled();
|
||||
$source->setModuleHandler($module_handler->reveal());
|
||||
|
||||
// Ensure we don't log this to the mapping table.
|
||||
$this->idMap->expects($this->never())
|
||||
->method('saveIdMapping');
|
||||
|
||||
$this->assertTrue($source->prepareRow($row));
|
||||
|
||||
// Track_changes...
|
||||
$source = new StubSourcePlugin(['track_changes' => TRUE], '', [], $migration);
|
||||
$row2 = $this->prophesize(Row::class);
|
||||
$row2->rehash()
|
||||
->shouldBeCalled();
|
||||
$module_handler->invokeAll('migrate_prepare_row', [$row2, $source, $migration])
|
||||
->willReturn([TRUE, TRUE])
|
||||
->shouldBeCalled();
|
||||
$module_handler->invokeAll('migrate_' . $migration->id() . '_prepare_row', [$row2, $source, $migration])
|
||||
->willReturn([TRUE, TRUE])
|
||||
->shouldBeCalled();
|
||||
$source->setModuleHandler($module_handler->reveal());
|
||||
$this->assertTrue($source->prepareRow($row2->reveal()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that global prepare hooks can skip rows.
|
||||
*
|
||||
* @covers ::prepareRow
|
||||
*/
|
||||
public function testPrepareRowGlobalPrepareSkip() {
|
||||
$this->migrationConfiguration['id'] = 'test_migration';
|
||||
|
||||
$migration = $this->getMigration();
|
||||
$source = new StubSourcePlugin([], '', [], $migration);
|
||||
$row = new Row([], []);
|
||||
|
||||
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
|
||||
// Return a failure from a prepare row hook.
|
||||
$module_handler->invokeAll('migrate_prepare_row', [$row, $source, $migration])
|
||||
->willReturn([TRUE, FALSE, TRUE])
|
||||
->shouldBeCalled();
|
||||
$module_handler->invokeAll('migrate_' . $migration->id() . '_prepare_row', [$row, $source, $migration])
|
||||
->willReturn([TRUE, TRUE])
|
||||
->shouldBeCalled();
|
||||
$source->setModuleHandler($module_handler->reveal());
|
||||
|
||||
$this->idMap->expects($this->once())
|
||||
->method('saveIdMapping')
|
||||
->with($row, [], MigrateIdMapInterface::STATUS_IGNORED);
|
||||
|
||||
$this->assertFalse($source->prepareRow($row));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that migrate specific prepare hooks can skip rows.
|
||||
*
|
||||
* @covers ::prepareRow
|
||||
*/
|
||||
public function testPrepareRowMigratePrepareSkip() {
|
||||
$this->migrationConfiguration['id'] = 'test_migration';
|
||||
|
||||
$migration = $this->getMigration();
|
||||
$source = new StubSourcePlugin([], '', [], $migration);
|
||||
$row = new Row([], []);
|
||||
|
||||
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
|
||||
// Return a failure from a prepare row hook.
|
||||
$module_handler->invokeAll('migrate_prepare_row', [$row, $source, $migration])
|
||||
->willReturn([TRUE, TRUE])
|
||||
->shouldBeCalled();
|
||||
$module_handler->invokeAll('migrate_' . $migration->id() . '_prepare_row', [$row, $source, $migration])
|
||||
->willReturn([TRUE, FALSE, TRUE])
|
||||
->shouldBeCalled();
|
||||
$source->setModuleHandler($module_handler->reveal());
|
||||
|
||||
$this->idMap->expects($this->once())
|
||||
->method('saveIdMapping')
|
||||
->with($row, [], MigrateIdMapInterface::STATUS_IGNORED);
|
||||
|
||||
$this->assertFalse($source->prepareRow($row));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a skip exception during prepare hooks correctly skips.
|
||||
*
|
||||
* @covers ::prepareRow
|
||||
*/
|
||||
public function testPrepareRowPrepareException() {
|
||||
$this->migrationConfiguration['id'] = 'test_migration';
|
||||
|
||||
$migration = $this->getMigration();
|
||||
$source = new StubSourcePlugin([], '', [], $migration);
|
||||
$row = new Row([], []);
|
||||
|
||||
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
|
||||
// Return a failure from a prepare row hook.
|
||||
$module_handler->invokeAll('migrate_prepare_row', [$row, $source, $migration])
|
||||
->willReturn([TRUE, TRUE])
|
||||
->shouldBeCalled();
|
||||
$module_handler->invokeAll('migrate_' . $migration->id() . '_prepare_row', [$row, $source, $migration])
|
||||
->willThrow(new MigrateSkipRowException())
|
||||
->shouldBeCalled();
|
||||
$source->setModuleHandler($module_handler->reveal());
|
||||
|
||||
// This will only be called on the first prepare because the second
|
||||
// explicitly avoids it.
|
||||
$this->idMap->expects($this->once())
|
||||
->method('saveIdMapping')
|
||||
->with($row, [], MigrateIdMapInterface::STATUS_IGNORED);
|
||||
$this->assertFalse($source->prepareRow($row));
|
||||
|
||||
// Throw an exception the second time that avoids mapping.
|
||||
$e = new MigrateSkipRowException('', FALSE);
|
||||
$module_handler->invokeAll('migrate_' . $migration->id() . '_prepare_row', [$row, $source, $migration])
|
||||
->willThrow($e)
|
||||
->shouldBeCalled();
|
||||
$this->assertFalse($source->prepareRow($row));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a mock executable for the test.
|
||||
*
|
||||
|
@ -239,3 +384,46 @@ class MigrateSourceTest extends MigrateTestCase {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Stubbed source plugin for testing base class implementations.
|
||||
*/
|
||||
class StubSourcePlugin extends SourcePluginBase {
|
||||
|
||||
/**
|
||||
* Helper for setting internal module handler implementation.
|
||||
*
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
*/
|
||||
function setModuleHandler(ModuleHandlerInterface $module_handler) {
|
||||
$this->moduleHandler = $module_handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __toString() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function initializeIterator() {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,11 @@ abstract class MigrateTestCase extends UnitTestCase {
|
|||
|
||||
protected $migrationConfiguration = [];
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Plugin\MigrateIdMapInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $idMap;
|
||||
|
||||
/**
|
||||
* Local store for mocking setStatus()/getStatus().
|
||||
*
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\Plugin\migrate\destination\EntityContentBaseTest
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Tests base entity migration destination functionality.
|
||||
*
|
||||
* @coversDefaultClass \Drupal\migrate\Plugin\migrate\destination\EntityContentBase
|
||||
* @group migrate
|
||||
*/
|
||||
class EntityContentBaseTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Entity\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->migration = $this->prophesize(MigrationInterface::class);
|
||||
$this->storage = $this->prophesize(EntityStorageInterface::class);
|
||||
$this->entityManager = $this->prophesize(EntityManagerInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test basic entity save.
|
||||
*
|
||||
* @covers ::import
|
||||
*/
|
||||
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);
|
||||
// Assert that save is called.
|
||||
$entity->save()
|
||||
->shouldBeCalledTimes(1);
|
||||
// Set an id for the entity
|
||||
$entity->id()
|
||||
->willReturn(5);
|
||||
$destination->setEntity($entity->reveal());
|
||||
// Ensure the id is saved entity id is returned from import.
|
||||
$this->assertEquals([5], $destination->import(new Row([], [])));
|
||||
// Assert that import set the rollback action.
|
||||
$this->assertEquals(MigrateIdMapInterface::ROLLBACK_DELETE, $destination->rollbackAction());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test row skipping when we can't get an entity to save.
|
||||
*
|
||||
* @covers ::import
|
||||
* @expectedException \Drupal\migrate\MigrateException
|
||||
* @expectedExceptionMessage Unable to get entity
|
||||
*/
|
||||
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([], []));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Stub class for testing EntityContentBase methods.
|
||||
*
|
||||
* We want to test things without testing the base class implementations.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -36,6 +36,11 @@ class EntityRevisionTest extends UnitTestCase {
|
|||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\Field\FieldTypePluginManagerInterface
|
||||
*/
|
||||
protected $fieldTypeManager;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
|
@ -43,6 +48,7 @@ class EntityRevisionTest extends UnitTestCase {
|
|||
$this->migration = $this->prophesize('\Drupal\migrate\Entity\MigrationInterface');
|
||||
$this->storage = $this->prophesize('\Drupal\Core\Entity\EntityStorageInterface');
|
||||
$this->entityManager = $this->prophesize('\Drupal\Core\Entity\EntityManagerInterface');
|
||||
$this->fieldTypeManager = $this->prophesize('\Drupal\Core\Field\FieldTypePluginManagerInterface');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -183,7 +189,9 @@ class EntityRevisionTest extends UnitTestCase {
|
|||
$this->migration->reveal(),
|
||||
$this->storage->reveal(),
|
||||
[],
|
||||
$this->entityManager->reveal());
|
||||
$this->entityManager->reveal(),
|
||||
$this->fieldTypeManager->reveal()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue