Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663

This commit is contained in:
Greg Anderson 2015-10-08 11:40:12 -07:00
parent eb34d130a8
commit f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions

View file

@ -0,0 +1,55 @@
<?php
/**
* @file
* Contains \Drupal\Tests\migrate\Unit\Exception\RequirementsExceptionTest.
*/
namespace Drupal\Tests\migrate\Unit\Exception;
use Drupal\migrate\Exception\RequirementsException;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\migrate\Exception\RequirementsException
* @group migration
*/
class RequirementsExceptionTest extends UnitTestCase {
protected $missingRequirements = ['random_jackson_pivot', '51_Eridani_b'];
/**
* @covers ::getRequirements
*/
public function testGetRequirements() {
$exception = new RequirementsException('Missing requirements ', ['requirements' => $this->missingRequirements]);
$this->assertArrayEquals(['requirements' => $this->missingRequirements], $exception->getRequirements());
}
/**
* @covers ::getRequirementsString
* @dataProvider getRequirementsProvider
*/
public function testGetExceptionString($expected, $message, $requirements) {
$exception = new RequirementsException($message, $requirements);
$this->assertEquals($expected, $exception->getRequirementsString());
}
/**
* Provides a list of requirements to test.
*/
public function getRequirementsProvider() {
return array(
array(
'requirements: random_jackson_pivot.',
'Single Requirement',
array('requirements' => $this->missingRequirements[0]),
),
array(
'requirements: random_jackson_pivot. requirements: 51_Eridani_b.',
'Multiple Requirements',
array('requirements' => $this->missingRequirements),
),
);
}
}

View file

