Update to Drupal 8.0.2. For more information, see https://www.drupal.org/drupal-8.0.2-release-notes

This commit is contained in:
Pantheon Automation 2016-01-06 16:31:26 -08:00 committed by Greg Anderson
parent 1a0e9d9fac
commit a6b049dd05
538 changed files with 5247 additions and 1594 deletions

View file

@ -45,7 +45,9 @@ class MigrateExecutableMemoryExceededTest extends MigrateTestCase {
);
/**
* php.init memory_limit value.
* The php.ini memory_limit value.
*
* @var int
*/
protected $memoryLimit = 10000000;
@ -68,12 +70,13 @@ class MigrateExecutableMemoryExceededTest extends MigrateTestCase {
* The second message to assert.
* @param bool $memory_exceeded
* Whether to test the memory exceeded case.
* @param int $memory_usage_first
* (optional) The first memory usage value.
* @param int $memory_usage_second
* @param int|null $memory_usage_first
* (optional) The first memory usage value. Defaults to NULL.
* @param int|null $memory_usage_second
* (optional) The fake amount of memory usage reported after memory reclaim.
* @param int $memory_limit
* (optional) The memory limit.
* Defaults to NULL.
* @param int|null $memory_limit
* (optional) The memory limit. Defaults to NULL.
*/
protected function runMemoryExceededTest($message, $memory_exceeded, $memory_usage_first = NULL, $memory_usage_second = NULL, $memory_limit = NULL) {
$this->executable->setMemoryLimit($memory_limit ?: $this->memoryLimit);

View file

@ -14,7 +14,7 @@ use Drupal\migrate\MigrateException;
use Drupal\migrate\Row;
/**
* @coversDefaultClass \Drupal\Tests\migrate\Unit\MigrateExecutableTest
* @coversDefaultClass \Drupal\migrate\MigrateExecutable
* @group migrate
*/
class MigrateExecutableTest extends MigrateTestCase {
@ -40,6 +40,11 @@ class MigrateExecutableTest extends MigrateTestCase {
*/
protected $executable;
/**
* The migration's configuration values.
*
* @var array
*/
protected $migrationConfiguration = array(
'id' => 'test',
);
@ -224,8 +229,9 @@ class MigrateExecutableTest extends MigrateTestCase {
}
/**
* Tests the import method with a MigrateException being thrown from the
* destination.
* Tests the import method with a thrown MigrateException.
*
* The MigrationException in this case is being thrown from the destination.
*/
public function testImportWithValidRowWithDestinationMigrateException() {
$exception_message = $this->getRandomGenerator()->string();
@ -275,8 +281,9 @@ class MigrateExecutableTest extends MigrateTestCase {
}
/**
* Tests the import method with a MigrateException being thrown from a process
* plugin.
* Tests the import method with a thrown MigrateException.
*
* The MigrationException in this case is being thrown from a process plugin.
*/
public function testImportWithValidRowWithProcesMigrateException() {
$exception_message = $this->getRandomGenerator()->string();
@ -421,6 +428,7 @@ class MigrateExecutableTest extends MigrateTestCase {
* Returns a mock migration source instance.
*
* @return \Drupal\migrate\Plugin\MigrateSourceInterface|\PHPUnit_Framework_MockObject_MockObject
* The mocked migration source.
*/
protected function getMockSource() {
$iterator = $this->getMock('\Iterator');

View file

@ -61,14 +61,16 @@ class MigrateSourceTest extends MigrateTestCase {
protected $executable;
/**
* Get the source plugin to test.
* Gets the source plugin to test.
*
* @param array $configuration
* The source configuration.
* (optional) The source configuration. Defaults to an empty array.
* @param array $migrate_config
* The migration configuration to be used in parent::getMigration().
* (optional) The migration configuration to be used in
* parent::getMigration(). Defaults to an empty array.
* @param int $status
* The default status for the new rows to be imported.
* (optional) The default status for the new rows to be imported. Defaults
* to MigrateIdMapInterface::STATUS_NEEDS_UPDATE.
*
* @return \Drupal\migrate\Plugin\MigrateSourceInterface
* A mocked source plugin.
@ -367,7 +369,7 @@ class MigrateSourceTest extends MigrateTestCase {
}
/**
* Get a mock executable for the test.
* Gets a mock executable for the test.
*
* @param \Drupal\migrate\Entity\MigrationInterface $migration
* The migration entity.
@ -394,8 +396,9 @@ class StubSourcePlugin extends SourcePluginBase {
* Helper for setting internal module handler implementation.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
function setModuleHandler(ModuleHandlerInterface $module_handler) {
public function setModuleHandler(ModuleHandlerInterface $module_handler) {
$this->moduleHandler = $module_handler;
}
@ -426,4 +429,5 @@ class StubSourcePlugin extends SourcePluginBase {
protected function initializeIterator() {
return [];
}
}

View file

@ -29,12 +29,22 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
'id' => 'sql_idmap_test',
];
/**
* The source IDs.
*
* @var array
*/
protected $sourceIds = [
'source_id_property' => [
'type' => 'string',
],
];
/**
* The destination IDs.
*
* @var array
*/
protected $destinationIds = [
'destination_id_property' => [
'type' => 'string',
@ -48,7 +58,10 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
*/
protected $database;
public function setUp() {
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->database = $this->getDatabase([]);
}
@ -56,7 +69,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
* Saves a single ID mapping row in the database.
*
* @param array $map
* The row to save.
* The row to save.
*/
protected function saveMap(array $map) {
$table = 'migrate_map_sql_idmap_test';
@ -114,6 +127,12 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
/**
* Sets defaults for SQL ID map plugin tests.
*
* @return array
* An associative array with the following keys:
* - source_row_status
* - rollback_action
* - hash
*/
protected function idMapDefaults() {
$defaults = array(
@ -351,6 +370,9 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
* - Multi-value source ID to multi-value destination ID.
* - Single-value source ID to multi-value destination ID.
* - Multi-value source ID to single-value destination ID.
*
* @return array
* An array of data values.
*/
public function lookupDestinationIdMappingDataProvider() {
return [
@ -368,6 +390,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
* Number of source fields to test.
* @param int $num_destination_fields
* Number of destination fields to test.
*
* @dataProvider lookupDestinationIdMappingDataProvider
*/
public function testLookupDestinationIdMapping($num_source_fields, $num_destination_fields) {
@ -435,6 +458,9 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
* - Multi-value destination ID to multi-value source ID.
* - Single-value destination ID to multi-value source ID.
* - Multi-value destination ID to single-value source ID.
*
* @return array
* An array of data values.
*/
public function lookupSourceIDMappingDataProvider() {
return [
@ -452,6 +478,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
* Number of source fields to test.
* @param int $num_destination_fields
* Number of destination fields to test.
*
* @dataProvider lookupSourceIDMappingDataProvider
*/
public function testLookupSourceIDMapping($num_source_fields, $num_destination_fields) {
@ -556,6 +583,9 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
* - No updates.
* - One update.
* - Multiple updates.
*
* @return array
* An array of data values.
*/
public function updateCountDataProvider() {
return [
@ -570,6 +600,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
*
* @param int $num_update_rows
* The number of update rows to test.
*
* @dataProvider updateCountDataProvider
*/
public function testUpdateCount($num_update_rows) {
@ -598,6 +629,9 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
* - No errors.
* - One error.
* - Multiple errors.
*
* @return array
* An array of data values.
*/
public function errorCountDataProvider() {
return [
@ -612,6 +646,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
*
* @param int $num_error_rows
* Number of error rows to test.
*
* @dataProvider errorCountDataProvider
*/
public function testErrorCount($num_error_rows) {
@ -731,7 +766,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
*/
public function testDestroy() {
$id_map = $this->getIdMap();
// Initialize the id map.
// Initialize the ID map.
$id_map->getDatabase();
$map_table_name = $id_map->mapTableName();
$message_table_name = $id_map->messageTableName();
@ -789,6 +824,12 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
$this->assertSame(iterator_to_array($this->getIdMap()), $expected_results);
}
/**
* Retrieves the contents of an ID map.
*
* @return array
* The contents of an ID map.
*/
private function getIdMapContents() {
$result = $this->database
->select('migrate_map_sql_idmap_test', 't')

View file

@ -111,7 +111,7 @@ abstract class MigrateSqlSourceTestCase extends MigrateTestCase {
}
/**
* Test the source returns the same rows as expected.
* Tests that the source returns the same rows as expected.
*/
public function testRetrieval() {
$this->assertInstanceOf(SelectInterface::class, $this->source->query());
@ -119,7 +119,7 @@ abstract class MigrateSqlSourceTestCase extends MigrateTestCase {
}
/**
* Test the source returns the row count expected.
* Tests that the source returns the row count expected.
*/
public function testSourceCount() {
$count = $this->source->count();
@ -128,16 +128,22 @@ abstract class MigrateSqlSourceTestCase extends MigrateTestCase {
}
/**
* Test the source defines a valid ID.
* Tests the source defines a valid ID.
*/
public function testSourceId() {
$this->assertNotEmpty($this->source->getIds());
}
/**
* Gets the value on a row for a given key.
*
* @param \Drupal\migrate\Row $row
* The row identifier.
* @param string $key
* The key identifier.
*
* @return mixed
* The value on a row for a given key.
*/
protected function getValue($row, $key) {
return $row->getSourceProperty($key);

View file

@ -17,9 +17,16 @@ use Drupal\Tests\UnitTestCase;
*/
abstract class MigrateTestCase extends UnitTestCase {
/**
* An array of migration configuration values.
*
* @var array
*/
protected $migrationConfiguration = [];
/**
* The migration ID map.
*
* @var \Drupal\migrate\Plugin\MigrateIdMapInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $idMap;
@ -32,7 +39,7 @@ abstract class MigrateTestCase extends UnitTestCase {
protected $migrationStatus = MigrationInterface::STATUS_IDLE;
/**
* Retrieve a mocked migration.
* Retrieves a mocked migration.
*
* @return \Drupal\migrate\Entity\MigrationInterface|\PHPUnit_Framework_MockObject_MockObject
* The mocked migration.
@ -83,8 +90,8 @@ abstract class MigrateTestCase extends UnitTestCase {
$migration->method('set')
->willReturnCallback(function ($argument, $value) use (&$configuration) {
$configuration[$argument] = $value;
});
$configuration[$argument] = $value;
});
$migration->method('id')
->willReturn($configuration['id']);
@ -93,13 +100,14 @@ abstract class MigrateTestCase extends UnitTestCase {
}
/**
* Get an SQLite database connection object for use in tests.
* Gets an SQLite database connection object for use in tests.
*
* @param array $database_contents
* The database contents faked as an array. Each key is a table name, each
* value is a list of table rows, an associative array of field => value.
* @param array $connection_options
* (optional) Options for the database connection.
* (optional) Options for the database connection. Defaults to an empty
* array.
*
* @return \Drupal\Core\Database\Driver\sqlite\Connection
* The database connection.
@ -136,23 +144,25 @@ abstract class MigrateTestCase extends UnitTestCase {
* Generates a table schema from a row.
*
* @param array $row
* The reference row on which to base the schema.
* The reference row on which to base the schema.
*
* @return array
* The Schema API-ready table schema.
* The Schema API-ready table schema.
*/
protected function createSchemaFromRow(array $row) {
// SQLite uses loose ("affinity") typing, so it's OK for every column
// to be a text field.
// SQLite uses loose ("affinity") typing, so it is OK for every column to be
// a text field.
$fields = array_map(function() { return ['type' => 'text']; }, $row);
return ['fields' => $fields];
}
/**
* Tests a query
* Tests a query.
*
* @param array|\Traversable
* @param array|\Traversable $iter
* The countable. foreach-able actual results if a query is being run.
* @param array $expected_results
* An array of expected results.
*/
public function queryResultTest($iter, $expected_results) {
$this->assertSame(count($expected_results), count($iter), 'Number of results match');
@ -168,9 +178,15 @@ abstract class MigrateTestCase extends UnitTestCase {
}
/**
* Gets the value on a row for a given key.
*
* @param array $row
* The row information.
* @param string $key
* The key identifier.
*
* @return mixed
* The value on a row for a given key.
*/
protected function getValue($row, $key) {
return $row[$key];

View file

@ -23,11 +23,15 @@ use Drupal\Tests\UnitTestCase;
class MigrationStorageTest extends UnitTestCase {
/**
* The migration storage.
*
* @var \Drupal\Tests\migrate\Unit\TestMigrationStorage
*/
protected $storage;
/**
* The storage query.
*
* @var \Drupal\Core\Entity\Query\QueryInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $query;
@ -35,7 +39,7 @@ class MigrationStorageTest extends UnitTestCase {
/**
* {@inheritdoc}
*/
public function setUp() {
protected function setUp() {
$this->query = $this->getMock(QueryInterface::class);
$this->query->method('condition')
->willReturnSelf();
@ -63,7 +67,7 @@ class MigrationStorageTest extends UnitTestCase {
->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);
$this->assertSame(['d6_node__page', 'd6_node__article', 'd6_user'], $ids);
}
/**
@ -76,11 +80,13 @@ class MigrationStorageTest extends UnitTestCase {
->willReturn([]);
$ids = $this->storage->getVariantIds(['d6_node:*', 'd6_user']);
$this->assertSame(['d6_user'], $ids);
$this->assertSame(['d6_user'], $ids);
}
/**
* Tests getVariantIds() when no variants exist and there are no static
* Tests getVariantIds().
*
* This tests getVariantIds() when no variants exist and there are no static
* (non-variant) dependencies.
*
* @covers ::getVariantIds
@ -90,7 +96,7 @@ class MigrationStorageTest extends UnitTestCase {
->willReturn([]);
$ids = $this->storage->getVariantIds(['d6_node:*', 'd6_node_revision:*']);
$this->assertSame([], $ids);
$this->assertSame([], $ids);
}
}
@ -98,7 +104,7 @@ class MigrationStorageTest extends UnitTestCase {
/**
* Test version of \Drupal\migrate\MigrationStorage.
*
* Exposes protected methods for testing.
* This class exposes protected methods for testing.
*/
class TestMigrationStorage extends MigrationStorage {

View file

@ -120,29 +120,65 @@ class MigrationTest extends UnitTestCase {
}
/**
* Defines the TestMigration class.
*/
class TestMigration extends Migration {
/**
* Constructs an instance of TestMigration object.
*/
public function __construct() {
}
/**
* Sets the requirements values.
*
* @param array $requirements
* The array of requirement values.
*/
public function setRequirements(array $requirements) {
$this->requirements = $requirements;
}
/**
* Sets the source Plugin.
*
* @param \Drupal\migrate\Plugin\MigrateSourceInterface $source_plugin
* The source Plugin.
*/
public function setSourcePlugin(MigrateSourceInterface $source_plugin) {
$this->sourcePlugin = $source_plugin;
}
/**
* Sets the destination Plugin.
*
* @param \Drupal\migrate\Plugin\MigrateDestinationInterface $destination_plugin
* The destination Plugin.
*/
public function setDestinationPlugin(MigrateDestinationInterface $destination_plugin) {
$this->destinationPlugin = $destination_plugin;
}
/**
* Sets the entity manager service.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager service.
*/
public function setEntityManager(EntityManagerInterface $entity_manager) {
$this->entityManager = $entity_manager;
}
}
/**
* Defines the RequirementsAwareSourceInterface.
*/
interface RequirementsAwareSourceInterface extends MigrateSourceInterface, RequirementsInterface {}
/**
* Defines the RequirementsAwareDestinationInterface.
*/
interface RequirementsAwareDestinationInterface extends MigrateDestinationInterface, RequirementsInterface {}

View file

@ -43,7 +43,7 @@ class EntityContentBaseTest extends UnitTestCase {
/**
* {@inheritdoc}
*/
public function setUp() {
protected function setUp() {
parent::setUp();
$this->migration = $this->prophesize(MigrationInterface::class);

View file

@ -18,16 +18,20 @@ use Drupal\Tests\UnitTestCase;
class SqlBaseTest extends UnitTestCase {
/**
* Tests that the ID map is joinable.
*
* @param bool $expected_result
* The expected result.
* @param bool $id_map_is_sql
* TRUE if we want getIdMap() to return an instance of Sql.
* @param bool $with_id_map
* TRUE if we want the id map to have a valid map of ids.
* TRUE if we want the ID map to have a valid map of IDs.
* @param array $source_options
* An array of connection options for the source connection.
* (optional) An array of connection options for the source connection.
* Defaults to an empty array.
* @param array $idmap_options
* An array of connection options for the id map connection.
* (optional) An array of connection options for the ID map connection.
* Defaults to an empty array.
*
* @dataProvider sqlBaseTestProvider
*/
@ -40,7 +44,7 @@ class SqlBaseTest extends UnitTestCase {
->method('getConnectionOptions')
->willReturn($source_options);
// Setup the id map connection.
// Setup the ID map connection.
$idmap_connection = $this->getMockBuilder('Drupal\Core\Database\Connection')
->disableOriginalConstructor()
->getMock();
@ -86,22 +90,56 @@ class SqlBaseTest extends UnitTestCase {
public function sqlBaseTestProvider() {
return [
// Source ids are empty so mapJoinable() is false.
[FALSE, FALSE, FALSE],
[
FALSE,
FALSE,
FALSE,
],
// Still false because getIdMap() is not a subclass of Sql.
[FALSE, FALSE, TRUE],
[
FALSE,
FALSE,
TRUE,
],
// Test mapJoinable() returns false when source and id connection options
// differ.
[FALSE, TRUE, TRUE, ['username' => 'different_from_map', 'password' => 'different_from_map'], ['username' => 'different_from_source', 'password' => 'different_from_source']],
[
FALSE,
TRUE,
TRUE,
['username' => 'different_from_map', 'password' => 'different_from_map'],
['username' => 'different_from_source', 'password' => 'different_from_source'],
],
// Returns true because source and id map connection options are the same.
[TRUE, TRUE, TRUE, ['username' => 'same_value', 'password' => 'same_value'], ['username' => 'same_value', 'password' => 'same_value']],
[
TRUE,
TRUE,
TRUE,
['username' => 'same_value', 'password' => 'same_value'],
['username' => 'same_value', 'password' => 'same_value'],
],
];
}
}
/**
* Creates a base source class for SQL migration testing.
*/
class TestSqlBase extends SqlBase {
/**
* The database object.
*
* @var object
*/
protected $database;
/**
* The migration IDs.
*
* @var array
*/
protected $ids;
/**
@ -151,7 +189,10 @@ class TestSqlBase extends SqlBase {
}
/**
* Allows us to set the ids during a test.
* Allows us to set the IDs during a test.
*
* @param array $ids
* An array of identifiers.
*/
public function setIds($ids) {
$this->ids = $ids;

View file

@ -53,7 +53,7 @@ class TestMigrateExecutable extends MigrateExecutable {
* Allows access to protected sourceIdValues property.
*
* @param array $source_id_values
* The value to set.
* The values to set.
*/
public function setSourceIdValues($source_id_values) {
$this->sourceIdValues = $source_id_values;
@ -100,7 +100,7 @@ class TestMigrateExecutable extends MigrateExecutable {
* @param int $memory_usage
* The fake memory usage value.
* @param int $cleared_memory_usage
* (optional) The fake cleared memory value.
* (optional) The fake cleared memory value. Defaults to NULL.
*/
public function setMemoryUsage($memory_usage, $cleared_memory_usage = NULL) {
$this->memoryUsage = $memory_usage;

View file

@ -31,6 +31,8 @@ class TestSqlIdMap extends Sql implements \Iterator {
* The configuration for the plugin.
* @param \Drupal\migrate\Entity\MigrationInterface $migration
* The migration to do.
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
* The event dispatcher service.
*/
public function __construct(Connection $database, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EventDispatcherInterface $event_dispatcher) {
$this->database = $database;
@ -44,6 +46,18 @@ class TestSqlIdMap extends Sql implements \Iterator {
return parent::getDatabase();
}
/**
* Gets the field schema.
*
* @param array $id_definition
* An array defining the field, with a key 'type'.
*
* @return array
* A field schema depending on value of key 'type'. An empty array is
* returned if 'type' is not defined.
*
* @throws \Drupal\migrate\MigrateException
*/
protected function getFieldSchema(array $id_definition) {
if (!isset($id_definition['type'])) {
return array();
@ -54,14 +68,17 @@ class TestSqlIdMap extends Sql implements \Iterator {
'type' => 'int',
'not null' => TRUE,
);
case 'string':
return array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
);
default:
throw new MigrateException($id_definition['type'] . ' not supported');
}
}
}

View file

@ -41,7 +41,7 @@ class EntityRevisionTest extends UnitTestCase {
*/
protected $fieldTypeManager;
public function setUp() {
protected function setUp() {
parent::setUp();
// Setup mocks to be used when creating a revision destination.