Update to Drupal 8.0.0-beta15. For more information, see: https://www.drupal.org/node/2563023
This commit is contained in:
parent
2720a9ec4b
commit
f3791f1da3
1898 changed files with 54300 additions and 11481 deletions
|
@ -0,0 +1,5 @@
|
|||
name: 'Migrate events test'
|
||||
type: module
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\migrate_events_test\Plugin\migrate\destination\DummyDestination.
|
||||
*/
|
||||
|
||||
namespace Drupal\migrate_events_test\Plugin\migrate\destination;
|
||||
|
||||
use Drupal\migrate\Entity\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\migrate\destination\DestinationBase;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* @MigrateDestination(
|
||||
* id = "dummy",
|
||||
* requirements_met = true
|
||||
* )
|
||||
*/
|
||||
class DummyDestination extends DestinationBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['value']['type'] = 'string';
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields(MigrationInterface $migration = NULL) {
|
||||
return ['value' => 'Dummy value'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function import(Row $row, array $old_destination_id_values = array()) {
|
||||
return ['value' => $row->getDestinationProperty('value')];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
name: 'Migrate module prepareRow tests'
|
||||
type: module
|
||||
description: 'Support module for source plugin prepareRow testing.'
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Test module for testing the migration source plugin prepareRow() exception
|
||||
* handling.
|
||||
*/
|
||||
|
||||
use Drupal\migrate\Entity\MigrationInterface;
|
||||
use Drupal\migrate\MigrateSkipRowException;
|
||||
use Drupal\migrate\Plugin\MigrateSourceInterface;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Implements hook_migrate_prepare_row().
|
||||
*/
|
||||
function migrate_prepare_row_test_migrate_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration) {
|
||||
// Test both options for save_to_map.
|
||||
$data = $row->getSourceProperty('data');
|
||||
if ($data == 'skip_and_record') {
|
||||
throw new MigrateSkipRowException('', TRUE);
|
||||
}
|
||||
elseif ($data == 'skip_and_dont_record') {
|
||||
throw new MigrateSkipRowException('', FALSE);
|
||||
}
|
||||
}
|
|
@ -50,11 +50,9 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
parent::setUp();
|
||||
$this->migration = $this->getMigration();
|
||||
$this->message = $this->getMock('Drupal\migrate\MigrateMessageInterface');
|
||||
|
||||
$this->executable = new TestMigrateExecutable($this->migration, $this->message);
|
||||
$event_dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
|
||||
$this->executable = new TestMigrateExecutable($this->migration, $this->message, $event_dispatcher);
|
||||
$this->executable->setStringTranslation($this->getStringTranslationStub());
|
||||
$this->executable->setTimeThreshold(0.1);
|
||||
$this->executable->limit = array('unit' => 'second', 'value' => 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -120,11 +118,6 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
->will($this->returnValue($destination));
|
||||
|
||||
$this->assertSame(MigrationInterface::RESULT_COMPLETED, $this->executable->import());
|
||||
|
||||
$this->assertSame(1, $this->executable->getSuccessesSinceFeedback());
|
||||
$this->assertSame(1, $this->executable->getTotalSuccesses());
|
||||
$this->assertSame(1, $this->executable->getTotalProcessed());
|
||||
$this->assertSame(1, $this->executable->getProcessedSinceFeedback());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -170,11 +163,6 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
->method('saveIdMapping');
|
||||
|
||||
$this->assertSame(MigrationInterface::RESULT_COMPLETED, $this->executable->import());
|
||||
|
||||
$this->assertSame(1, $this->executable->getSuccessesSinceFeedback());
|
||||
$this->assertSame(1, $this->executable->getTotalSuccesses());
|
||||
$this->assertSame(1, $this->executable->getTotalProcessed());
|
||||
$this->assertSame(1, $this->executable->getProcessedSinceFeedback());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -346,44 +334,6 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
$this->assertSame(MigrationInterface::RESULT_COMPLETED, $this->executable->import());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests time limit option method.
|
||||
*/
|
||||
public function testTimeOptionExceeded() {
|
||||
// Assert time limit of one second (test configuration default) is exceeded.
|
||||
$this->executable->setTimeElapsed(1);
|
||||
$this->assertTrue($this->executable->timeOptionExceeded());
|
||||
// Assert time limit not exceeded.
|
||||
$this->executable->limit = array('unit' => 'seconds', 'value' => (int) $_SERVER['REQUEST_TIME'] - 3600);
|
||||
$this->assertFalse($this->executable->timeOptionExceeded());
|
||||
// Assert no time limit.
|
||||
$this->executable->limit = array();
|
||||
$this->assertFalse($this->executable->timeOptionExceeded());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests get time limit method.
|
||||
*/
|
||||
public function testGetTimeLimit() {
|
||||
// Assert time limit has a unit of one second (test configuration default).
|
||||
$limit = $this->executable->limit;
|
||||
$this->assertArrayHasKey('unit', $limit);
|
||||
$this->assertSame('second', $limit['unit']);
|
||||
$this->assertSame($limit['value'], $this->executable->getTimeLimit());
|
||||
// Assert time limit has a unit of multiple seconds.
|
||||
$this->executable->limit = array('unit' => 'seconds', 'value' => 30);
|
||||
$limit = $this->executable->limit;
|
||||
$this->assertArrayHasKey('unit', $limit);
|
||||
$this->assertSame('seconds', $limit['unit']);
|
||||
$this->assertSame($limit['value'], $this->executable->getTimeLimit());
|
||||
// Assert no time limit.
|
||||
$this->executable->limit = array();
|
||||
$limit = $this->executable->limit;
|
||||
$this->assertArrayNotHasKey('unit', $limit);
|
||||
$this->assertArrayNotHasKey('value', $limit);
|
||||
$this->assertNull($this->executable->getTimeLimit());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests saving of queued messages.
|
||||
*/
|
||||
|
@ -435,22 +385,6 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
$this->assertAttributeEquals($expected_messages, 'queuedMessages', $this->executable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests maximum execution time (max_execution_time) of an import.
|
||||
*/
|
||||
public function testMaxExecTimeExceeded() {
|
||||
// Assert no max_execution_time value.
|
||||
$this->executable->setMaxExecTime(0);
|
||||
$this->assertFalse($this->executable->maxExecTimeExceeded());
|
||||
// Assert default max_execution_time value does not exceed.
|
||||
$this->executable->setMaxExecTime(30);
|
||||
$this->assertFalse($this->executable->maxExecTimeExceeded());
|
||||
// Assert max_execution_time value is exceeded.
|
||||
$this->executable->setMaxExecTime(1);
|
||||
$this->executable->setTimeElapsed(2);
|
||||
$this->assertTrue($this->executable->maxExecTimeExceeded());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the processRow method.
|
||||
*/
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
namespace Drupal\Tests\migrate\Unit;
|
||||
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\Plugin\MigrateIdMapInterface;
|
||||
|
@ -139,10 +140,12 @@ class MigrateSourceTest extends MigrateTestCase {
|
|||
* Test that the source count is correct.
|
||||
*/
|
||||
public function testCount() {
|
||||
|
||||
// Mock the cache to validate set() receives appropriate arguments.
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('cache.migrate', 'Drupal\Core\Cache\NullBackend')
|
||||
->setArguments(['migrate']);
|
||||
$cache = $this->getMock(CacheBackendInterface::class);
|
||||
$cache->expects($this->any())->method('set')
|
||||
->with($this->isType('string'), $this->isType('int'), $this->isType('int'));
|
||||
$container->set('cache.migrate', $cache);
|
||||
\Drupal::setContainer($container);
|
||||
|
||||
// Test that the basic count works.
|
||||
|
@ -168,16 +171,6 @@ class MigrateSourceTest extends MigrateTestCase {
|
|||
$this->assertNull($source->current(), 'No row is available when prepareRow() is false.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the when a source id is in the idList, we don't get a row.
|
||||
*/
|
||||
public function testIdInList() {
|
||||
$source = $this->getSource([], ['idlist' => ['test_sourceid1']]);
|
||||
$source->rewind();
|
||||
|
||||
$this->assertNull($source->current(), 'No row is available because id was in idList.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that $row->needsUpdate() works as expected.
|
||||
*/
|
||||
|
@ -238,8 +231,11 @@ class MigrateSourceTest extends MigrateTestCase {
|
|||
* The migrate executable.
|
||||
*/
|
||||
protected function getMigrateExecutable($migration) {
|
||||
/** @var \Drupal\migrate\MigrateMessageInterface $message */
|
||||
$message = $this->getMock('Drupal\migrate\MigrateMessageInterface');
|
||||
return new MigrateExecutable($migration, $message);
|
||||
/** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher */
|
||||
$event_dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
|
||||
return new MigrateExecutable($migration, $message, $event_dispatcher);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -181,31 +181,33 @@ class MigrateSqlIdMapEnsureTablesTest extends MigrateTestCase {
|
|||
->getMock();
|
||||
$database->expects($this->any())
|
||||
->method('schema')
|
||||
->will($this->returnValue($schema));
|
||||
->willReturn($schema);
|
||||
$migration = $this->getMigration();
|
||||
$plugin = $this->getMock('Drupal\migrate\Plugin\MigrateSourceInterface');
|
||||
$plugin->expects($this->any())
|
||||
->method('getIds')
|
||||
->will($this->returnValue(array(
|
||||
->willReturn(array(
|
||||
'source_id_property' => array(
|
||||
'type' => 'integer',
|
||||
),
|
||||
)));
|
||||
));
|
||||
$migration->expects($this->any())
|
||||
->method('getSourcePlugin')
|
||||
->will($this->returnValue($plugin));
|
||||
->willReturn($plugin);
|
||||
$plugin = $this->getMock('Drupal\migrate\Plugin\MigrateSourceInterface');
|
||||
$plugin->expects($this->any())
|
||||
->method('getIds')
|
||||
->will($this->returnValue(array(
|
||||
->willReturn(array(
|
||||
'destination_id_property' => array(
|
||||
'type' => 'string',
|
||||
),
|
||||
)));
|
||||
));
|
||||
$migration->expects($this->any())
|
||||
->method('getDestinationPlugin')
|
||||
->will($this->returnValue($plugin));
|
||||
$map = new TestSqlIdMap($database, array(), 'sql', array(), $migration);
|
||||
->willReturn($plugin);
|
||||
/** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher */
|
||||
$event_dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
|
||||
$map = new TestSqlIdMap($database, array(), 'sql', array(), $migration, $event_dispatcher);
|
||||
$map->getDatabase();
|
||||
}
|
||||
|
||||
|
|
|
@ -102,8 +102,9 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
|||
$migration
|
||||
->method('getDestinationPlugin')
|
||||
->willReturn($plugin);
|
||||
$event_dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
|
||||
|
||||
$id_map = new TestSqlIdMap($this->database, [], 'sql', [], $migration);
|
||||
$id_map = new TestSqlIdMap($this->database, [], 'sql', [], $migration, $event_dispatcher);
|
||||
$migration
|
||||
->method('getIdMap')
|
||||
->willReturn($id_map);
|
||||
|
@ -286,25 +287,34 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
|||
|
||||
foreach ($expected_results as $key => $expected_result) {
|
||||
$id_map->saveMessage([$key], $message, $expected_result['level']);
|
||||
$message_row = $this->database->select($id_map->messageTableName(), 'message')
|
||||
->fields('message')
|
||||
->condition('level', $expected_result['level'])
|
||||
->condition('message', $expected_result['message'])
|
||||
->execute()
|
||||
->fetchAssoc();
|
||||
$this->assertEquals($expected_result['message'], $message_row['message'], 'Message from database was read.');
|
||||
}
|
||||
|
||||
foreach ($id_map->getMessageIterator() as $message_row) {
|
||||
$key = $message_row->sourceid1;
|
||||
$this->assertEquals($expected_results[$key]['message'], $message_row->message);
|
||||
$this->assertEquals($expected_results[$key]['level'], $message_row->level);
|
||||
}
|
||||
|
||||
// Insert with default level.
|
||||
$message_default = 'Hello world default.';
|
||||
$id_map->saveMessage([5], $message_default);
|
||||
$message_row = $this->database->select($id_map->messageTableName(), 'message')
|
||||
->fields('message')
|
||||
->condition('level', MigrationInterface::MESSAGE_ERROR)
|
||||
->condition('message', $message_default)
|
||||
->execute()
|
||||
->fetchAssoc();
|
||||
$this->assertEquals($message_default, $message_row['message'], 'Message from database was read.');
|
||||
$messages = $id_map->getMessageIterator([5]);
|
||||
$count = 0;
|
||||
foreach ($messages as $key => $message_row) {
|
||||
$count = 1;
|
||||
$this->assertEquals($message_default, $message_row->message);
|
||||
$this->assertEquals(MigrationInterface::MESSAGE_ERROR, $message_row->level);
|
||||
}
|
||||
$this->assertEquals($count, 1);
|
||||
|
||||
// Retrieve messages with a specific level.
|
||||
$messages = $id_map->getMessageIterator([], MigrationInterface::MESSAGE_WARNING);
|
||||
$count = 0;
|
||||
foreach ($messages as $key => $message_row) {
|
||||
$count = 1;
|
||||
$this->assertEquals(MigrationInterface::MESSAGE_WARNING, $message_row->level);
|
||||
}
|
||||
$this->assertEquals($count, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace Drupal\Tests\migrate\Unit;
|
|||
|
||||
use Drupal\Core\Database\Driver\sqlite\Connection;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\migrate\Entity\MigrationInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
|
@ -18,6 +19,13 @@ abstract class MigrateTestCase extends UnitTestCase {
|
|||
|
||||
protected $migrationConfiguration = [];
|
||||
|
||||
/**
|
||||
* Local store for mocking setStatus()/getStatus().
|
||||
*
|
||||
* @var \Drupal\migrate\Entity\MigrationInterface::STATUS_*
|
||||
*/
|
||||
protected $migrationStatus = MigrationInterface::STATUS_IDLE;
|
||||
|
||||
/**
|
||||
* Retrieve a mocked migration.
|
||||
*
|
||||
|
@ -28,29 +36,54 @@ abstract class MigrateTestCase extends UnitTestCase {
|
|||
$this->migrationConfiguration += ['migrationClass' => 'Drupal\migrate\Entity\Migration'];
|
||||
$this->idMap = $this->getMock('Drupal\migrate\Plugin\MigrateIdMapInterface');
|
||||
|
||||
$this->idMap->expects($this->any())
|
||||
$this->idMap
|
||||
->method('getQualifiedMapTableName')
|
||||
->will($this->returnValue('test_map'));
|
||||
->willReturn('test_map');
|
||||
|
||||
$migration = $this->getMockBuilder($this->migrationConfiguration['migrationClass'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$migration->method('checkRequirements')
|
||||
->willReturn(TRUE);
|
||||
|
||||
$migration->method('getIdMap')
|
||||
->willReturn($this->idMap);
|
||||
|
||||
// We need the state to be toggled throughout the test so we store the value
|
||||
// on the test class and use a return callback.
|
||||
$migration->expects($this->any())
|
||||
->method('checkRequirements')
|
||||
->will($this->returnValue(TRUE));
|
||||
->method('getStatus')
|
||||
->willReturnCallback(function() {
|
||||
return $this->migrationStatus;
|
||||
});
|
||||
$migration->expects($this->any())
|
||||
->method('getIdMap')
|
||||
->will($this->returnValue($this->idMap));
|
||||
->method('setStatus')
|
||||
->willReturnCallback(function($status) {
|
||||
$this->migrationStatus = $status;
|
||||
});
|
||||
|
||||
$migration->method('getMigrationDependencies')
|
||||
->willReturn([
|
||||
'required' => [],
|
||||
'optional' => [],
|
||||
]);
|
||||
|
||||
$configuration = &$this->migrationConfiguration;
|
||||
$migration->expects($this->any())->method('get')->will($this->returnCallback(function ($argument) use (&$configuration) {
|
||||
return isset($configuration[$argument]) ? $configuration[$argument] : '';
|
||||
}));
|
||||
$migration->expects($this->any())->method('set')->will($this->returnCallback(function ($argument, $value) use (&$configuration) {
|
||||
|
||||
$migration->method('get')
|
||||
->willReturnCallback(function ($argument) use (&$configuration) {
|
||||
return isset($configuration[$argument]) ? $configuration[$argument] : '';
|
||||
});
|
||||
|
||||
$migration->method('set')
|
||||
->willReturnCallback(function ($argument, $value) use (&$configuration) {
|
||||
$configuration[$argument] = $value;
|
||||
}));
|
||||
$migration->expects($this->any())
|
||||
->method('id')
|
||||
->will($this->returnValue($configuration['id']));
|
||||
});
|
||||
|
||||
$migration->method('id')
|
||||
->willReturn($configuration['id']);
|
||||
|
||||
return $migration;
|
||||
}
|
||||
|
||||
|
|
112
core/modules/migrate/tests/src/Unit/MigrationStorageTest.php
Normal file
112
core/modules/migrate/tests/src/Unit/MigrationStorageTest.php
Normal file
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\MigrationStorageTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit;
|
||||
|
||||
use Drupal\Component\Uuid\UuidInterface;
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\Query\QueryFactoryInterface;
|
||||
use Drupal\Core\Entity\Query\QueryInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Drupal\migrate\MigrationStorage;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\migrate\MigrationStorage
|
||||
* @group migrate
|
||||
*/
|
||||
class MigrationStorageTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\Tests\migrate\Unit\TestMigrationStorage
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\Entity\Query\QueryInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $query;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
$this->query = $this->getMock(QueryInterface::class);
|
||||
$this->query->method('condition')
|
||||
->willReturnSelf();
|
||||
|
||||
$query_factory = $this->getMock(QueryFactoryInterface::class);
|
||||
$query_factory->method('get')
|
||||
->willReturn($this->query);
|
||||
|
||||
$this->storage = new TestMigrationStorage(
|
||||
$this->getMock(EntityTypeInterface::class),
|
||||
$this->getMock(ConfigFactoryInterface::class),
|
||||
$this->getMock(UuidInterface::class),
|
||||
$this->getMock(LanguageManagerInterface::class),
|
||||
$query_factory
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests getVariantIds() when variants exist.
|
||||
*
|
||||
* @covers ::getVariantIds
|
||||
*/
|
||||
public function testGetVariantIdsWithVariants() {
|
||||
$this->query->method('execute')
|
||||
->willReturn(['d6_node__page', 'd6_node__article']);
|
||||
|
||||
$ids = $this->storage->getVariantIds(['d6_node:*', 'd6_user']);
|
||||
$this->assertSame(['d6_node__page', 'd6_node__article', 'd6_user'], $ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests getVariantIds() when no variants exist.
|
||||
*
|
||||
* @covers ::getVariantIds
|
||||
*/
|
||||
public function testGetVariantIdsNoVariants() {
|
||||
$this->query->method('execute')
|
||||
->willReturn([]);
|
||||
|
||||
$ids = $this->storage->getVariantIds(['d6_node:*', 'd6_user']);
|
||||
$this->assertSame(['d6_user'], $ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests getVariantIds() when no variants exist and there are no static
|
||||
* (non-variant) dependencies.
|
||||
*
|
||||
* @covers ::getVariantIds
|
||||
*/
|
||||
public function testGetVariantIdsNoVariantsOrStaticDependencies() {
|
||||
$this->query->method('execute')
|
||||
->willReturn([]);
|
||||
|
||||
$ids = $this->storage->getVariantIds(['d6_node:*', 'd6_node_revision:*']);
|
||||
$this->assertSame([], $ids);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test version of \Drupal\migrate\MigrationStorage.
|
||||
*
|
||||
* Exposes protected methods for testing.
|
||||
*/
|
||||
class TestMigrationStorage extends MigrationStorage {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getVariantIds(array $ids) {
|
||||
return parent::getVariantIds($ids);
|
||||
}
|
||||
|
||||
}
|
|
@ -15,13 +15,6 @@ use Drupal\migrate\MigrateExecutable;
|
|||
*/
|
||||
class TestMigrateExecutable extends MigrateExecutable {
|
||||
|
||||
/**
|
||||
* The (fake) number of seconds elapsed since the start of the test.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $timeElapsed;
|
||||
|
||||
/**
|
||||
* The fake memory usage in bytes.
|
||||
*
|
||||
|
@ -46,86 +39,6 @@ class TestMigrateExecutable extends MigrateExecutable {
|
|||
$this->stringTranslation = $string_translation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows access to protected timeOptionExceeded method.
|
||||
*
|
||||
* @return bool
|
||||
* A threshold exceeded value.
|
||||
*/
|
||||
public function timeOptionExceeded() {
|
||||
return parent::timeOptionExceeded();
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows access to set protected maxExecTime property.
|
||||
*
|
||||
* @param int $max_exec_time
|
||||
* The value to set.
|
||||
*/
|
||||
public function setMaxExecTime($max_exec_time) {
|
||||
$this->maxExecTime = $max_exec_time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows access to protected maxExecTime property.
|
||||
*
|
||||
* @return int
|
||||
* The value of the protected property.
|
||||
*/
|
||||
public function getMaxExecTime() {
|
||||
return $this->maxExecTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows access to protected successesSinceFeedback property.
|
||||
*
|
||||
* @return int
|
||||
* The value of the protected property.
|
||||
*/
|
||||
public function getSuccessesSinceFeedback() {
|
||||
return $this->successesSinceFeedback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows access to protected totalSuccesses property.
|
||||
*
|
||||
* @return int
|
||||
* The value of the protected property.
|
||||
*/
|
||||
public function getTotalSuccesses() {
|
||||
return $this->totalSuccesses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows access to protected totalProcessed property.
|
||||
*
|
||||
* @return int
|
||||
* The value of the protected property.
|
||||
*/
|
||||
public function getTotalProcessed() {
|
||||
return $this->totalProcessed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows access to protected processedSinceFeedback property.
|
||||
*
|
||||
* @return int
|
||||
* The value of the protected property.
|
||||
*/
|
||||
public function getProcessedSinceFeedback() {
|
||||
return $this->processedSinceFeedback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows access to protected maxExecTimeExceeded method.
|
||||
*
|
||||
* @return bool
|
||||
* The threshold exceeded value.
|
||||
*/
|
||||
public function maxExecTimeExceeded() {
|
||||
return parent::maxExecTimeExceeded();
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows access to set protected source property.
|
||||
*
|
||||
|
@ -146,23 +59,6 @@ class TestMigrateExecutable extends MigrateExecutable {
|
|||
$this->sourceIdValues = $source_id_values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows setting a fake elapsed time.
|
||||
*
|
||||
* @param int $time
|
||||
* The time in seconds.
|
||||
*/
|
||||
public function setTimeElapsed($time) {
|
||||
$this->timeElapsed = $time;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getTimeElapsed() {
|
||||
return $this->timeElapsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -231,16 +127,6 @@ class TestMigrateExecutable extends MigrateExecutable {
|
|||
$this->memoryThreshold = $threshold;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the time threshold.
|
||||
*
|
||||
* @param float $threshold
|
||||
* The new threshold.
|
||||
*/
|
||||
public function setTimeThreshold($threshold) {
|
||||
$this->timeThreshold = $threshold;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -11,6 +11,7 @@ use Drupal\Core\Database\Connection;
|
|||
use Drupal\migrate\Entity\MigrationInterface;
|
||||
use Drupal\migrate\MigrateException;
|
||||
use Drupal\migrate\Plugin\migrate\id_map\Sql;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
/**
|
||||
* Defines a SQL ID map for use in tests.
|
||||
|
@ -31,9 +32,9 @@ class TestSqlIdMap extends Sql implements \Iterator {
|
|||
* @param \Drupal\migrate\Entity\MigrationInterface $migration
|
||||
* The migration to do.
|
||||
*/
|
||||
public function __construct(Connection $database, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration) {
|
||||
public function __construct(Connection $database, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EventDispatcherInterface $event_dispatcher) {
|
||||
$this->database = $database;
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $event_dispatcher);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -51,4 +51,13 @@ class ExtractTest extends MigrateProcessTestCase {
|
|||
$this->plugin->transform(array('bar' => 'foo'), $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests unsuccessful extraction.
|
||||
*/
|
||||
public function testExtractFailDefault() {
|
||||
$plugin = new Extract(['index' => ['foo'], 'default' => 'test'], 'map', []);
|
||||
$value = $plugin->transform(['bar' => 'foo'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, 'test', '');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -61,7 +61,8 @@ class IteratorTest extends MigrateTestCase {
|
|||
$migration->expects($this->at(2))
|
||||
->method('getProcessPlugins')
|
||||
->will($this->returnValue($key_plugin));
|
||||
$migrate_executable = new MigrateExecutable($migration, $this->getMock('Drupal\migrate\MigrateMessageInterface'));
|
||||
$event_dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
|
||||
$migrate_executable = new MigrateExecutable($migration, $this->getMock('Drupal\migrate\MigrateMessageInterface'), $event_dispatcher);
|
||||
|
||||
// The current value of the pipeline.
|
||||
$current_value = array(
|
||||
|
|
Reference in a new issue