@ -7,6 +7,7 @@
namespace Drupal\Tests\migrate\Unit;
use Drupal\Component\Utility\Html;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\Plugin\MigrateIdMapInterface;
use Drupal\migrate\MigrateException;
@ -72,7 +73,7 @@ class MigrateExecutableTest extends MigrateTestCase {
// Ensure that a message with the proper message was added.
$this->message->expects($this->once())
->method('display')
->with("Migration failed with source plugin exception: $exception_message");
->with("Migration failed with source plugin exception: " . Html::escape($exception_message));
$result = $this->executable->import();
$this->assertEquals(MigrationInterface::RESULT_FAILED, $result);
@ -199,10 +200,6 @@ class MigrateExecutableTest extends MigrateTestCase {
->method('getDestinationPlugin')
->will($this->returnValue($destination));
$this->idMap->expects($this->once())
->method('delete')
->with(array('id' => 'test'), TRUE);
$this->idMap->expects($this->once())
->method('saveIdMapping')
->with($row, array(), MigrateIdMapInterface::STATUS_FAILED, NULL);
@ -227,9 +224,10 @@ class MigrateExecutableTest extends MigrateTestCase {
}
/**
* Tests the import method with a MigrateException being thrown.
* Tests the import method with a MigrateException being thrown from the
* destination.
*/
public function testImportWithValidRowWithMigrateException() {
public function testImportWithValidRowWithDestinationMigrateException() {
$exception_message = $this->getRandomGenerator()->string();
$source = $this->getMockSource();
@ -268,10 +266,6 @@ class MigrateExecutableTest extends MigrateTestCase {
$this->idMap->expects($this->once())
->method('saveMessage');
$this->message->expects($this->once())
->method('display')
->with($exception_message);
$this->idMap->expects($this->once())
->method('lookupDestinationId')
->with(array('id' => 'test'))
@ -280,6 +274,53 @@ class MigrateExecutableTest extends MigrateTestCase {
$this->assertSame(MigrationInterface::RESULT_COMPLETED, $this->executable->import());
}
/**
* Tests the import method with a MigrateException being thrown from a process
* plugin.
*/
public function testImportWithValidRowWithProcesMigrateException() {
$exception_message = $this->getRandomGenerator()->string();
$source = $this->getMockSource();
$row = $this->getMockBuilder('Drupal\migrate\Row')
->disableOriginalConstructor()
->getMock();
$row->expects($this->once())
->method('getSourceIdValues')
->willReturn(array('id' => 'test'));
$source->expects($this->once())
->method('current')
->willReturn($row);
$this->executable->setSource($source);
$this->migration->expects($this->once())
->method('getProcessPlugins')
->willThrowException(new MigrateException($exception_message));
$destination = $this->getMock('Drupal\migrate\Plugin\MigrateDestinationInterface');
$destination->expects($this->never())
->method('import');
$this->migration->expects($this->once())
->method('getDestinationPlugin')
->willReturn($destination);
$this->idMap->expects($this->once())
->method('saveIdMapping')
->with($row, array(), MigrateIdMapInterface::STATUS_FAILED, NULL);
$this->idMap->expects($this->once())
->method('saveMessage');
$this->idMap->expects($this->never())
->method('lookupDestinationId');
$this->assertSame(MigrationInterface::RESULT_COMPLETED, $this->executable->import());
}
/**
* Tests the import method with a regular Exception being thrown.
*/
@ -334,57 +375,6 @@ class MigrateExecutableTest extends MigrateTestCase {
$this->assertSame(MigrationInterface::RESULT_COMPLETED, $this->executable->import());
}
/**
* Tests saving of queued messages.
*/
public function testSaveQueuedMessages() {
// Assert no queued messages before save.
$this->assertAttributeEquals(array(), 'queuedMessages', $this->executable);
// Set required source_id_values for MigrateIdMapInterface::saveMessage().
$expected_messages[] = array('message' => 'message 1', 'level' => MigrationInterface::MESSAGE_ERROR);
$expected_messages[] = array('message' => 'message 2', 'level' => MigrationInterface::MESSAGE_WARNING);
$expected_messages[] = array('message' => 'message 3', 'level' => MigrationInterface::MESSAGE_INFORMATIONAL);
foreach ($expected_messages as $queued_message) {
$this->executable->queueMessage($queued_message['message'], $queued_message['level']);
}
$this->executable->setSourceIdValues(array());
$this->assertAttributeEquals($expected_messages, 'queuedMessages', $this->executable);
// No asserts of saved messages since coverage exists
// in MigrateSqlIdMapTest::saveMessage().
$this->executable->saveQueuedMessages();
// Assert no queued messages after save.
$this->assertAttributeEquals(array(), 'queuedMessages', $this->executable);
}
/**
* Tests the queuing of messages.
*/
public function testQueueMessage() {
// Assert no queued messages.
$expected_messages = array();
$this->assertAttributeEquals(array(), 'queuedMessages', $this->executable);
// Assert a single (default level) queued message.
$expected_messages[] = array(
'message' => 'message 1',
'level' => MigrationInterface::MESSAGE_ERROR,
);
$this->executable->queueMessage('message 1');
$this->assertAttributeEquals($expected_messages, 'queuedMessages', $this->executable);
// Assert multiple queued messages.
$expected_messages[] = array(
'message' => 'message 2',
'level' => MigrationInterface::MESSAGE_WARNING,
);
$this->executable->queueMessage('message 2', MigrationInterface::MESSAGE_WARNING);
$this->assertAttributeEquals($expected_messages, 'queuedMessages', $this->executable);
$expected_messages[] = array(
'message' => 'message 3',
'level' => MigrationInterface::MESSAGE_INFORMATIONAL,
);
$this->executable->queueMessage('message 3', MigrationInterface::MESSAGE_INFORMATIONAL);
$this->assertAttributeEquals($expected_messages, 'queuedMessages', $this->executable);
}
/**
* Tests the processRow method.
*/
@ -440,9 +430,6 @@ class MigrateExecutableTest extends MigrateTestCase {
->disableOriginalConstructor()
->setMethods(get_class_methods($class))
->getMockForAbstractClass();
$source->expects($this->any())
->method('getIterator')
->will($this->returnValue($iterator));
$source->expects($this->once())
->method('rewind')
->will($this->returnValue(TRUE));

View file

@ -191,7 +191,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
// Insert 4 message for later delete.
foreach ($expected_results as $key => $expected_result) {
$id_map->saveMessage([$key], $message);
$id_map->saveMessage(['source_id_property' => $key], $message);
}
// Truncate and check that 4 messages were deleted.
@ -240,7 +240,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
// Assert the row matches its original source.
$source_id = $expected_results[MigrateIdMapInterface::STATUS_NEEDS_UPDATE]['sourceid1'];
$test_row = $id_map->getRowBySource([$source_id]);
$test_row = $id_map->getRowBySource(['source_id_property' => $source_id]);
// $row_needing_update is an array of objects returned from the database,
// but $test_row is an array, so the cast is necessary.
$this->assertSame($test_row, (array) $row_needing_update[0]);
@ -268,7 +268,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
foreach ($expected_results as $key => $expected_result) {
$count = $id_map->messageCount();
$this->assertEquals($expected_result, $count);
$id_map->saveMessage([$key], $message);
$id_map->saveMessage(['source_id_property' => $key], $message);
}
}
@ -286,7 +286,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
$id_map = $this->getIdMap();
foreach ($expected_results as $key => $expected_result) {
$id_map->saveMessage([$key], $message, $expected_result['level']);
$id_map->saveMessage(['source_id_property' => $key], $message, $expected_result['level']);
}
foreach ($id_map->getMessageIterator() as $message_row) {
@ -297,8 +297,8 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
// Insert with default level.
$message_default = 'Hello world default.';
$id_map->saveMessage([5], $message_default);
$messages = $id_map->getMessageIterator([5]);
$id_map->saveMessage(['source_id_property' => 5], $message_default);
$messages = $id_map->getMessageIterator(['source_id_property' => 5]);
$count = 0;
foreach ($messages as $key => $message_row) {
$count = 1;
@ -334,11 +334,11 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
'destid1' => 'destination_id_value_2',
] + $this->idMapDefaults();
$this->saveMap($row);
$source_id_values = [$row['sourceid1'], $row['sourceid2']];
$source_id_values = ['source_id_property' => $row['sourceid1'], 'sourceid2' => $row['sourceid2']];
$id_map = $this->getIdMap();
$result_row = $id_map->getRowBySource($source_id_values);
$this->assertSame($row, $result_row);
$source_id_values = ['missing_value_1', 'missing_value_2'];
$source_id_values = ['source_id_property' => 'missing_value_1', 'sourceid2' => 'missing_value_2'];
$result_row = $id_map->getRowBySource($source_id_values);
$this->assertFalse($result_row);
}
@ -416,12 +416,12 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
'destid1' => 'destination_id_value_2',
] + $this->idMapDefaults();
$this->saveMap($row);
$dest_id_values = [$row['destid1']];
$dest_id_values = ['destination_id_property' => $row['destid1']];
$id_map = $this->getIdMap();
$result_row = $id_map->getRowByDestination($dest_id_values);
$this->assertSame($row, $result_row);
// This value does not exist.
$dest_id_values = ['invalid_destination_id_property'];
$dest_id_values = ['destination_id_property' => 'invalid_destination_id_property'];
$id_map = $this->getIdMap();
$result_row = $id_map->getRowByDestination($dest_id_values);
$this->assertFalse($result_row);
@ -463,15 +463,15 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
$expected_result = [];
for ($i = 1; $i <= $num_source_fields; $i++) {
$row["sourceid$i"] = "source_id_value_$i";
$expected_result[] = "source_id_value_$i";
$expected_result["source_id_property_$i"] = "source_id_value_$i";
$this->sourceIds["source_id_property_$i"] = [];
}
$destination_id_values = [];
$nonexistent_id_values = [];
for ($i = 1; $i <= $num_destination_fields; $i++) {
$row["destid$i"] = "destination_id_value_$i";
$destination_id_values[] = "destination_id_value_$i";
$nonexistent_id_values[] = "nonexistent_destination_id_value_$i";
$destination_id_values["destination_id_property_$i"] = "destination_id_value_$i";
$nonexistent_id_values["destination_id_property_$i"] = "nonexistent_destination_id_value_$i";
$this->destinationIds["destination_id_property_$i"] = [];
}
$this->saveMap($row);
@ -662,7 +662,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
$this->queryResultTest($this->getIdMapContents(), $expected_results);
// Mark each row as STATUS_NEEDS_UPDATE.
foreach ($row_statuses as $status) {
$id_map->setUpdate(['source_value_' . $status]);
$id_map->setUpdate(['source_id_property' => 'source_value_' . $status]);
}
// Update expected results.
foreach ($expected_results as $key => $value) {
@ -737,7 +737,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
$message_table_name = $id_map->messageTableName();
$row = new Row(['source_id_property' => 'source_value'], ['source_id_property' => []]);
$id_map->saveIdMapping($row, ['destination_id_property' => 2]);
$id_map->saveMessage(['source_value'], 'A message');
$id_map->saveMessage(['source_id_property' => 'source_value'], 'A message');
$this->assertTrue($this->database->schema()->tableExists($map_table_name),
"$map_table_name exists");
$this->assertTrue($this->database->schema()->tableExists($message_table_name),

View file

@ -7,6 +7,8 @@
namespace Drupal\Tests\migrate\Unit;
use Drupal\Core\Database\Query\SelectInterface;
/**
* Base class for Migrate module source unit tests.
*/
@ -77,6 +79,7 @@ abstract class MigrateSqlSourceTestCase extends MigrateTestCase {
*/
protected function setUp() {
$module_handler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface');
$state = $this->getMock('Drupal\Core\State\StateInterface');
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
$migration = $this->getMigration();
@ -86,7 +89,7 @@ abstract class MigrateSqlSourceTestCase extends MigrateTestCase {
// Setup the plugin.
$plugin_class = static::PLUGIN_CLASS;
$plugin = new $plugin_class($this->migrationConfiguration['source'], $this->migrationConfiguration['source']['plugin'], array(), $migration, $entity_manager);
$plugin = new $plugin_class($this->migrationConfiguration['source'], $this->migrationConfiguration['source']['plugin'], array(), $migration, $state, $entity_manager);
// Do some reflection to set the database and moduleHandler.
$plugin_reflection = new \ReflectionClass($plugin);
@ -111,6 +114,7 @@ abstract class MigrateSqlSourceTestCase extends MigrateTestCase {
* Test the source returns the same rows as expected.
*/
public function testRetrieval() {
$this->assertInstanceOf(SelectInterface::class, $this->source->query());
$this->queryResultTest($this->source, $this->expectedResults);
}
@ -118,7 +122,16 @@ abstract class MigrateSqlSourceTestCase extends MigrateTestCase {
* Test the source returns the row count expected.
*/
public function testSourceCount() {
$this->assertEquals($this->source->count(), $this->expectedCount);
$count = $this->source->count();
$this->assertTrue(is_numeric($count));
$this->assertEquals($count, $this->expectedCount);
}
/**
* Test the source defines a valid ID.
*/
public function testSourceId() {
$this->assertNotEmpty($this->source->getIds());
}
/**

View file

@ -96,13 +96,13 @@ class MigrationTest extends UnitTestCase {
$migration_d = $this->getMock('Drupal\migrate\Entity\MigrationInterface');
$migration_b->expects($this->once())
->method('isComplete')
->method('allRowsProcessed')
->willReturn(TRUE);
$migration_c->expects($this->once())
->method('isComplete')
->method('allRowsProcessed')
->willReturn(FALSE);
$migration_d->expects($this->once())
->method('isComplete')
->method('allRowsProcessed')
->willReturn(TRUE);
$migration_storage = $this->getMock('Drupal\Core\Entity\EntityStorageInterface');

View file

@ -37,6 +37,9 @@ class ConfigTest extends UnitTestCase {
}
$config->expects($this->once())
->method('save');
$config->expects($this->once())
->method('getName')
->willReturn('d8_config');
$config_factory = $this->getMock('Drupal\Core\Config\ConfigFactoryInterface');
$config_factory->expects($this->once())
->method('getEditable')
@ -49,7 +52,8 @@ class ConfigTest extends UnitTestCase {
->method('getRawDestination')
->will($this->returnValue($source));
$destination = new Config(array('config_name' => 'd8_config'), 'd8_config', array('pluginId' => 'd8_config'), $migration, $config_factory);
$destination->import($row);
$destination_id = $destination->import($row);
$this->assertEquals($destination_id, ['d8_config']);
}
}