#71: Remove files no longer part of Drupal core in Drupal 8.0.0-beta15.

This commit is contained in:
Pantheon Automation 2015-09-15 11:47:45 -07:00 committed by Greg Anderson
parent f3791f1da3
commit 1ebe18adc2
101 changed files with 0 additions and 9459 deletions

View file

@ -1,236 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\MigrationStorage.
*/
namespace Drupal\migrate_drupal;
use Drupal\Component\Uuid\UuidInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\migrate\Plugin\migrate\source\SourcePluginBase;
use Drupal\migrate_drupal\Plugin\CckFieldMigrateSourceInterface;
use Drupal\migrate\MigrationStorage as BaseMigrationStorage;
use Drupal\migrate\Plugin\MigratePluginManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Storage for migration entities.
*/
class MigrationStorage extends BaseMigrationStorage {
/**
* A cached array of cck field plugins.
*
* @var array
*/
protected $cckFieldPlugins;
/**
* @var \Drupal\migrate_drupal\Plugin\MigratePluginManager
*/
protected $cckPluginManager;
/**
* Constructs a MigrationStorage object.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory service.
* @param \Drupal\Component\Uuid\UuidInterface $uuid_service
* The UUID service.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
* @param \Drupal\migrate_drupal\Plugin\MigratePluginManager
* The cckfield plugin manager.
*/
public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, MigratePluginManager $cck_plugin_manager) {
parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager);
$this->cckPluginManager = $cck_plugin_manager;
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static(
$entity_type,
$container->get('config.factory'),
$container->get('uuid'),
$container->get('language_manager'),
$container->get('plugin.manager.migrate.cckfield')
);
}
/**
* {@inheritdoc}
*/
public function loadMultiple(array $ids = NULL) {
$ids_to_load = array();
$dynamic_ids = array();
if (isset($ids)) {
foreach ($ids as $id) {
// Evaluate whether or not this migration is dynamic in the form of
// migration_id:* to load all the additional migrations.
if (($n = strpos($id, ':')) !== FALSE) {
$base_id = substr($id, 0, $n);
$ids_to_load[] = $base_id;
// Get the ids of the additional migrations.
$sub_id = substr($id, $n + 1);
if ($sub_id == '*') {
// If the id of the additional migration is '*', get all of them.
$dynamic_ids[$base_id] = NULL;
}
elseif (!isset($dynamic_ids[$base_id]) || is_array($dynamic_ids[$base_id])) {
$dynamic_ids[$base_id][] = $sub_id;
}
}
else {
$ids_to_load[] = $id;
}
}
$ids = array_flip($ids);
}
else {
$ids_to_load = NULL;
}
/** @var \Drupal\migrate_drupal\Entity\MigrationInterface[] $entities */
$entities = parent::loadMultiple($ids_to_load);
if (!isset($ids)) {
// Changing the array being foreach()'d is not a good idea.
$return = array();
foreach ($entities as $entity_id => $entity) {
if ($plugin = $entity->getLoadPlugin()) {
$new_entities = $plugin->loadMultiple($this);
$this->postLoad($new_entities);
$this->getDynamicIds($dynamic_ids, $new_entities);
$return += $new_entities;
}
else {
$return[$entity_id] = $entity;
}
}
$entities = $return;
}
else {
foreach ($dynamic_ids as $base_id => $sub_ids) {
$entity = $entities[$base_id];
if ($plugin = $entity->getLoadPlugin()) {
unset($entities[$base_id]);
$new_entities = $plugin->loadMultiple($this, $sub_ids);
$this->postLoad($new_entities);
if (!isset($sub_ids)) {
unset($dynamic_ids[$base_id]);
$this->getDynamicIds($dynamic_ids, $new_entities);
}
$entities += $new_entities;
}
}
}
// Allow modules providing cck field plugins to alter the required
// migrations to assist with the migration a custom field type.
$this->applyCckFieldProcessors($entities);
// Build an array of dependencies and set the order of the migrations.
return $this->buildDependencyMigration($entities, $dynamic_ids);
}
/**
* Extract the dynamic id mapping from entities loaded by plugin.
*
* @param array $dynamic_ids
* Get the dynamic migration ids.
* @param array $entities
* An array of entities.
*/
protected function getDynamicIds(array &$dynamic_ids, array $entities) {
foreach (array_keys($entities) as $new_id) {
list($base_id, $sub_id) = explode(':', $new_id, 2);
$dynamic_ids[$base_id][] = $sub_id;
}
}
/**
* {@inheritdoc}
*/
public function save(EntityInterface $entity) {
if (strpos($entity->id(), ':') !== FALSE) {
throw new EntityStorageException("Dynamic migration '{$entity->id()}' can't be saved");
}
return parent::save($entity);
}
/**
* Allow any field type plugins to adjust the migrations as required.
*
* @param \Drupal\migrate\Entity\Migration[] $entities
* An array of migration entities.
*/
protected function applyCckFieldProcessors(array $entities) {
$method_map = $this->getMigrationPluginMethodMap();
foreach ($entities as $entity_id => $migration) {
// Allow field plugins to process the required migrations.
if (isset($method_map[$entity_id])) {
$method = $method_map[$entity_id];
$cck_plugins = $this->getCckFieldPlugins();
array_walk($cck_plugins, function ($plugin) use ($method, $migration) {
$plugin->$method($migration);
});
}
// If this is a CCK bundle migration, allow the cck field plugins to add
// any field type processing.
$source_plugin = $migration->getSourcePlugin();
if ($source_plugin instanceof CckFieldMigrateSourceInterface && strpos($entity_id, SourcePluginBase::DERIVATIVE_SEPARATOR)) {
$plugins = $this->getCckFieldPlugins();
foreach ($source_plugin->fieldData() as $field_name => $data) {
if (isset($plugins[$data['type']])) {
$plugins[$data['type']]->processCckFieldValues($migration, $field_name, $data);
}
}
}
}
}
/**
* Get an array of loaded cck field plugins.
*
* @return \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface[]
* An array of cck field process plugins.
*/
protected function getCckFieldPlugins() {
if (!isset($this->cckFieldPlugins)) {
$this->cckFieldPlugins = [];
foreach ($this->cckPluginManager->getDefinitions() as $definition) {
$this->cckFieldPlugins[$definition['id']] = $this->cckPluginManager->createInstance($definition['id']);
}
}
return $this->cckFieldPlugins;
}
/**
* Provides a map between migration ids and the cck field plugin method.
*
* @return array
* The map between migrations and cck field plugin processing methods.
*/
protected function getMigrationPluginMethodMap() {
return [
'd6_field' => 'processField',
'd6_field_instance' => 'processFieldInstance',
'd6_field_instance_widget_settings' => 'processFieldWidget',
'd6_field_formatter_settings' => 'processFieldFormatter',
];
}
}

View file

@ -1,24 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Plugin\CckFieldMigrateSourceInterface.
*/
namespace Drupal\migrate_drupal\Plugin;
use Drupal\migrate\Plugin\MigrateSourceInterface;
/**
* Defines an interface for cck field sources that need per type processing.
*/
interface CckFieldMigrateSourceInterface extends MigrateSourceInterface {
/**
* Field data used for determining the field type in the LoadEntity
*
* @return mixed
* An array of cck field data.
*/
public function fieldData();
}

View file

@ -1,45 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Plugin\MigrateLoadInterface.
*/
namespace Drupal\migrate_drupal\Plugin;
use Drupal\Component\Plugin\PluginInspectionInterface;
use Drupal\Core\Entity\EntityStorageInterface;
/**
* Defines an interface for migration load plugins.
*
* @see \Drupal\migrate_drupal\Plugin\migrate\load\LoadEntity
*
* @ingroup migration
*/
interface MigrateLoadInterface extends PluginInspectionInterface {
/**
* Load an additional migration.
*
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The migration storage.
* @param string $sub_id
* For example, when loading d6_node:article, this will be article.
* @return \Drupal\migrate\Entity\MigrationInterface
*/
public function load(EntityStorageInterface $storage, $sub_id);
/**
* Load additional migrations.
*
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The migration storage.
* @param array $sub_ids
* For example, when loading d6_node:article, sub_id will be article.
* If NULL then load all sub-migrations.
* @return \Drupal\migrate\Entity\MigrationInterface[]
*/
public function loadMultiple(EntityStorageInterface $storage, array $sub_ids = NULL);
}

View file

@ -1,55 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Plugin\migrate\cckfield\FileField.
*/
namespace Drupal\migrate_drupal\Plugin\migrate\cckfield;
use Drupal\migrate\Entity\MigrationInterface;
/**
* @PluginID("filefield")
*/
class FileField extends CckFieldPluginBase {
/**
* {@inheritdoc}
*/
public function getFieldWidgetMap() {
return [
'filefield_widget' => 'file_generic',
];
}
/**
* {@inheritdoc}
*/
public function getFieldFormatterMap() {
return [
'default' => 'file_default',
'url_plain' => 'file_url_plain',
'path_plain' => 'file_url_plain',
'image_plain' => 'image',
'image_nodelink' => 'image',
'image_imagelink' => 'image',
];
}
/**
* {@inheritdoc}
*/
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {
$process = [
'plugin' => 'd6_cck_file',
'source' => [
$field_name,
$field_name . '_list',
$field_name . '_data',
],
];
$migration->mergeProcessOfProperty($field_name, $process);
}
}

View file

@ -1,50 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Plugin\migrate\cckfield\LinkField.
*/
namespace Drupal\migrate_drupal\Plugin\migrate\cckfield;
use Drupal\migrate\Entity\MigrationInterface;
/**
* @PluginID("link")
*/
class LinkField extends CckFieldPluginBase {
/**
* {@inheritdoc}
*/
public function getFieldFormatterMap() {
// See d6_field_formatter_settings.yml and CckFieldPluginBase
// processFieldFormatter().
return [
'default' => 'link',
'plain' => 'link',
'absolute' => 'link',
'title_plain' => 'link',
'url' => 'link',
'short' => 'link',
'label' => 'link',
'separate' => 'link_separate',
];
}
/**
* {@inheritdoc}
*/
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {
$process = [
'plugin' => 'd6_cck_link',
'source' => [
$field_name,
$field_name . '_title',
$field_name . '_attributes',
],
];
$migration->mergeProcessOfProperty($field_name, $process);
}
}

View file

@ -1,71 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Plugin\migrate\cckfield\TextField.
*/
namespace Drupal\migrate_drupal\Plugin\migrate\cckfield;
use Drupal\migrate\Entity\MigrationInterface;
/**
* @PluginID("text")
*/
class TextField extends CckFieldPluginBase {
/**
* {@inheritdoc}
*/
public function getFieldWidgetMap() {
return [
'text_textfield' => 'text_textfield',
];
}
/**
* {@inheritdoc}
*/
public function getFieldFormatterMap() {
return [
'default' => 'text_default',
'trimmed' => 'text_trimmed',
'plain' => 'basic_string',
];
}
/**
* {@inheritdoc}
*/
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {
// The data is stored differently depending on whether we're using
// db storage.
$value_key = $data['db_storage'] ? $field_name : "$field_name/value";
$format_key = $data['db_storage'] ? $field_name . '_format' : "$field_name/format" ;
$migration->setProcessOfProperty("$field_name/value", $value_key);
// See \Drupal\migrate_drupal\Plugin\migrate\source\d6\User::baseFields(),
// signature_format for an example of the YAML that represents this
// process array.
$process = [
[
'plugin' => 'static_map',
'bypass' => TRUE,
'source' => $format_key,
'map' => [0 => NULL]
],
[
'plugin' => 'skip_on_empty',
'method' => 'process',
],
[
'plugin' => 'migration',
'migration' => 'd6_filter_format',
'source' => $format_key,
],
];
$migration->mergeProcessOfProperty("$field_name/format", $process);
}
}

View file

@ -1,84 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateCckFieldRevisionTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\migrate\MigrateExecutable;
use Drupal\node\Tests\Migrate\d6\MigrateNodeTestBase;
/**
* CCK field revision migration.
*
* @group migrate_drupal
*/
class MigrateCckFieldRevisionTest extends MigrateNodeTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('field', 'filter', 'node', 'text');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
entity_create('field_storage_config', array(
'entity_type' => 'node',
'field_name' => 'field_test',
'type' => 'text',
))->save();
entity_create('field_config', array(
'entity_type' => 'node',
'field_name' => 'field_test',
'bundle' => 'story',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'node',
'field_name' => 'field_test_two',
'type' => 'integer',
'cardinality' => -1,
))->save();
entity_create('field_config', array(
'entity_type' => 'node',
'field_name' => 'field_test_two',
'bundle' => 'story',
))->save();
// Add some id mappings for the dependant migrations.
$id_mappings = array(
'd6_cck_field_values' => array(
array(array(1), array(1)),
),
'd6_node' => array(
array(array(1), array(1)),
array(array(2), array(2)),
),
'd6_node_revision' => array(
array(array(1), array(1)),
),
);
$this->prepareMigrations($id_mappings);
$migrations = entity_load_multiple('migration', array('d6_cck_field_revision:*'));
foreach ($migrations as $migration) {
$executable = new MigrateExecutable($migration, $this);
$executable->import();
}
}
/**
* Test CCK revision migration from Drupal 6 to 8.
*/
public function testCckFieldRevision() {
$node = \Drupal::entityManager()->getStorage('node')->loadRevision(2);
$this->assertIdentical('1', $node->id(), 'Node 1 loaded.');
$this->assertIdentical('2', $node->getRevisionId(), 'Node 1 revision 2loaded.');
}
}

View file

@ -1,210 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateCckFieldValuesTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\migrate\MigrateExecutable;
use Drupal\node\Entity\Node;
use Drupal\node\Tests\Migrate\d6\MigrateNodeTestBase;
/**
* CCK field content migration.
*
* @group migrate_drupal
*/
class MigrateCckFieldValuesTest extends MigrateNodeTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('node', 'text', 'filter', 'link', 'file');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('file');
entity_create('field_storage_config', array(
'entity_type' => 'node',
'field_name' => 'field_test',
'type' => 'text',
))->save();
entity_create('field_config', array(
'entity_type' => 'node',
'field_name' => 'field_test',
'bundle' => 'story',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'node',
'field_name' => 'field_test_two',
'type' => 'integer',
'cardinality' => -1,
))->save();
entity_create('field_config', array(
'entity_type' => 'node',
'field_name' => 'field_test_two',
'bundle' => 'story',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'node',
'field_name' => 'field_test_three',
'type' => 'decimal',
))->save();
entity_create('field_config', array(
'entity_type' => 'node',
'field_name' => 'field_test_three',
'bundle' => 'story',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'node',
'field_name' => 'field_test_integer_selectlist',
'type' => 'integer',
))->save();
entity_create('field_config', array(
'entity_type' => 'node',
'field_name' => 'field_test_integer_selectlist',
'bundle' => 'story',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'node',
'field_name' => 'field_test_exclude_unset',
'type' => 'text',
))->save();
entity_create('field_config', array(
'entity_type' => 'node',
'field_name' => 'field_test_exclude_unset',
'bundle' => 'story',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'node',
'field_name' => 'field_multivalue',
'type' => 'decimal',
'precision' => '10',
'scale' => '2',
'cardinality' => -1,
))->save();
entity_create('field_config', array(
'entity_type' => 'node',
'field_name' => 'field_multivalue',
'bundle' => 'test_planet',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'node',
'field_name' => 'field_test_identical1',
'type' => 'integer',
))->save();
entity_create('field_config', array(
'entity_type' => 'node',
'field_name' => 'field_test_identical1',
'bundle' => 'story',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'node',
'field_name' => 'field_test_identical2',
'type' => 'integer',
))->save();
entity_create('field_config', array(
'entity_type' => 'node',
'field_name' => 'field_test_identical2',
'bundle' => 'story',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'node',
'field_name' => 'field_test_link',
'type' => 'link',
))->save();
entity_create('field_config', array(
'entity_type' => 'node',
'field_name' => 'field_test_link',
'bundle' => 'story',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'node',
'field_name' => 'field_test_filefield',
'type' => 'file',
))->save();
entity_create('field_config', array(
'entity_type' => 'node',
'field_name' => 'field_test_filefield',
'bundle' => 'story',
))->save();
// Add some id mappings for the dependant migrations.
$id_mappings = array(
'd6_field_formatter_settings' => array(
array(array('page', 'default', 'node', 'field_test'), array('node', 'page', 'default', 'field_test')),
),
'd6_field_instance_widget_settings' => array(
array(array('page', 'field_test'), array('node', 'page', 'default', 'test')),
),
'd6_node' => array(
array(array(1), array(1)),
array(array(2), array(2)),
array(array(3), array(3)),
),
);
$this->prepareMigrations($id_mappings);
$migrations = entity_load_multiple('migration', array('d6_cck_field_values:*'));
foreach ($migrations as $migration) {
$executable = new MigrateExecutable($migration, $this);
$executable->import();
}
}
/**
* Test CCK migration from Drupal 6 to 8.
*/
public function testCckFields() {
$node = Node::load(1);
$this->assertIdentical('This is a shared text field', $node->field_test->value);
$this->assertIdentical('filtered_html', $node->field_test->format);
$this->assertIdentical('10', $node->field_test_two->value);
$this->assertIdentical('20', $node->field_test_two[1]->value);
$this->assertIdentical('42.42', $node->field_test_three->value, 'Single field second value is correct.');
$this->assertIdentical('3412', $node->field_test_integer_selectlist[0]->value);
$this->assertIdentical('1', $node->field_test_identical1->value, 'Integer value is correct');
$this->assertIdentical('1', $node->field_test_identical2->value, 'Integer value is correct');
$this->assertIdentical('This is a field with exclude unset.', $node->field_test_exclude_unset->value, 'Field with exclude unset is correct.');
// Test that link fields are migrated.
$this->assertIdentical('https://www.drupal.org/project/drupal', $node->field_test_link->uri);
$this->assertIdentical('Drupal project page', $node->field_test_link->title);
$this->assertIdentical(['target' => '_blank'], $node->field_test_link->options['attributes']);
// Test the file field meta.
$this->assertIdentical('desc', $node->field_test_filefield->description);
$this->assertIdentical('5', $node->field_test_filefield->target_id);
$planet_node = Node::load(3);
$value_1 = $planet_node->field_multivalue->value;
$value_2 = $planet_node->field_multivalue[1]->value;
// SQLite does not support scales for float data types so we need to convert
// the value manually.
if ($this->container->get('database')->driver() == 'sqlite') {
$value_1 = sprintf('%01.2f', $value_1);
$value_2 = sprintf('%01.2f', $value_2);
}
$this->assertIdentical('33.00', $value_1);
$this->assertIdentical('44.00', $value_2);
}
}

View file

@ -1,96 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateCommentTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\comment\Tests\CommentTestTrait;
/**
* Upgrade comments.
*
* @group migrate_drupal
*/
class MigrateCommentTest extends MigrateDrupal6TestBase {
use CommentTestTrait;
static $modules = array('node', 'comment', 'text', 'filter');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('node');
$this->installEntitySchema('comment');
$this->installConfig(['node', 'comment']);
entity_create('node_type', array('type' => 'page'))->save();
entity_create('node_type', array('type' => 'story'))->save();
$this->addDefaultCommentField('node', 'story');
$this->container->get('entity.manager')->getStorage('comment_type')->create(array(
'id' => 'comment_no_subject',
'label' => 'comment_no_subject',
'target_entity_type_id' => 'node',
))->save();
\Drupal::service('comment.manager')->addBodyField('comment_no_subject');
$node = entity_create('node', array(
'type' => 'story',
'nid' => 1,
));
$node->enforceIsNew();
$node->save();
$id_mappings = array(
'd6_filter_format' => array(array(array(1), array('filtered_html'))),
'd6_node' => array(array(array(1), array(1))),
'd6_user' => array(array(array(0), array(0))),
'd6_comment_type' => array(array(array('comment'), array('comment_no_subject'))),
'd6_comment_entity_display' => array(array(array('story'), array('node', 'story', 'default', 'comment'))),
'd6_comment_entity_form_display' => array(array(array('story'), array('node', 'story', 'default', 'comment'))),
);
$this->prepareMigrations($id_mappings);
$this->loadDumps([
'Node.php',
'NodeRevisions.php',
'ContentTypeStory.php',
'ContentTypeTestPlanet.php',
'Variable.php',
'NodeType.php',
'Comments.php',
]);
$this->executeMigration('d6_comment');
}
/**
* Tests the Drupal 6 to Drupal 8 comment migration.
*/
public function testComments() {
/** @var \Drupal\Core\Entity\EntityStorageInterface $comment_storage */
$comment_storage = $this->container->get('entity.manager')->getStorage('comment');
/** @var \Drupal\comment\CommentInterface $comment */
$comment = $comment_storage->load(1);
$this->assertIdentical('The first comment.', $comment->getSubject());
$this->assertIdentical('The first comment body.', $comment->comment_body->value);
$this->assertIdentical('filtered_html', $comment->comment_body->format);
$this->assertIdentical('0', $comment->pid->target_id);
$this->assertIdentical('1', $comment->getCommentedEntityId());
$this->assertIdentical('node', $comment->getCommentedEntityTypeId());
$this->assertIdentical('en', $comment->language()->getId());
$this->assertIdentical('comment_no_subject', $comment->getTypeId());
$comment = $comment_storage->load(2);
$this->assertIdentical('The response to the second comment.', $comment->subject->value);
$this->assertIdentical('3', $comment->pid->target_id);
$comment = $comment_storage->load(3);
$this->assertIdentical('The second comment.', $comment->subject->value);
$this->assertIdentical('0', $comment->pid->target_id);
}
}

View file

@ -1,45 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateCommentTypeTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\comment\Entity\CommentType;
/**
* Upgrade comment type.
*
* @group migrate_drupal
*/
class MigrateCommentTypeTest extends MigrateDrupal6TestBase {
static $modules = array('node', 'comment', 'text', 'filter');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('node');
$this->installEntitySchema('comment');
$this->installConfig(['node', 'comment']);
$this->loadDumps(['Variable.php', 'NodeType.php']);
$this->executeMigration('d6_comment_type');
}
/**
* Tests the Drupal 6 to Drupal 8 comment type migration.
*/
public function testCommentType() {
$comment_type = CommentType::load('comment');
$this->assertIdentical('node', $comment_type->getTargetEntityTypeId());
$comment_type = CommentType::load('comment_no_subject');
$this->assertIdentical('node', $comment_type->getTargetEntityTypeId());
}
}

View file

@ -1,70 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateCommentVariableDisplayBase.
*/
namespace Drupal\migrate_drupal\Tests\d6;
/**
* Base class for Drupal 6 comment variables to Drupal 8 entity display tests.
*/
abstract class MigrateCommentVariableDisplayBase extends MigrateDrupal6TestBase {
/**
* The ID of migration to run.
*
* This constant needs to be set in the concrete class in order for the test
* to work.
*/
const MIGRATION = '';
/**
* Modules to enable.
*
* @var array
*/
static $modules = array('comment', 'node');
/**
* The node types being tested.
*
* @var array
*/
protected $types = array('page', 'story', 'article');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
entity_create('field_storage_config', array(
'entity_type' => 'node',
'field_name' => 'comment',
'type' => 'comment',
'translatable' => '0',
))->save();
foreach ($this->types as $type) {
entity_create('node_type', array('type' => $type))->save();
entity_create('field_config', array(
'label' => 'Comments',
'description' => '',
'field_name' => 'comment',
'entity_type' => 'node',
'bundle' => $type,
'required' => 1,
))->save();
}
$id_mappings = array(
'd6_comment_field_instance' => array(
array(array('page'), array('node', 'comment', 'page')),
),
);
$this->prepareMigrations($id_mappings);
$this->loadDumps(['Variable.php', 'NodeType.php']);
$this->executeMigration(static::MIGRATION);
}
}

View file

@ -1,38 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateCommentVariableEntityDisplayTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
/**
* Upgrade comment variables to entity.display.node.*.default.yml.
*
* @group migrate_drupal
*/
class MigrateCommentVariableEntityDisplayTest extends MigrateCommentVariableDisplayBase {
/**
* The migration to run.
*/
const MIGRATION = 'd6_comment_entity_display';
/**
* The node types being used.
*/
protected $types = array('page', 'story', 'article');
/**
* Tests comment variables migrated into an entity display.
*/
public function testCommentEntityDisplay() {
foreach ($this->types as $type) {
$component = entity_get_display('node', $type, 'default')->getComponent('comment');
$this->assertIdentical('hidden', $component['label']);
$this->assertIdentical('comment_default', $component['type']);
$this->assertIdentical(20, $component['weight']);
}
}
}

View file

@ -1,60 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateCommentVariableEntityFormDisplaySubjectTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
/**
* Upgrade comment subject variable to core.entity_form_display.comment.*.default.yml
*
* @group migrate_drupal
*/
class MigrateCommentVariableEntityFormDisplaySubjectTest extends MigrateDrupal6TestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('comment', 'node');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
foreach (['comment', 'comment_no_subject'] as $comment_type) {
entity_create('comment_type', array(
'id' => $comment_type,
'target_entity_type_id' => 'node',
))
->save();
}
// Add some id mappings for the dependant migrations.
$id_mappings = array(
'd6_comment_type' => array(
array(array('comment'), array('comment_no_subject')),
),
);
$this->prepareMigrations($id_mappings);
$this->loadDumps(['Variable.php', 'NodeType.php']);
$this->executeMigration('d6_comment_entity_form_display_subject');
}
/**
* Tests comment subject variable migrated into an entity display.
*/
public function testCommentEntityFormDisplay() {
$component = entity_get_form_display('comment', 'comment', 'default')
->getComponent('subject');
$this->assertIdentical('string_textfield', $component['type']);
$this->assertIdentical(10, $component['weight']);
$component = entity_get_form_display('comment', 'comment_no_subject', 'default')
->getComponent('subject');
$this->assertNull($component);
}
}

View file

@ -1,33 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateCommentVariableEntityFormDisplayTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
/**
* Upgrade comment variables to core.entity_form_display.node.*.default.yml.
*
* @group migrate_drupal
*/
class MigrateCommentVariableEntityFormDisplayTest extends MigrateCommentVariableDisplayBase {
/**
* The migration to run.
*/
const MIGRATION = 'd6_comment_entity_form_display';
/**
* Tests comment variables migrated into an entity display.
*/
public function testCommentEntityFormDisplay() {
foreach ($this->types as $type) {
$component = entity_get_form_display('node', $type, 'default')->getComponent('comment');
$this->assertIdentical('comment_default', $component['type']);
$this->assertIdentical(20, $component['weight']);
}
}
}

View file

@ -1,54 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateCommentVariableFieldTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Upgrade comment variables to field.storage.node.comment.yml.
*
* @group migrate_drupal
*/
class MigrateCommentVariableFieldTest extends MigrateDrupal6TestBase {
static $modules = array('comment', 'node');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
foreach (array('page', 'story', 'test') as $type) {
entity_create('node_type', array('type' => $type))->save();
}
foreach (['comment', 'comment_no_subject'] as $comment_type) {
entity_create('comment_type', array(
'id' => $comment_type,
'target_entity_type_id' => 'node',
))
->save();
}
// Add some id mappings for the dependant migrations.
$id_mappings = array(
'd6_comment_type' => array(
array(array('comment'), array('comment_no_subject')),
),
);
$this->prepareMigrations($id_mappings);
$this->loadDumps(['Variable.php', 'NodeType.php']);
$this->executeMigration('d6_comment_field');
}
/**
* Tests comment variables migrated into a field entity.
*/
public function testCommentField() {
$this->assertTrue(is_object(FieldStorageConfig::load('node.comment')));
}
}

View file

@ -1,79 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateCommentVariableInstanceTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
/**
* Upgrade comment variables to field.instance.node.*.comment.yml.
*
* @group migrate_drupal
*/
class MigrateCommentVariableInstanceTest extends MigrateDrupal6TestBase {
static $modules = array('comment', 'node');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Add some id mappings for the dependant migrations.
$id_mappings = array(
'd6_comment_field' => array(
array(array('page'), array('node', 'page')),
),
'd6_node_type' => array(
array(array('page'), array('page')),
),
);
$this->prepareMigrations($id_mappings);
foreach (array('page', 'story', 'article') as $type) {
entity_create('node_type', array('type' => $type))->save();
}
entity_create('field_storage_config', array(
'entity_type' => 'node',
'field_name' => 'comment',
'type' => 'comment',
'translatable' => '0',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'node',
'field_name' => 'comment_no_subject',
'type' => 'comment',
'translatable' => '0',
))->save();
$this->loadDumps(['Variable.php', 'NodeType.php']);
$this->executeMigration('d6_comment_field_instance');
}
/**
* Test the migrated field instance values.
*/
public function testCommentFieldInstance() {
$node = entity_create('node', array('type' => 'page'));
$this->assertIdentical(0, $node->comment->status);
$this->assertIdentical('comment', $node->comment->getFieldDefinition()->getName());
$settings = $node->comment->getFieldDefinition()->getSettings();
$this->assertIdentical(4, $settings['default_mode']);
$this->assertIdentical(50, $settings['per_page']);
$this->assertIdentical(0, $settings['anonymous']);
$this->assertIdentical(FALSE, $settings['form_location']);
$this->assertIdentical(1, $settings['preview']);
$node = entity_create('node', array('type' => 'story'));
$this->assertIdentical(2, $node->comment_no_subject->status);
$this->assertIdentical('comment_no_subject', $node->comment_no_subject->getFieldDefinition()->getName());
$settings = $node->comment_no_subject->getFieldDefinition()->getSettings();
$this->assertIdentical(2, $settings['default_mode']);
$this->assertIdentical(70, $settings['per_page']);
$this->assertIdentical(1, $settings['anonymous']);
$this->assertIdentical(FALSE, $settings['form_location']);
$this->assertIdentical(0, $settings['preview']);
}
}

View file

@ -1,235 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateFieldFormatterSettingsTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\Core\Entity\Entity\EntityViewMode;
/**
* Upgrade field formatter settings to entity.display.*.*.yml.
*
* @group migrate_drupal
*/
class MigrateFieldFormatterSettingsTest extends MigrateDrupal6TestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('node', 'field', 'datetime', 'image', 'text', 'link', 'file', 'telephone');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(['node']);
entity_create('node_type', array('type' => 'test_page'))->save();
entity_create('node_type', array('type' => 'story'))->save();
// Create the node preview view mode.
EntityViewMode::create(array('id' => 'node.preview', 'targetEntityType' => 'node'))->save();
// Add some id mappings for the dependant migrations.
$id_mappings = array(
'd6_view_modes' => array(
array(array(1), array('node', 'preview')),
array(array(4), array('node', 'rss')),
array(array('teaser'), array('node', 'teaser')),
array(array('full'), array('node', 'full')),
),
'd6_field_instance' => array(
array(array('fieldname', 'page'), array('node', 'fieldname', 'page')),
),
'd6_field' => array(
array(array('field_test'), array('node', 'field_test')),
array(array('field_test_two'), array('node', 'field_test_two')),
array(array('field_test_three'), array('node', 'field_test_three')),
array(array('field_test_email'), array('node', 'field_test_email')),
array(array('field_test_link'), array('node', 'field_test_link')),
array(array('field_test_filefield'), array('node', 'field_test_filefield')),
array(array('field_test_imagefield'), array('node', 'field_test_imagefield')),
array(array('field_test_phone'), array('node', 'field_test_phone')),
array(array('field_test_date'), array('node', 'field_test_date')),
array(array('field_test_datestamp'), array('node', 'field_test_datestamp')),
array(array('field_test_datetime'), array('node', 'field_test_datetime')),
array(array('field_test_exclude_unset'), array('node', 'field_test_exclude_unset')),
),
);
$this->prepareMigrations($id_mappings);
$this->loadDumps([
'ContentNodeFieldInstance.php',
'ContentNodeField.php',
'ContentFieldTest.php',
'ContentFieldTestTwo.php',
'ContentFieldMultivalue.php',
]);
$this->executeMigration('d6_field_formatter_settings');
}
/**
* Test that migrated entity display settings can be loaded using D8 API's.
*/
public function testEntityDisplaySettings() {
// Run tests.
$field_name = "field_test";
$expected = array(
'label' => 'above',
'weight' => 1,
'type' => 'text_trimmed',
'settings' => array('trim_length' => 600),
'third_party_settings' => array(),
);
// Can we load any entity display.
$display = entity_load('entity_view_display', 'node.story.teaser');
$this->assertIdentical($expected, $display->getComponent($field_name));
// Test migrate worked with multiple bundles.
$display = entity_load('entity_view_display', 'node.test_page.teaser');
$expected['weight'] = 35;
$this->assertIdentical($expected, $display->getComponent($field_name));
// Test RSS because that has been converted from 4 to rss.
$display = entity_load('entity_view_display', 'node.story.rss');
$expected['weight'] = 1;
$this->assertIdentical($expected, $display->getComponent($field_name));
// Test the default format with text_default which comes from a static map.
$expected['type'] = 'text_default';
$expected['settings'] = array();
$display = entity_load('entity_view_display', 'node.story.default');
$this->assertIdentical($expected, $display->getComponent($field_name));
// Check that we can migrate multiple fields.
$content = $display->get('content');
$this->assertTrue(isset($content['field_test']), 'Settings for field_test exist.');
$this->assertTrue(isset($content['field_test_two']), "Settings for field_test_two exist.");
// Check that we can migrate a field where exclude is not set.
$this->assertTrue(isset($content['field_test_exclude_unset']), "Settings for field_test_exclude_unset exist.");
// Test the number field formatter settings are correct.
$expected['weight'] = 1;
$expected['type'] = 'number_integer';
$expected['settings'] = array(
'thousand_separator' => ',',
'prefix_suffix' => TRUE,
);
$component = $display->getComponent('field_test_two');
$this->assertIdentical($expected, $component);
$expected['weight'] = 2;
$expected['type'] = 'number_decimal';
$expected['settings'] = array(
'scale' => 2,
'decimal_separator' => '.',
'thousand_separator' => ',',
'prefix_suffix' => TRUE,
);
$component = $display->getComponent('field_test_three');
$this->assertIdentical($expected, $component);
// Test the email field formatter settings are correct.
$expected['weight'] = 6;
$expected['type'] = 'email_mailto';
$expected['settings'] = array();
$component = $display->getComponent('field_test_email');
$this->assertIdentical($expected, $component);
// Test the link field formatter settings.
$expected['weight'] = 7;
$expected['type'] = 'link';
$expected['settings'] = array(
'trim_length' => 80,
'url_only' => TRUE,
'url_plain' => TRUE,
'rel' => '0',
'target' => '0',
);
$component = $display->getComponent('field_test_link');
$this->assertIdentical($expected, $component);
$expected['settings']['url_only'] = FALSE;
$expected['settings']['url_plain'] = FALSE;
$display = entity_load('entity_view_display', 'node.story.teaser');
$component = $display->getComponent('field_test_link');
$this->assertIdentical($expected, $component);
// Test the file field formatter settings.
$expected['weight'] = 8;
$expected['type'] = 'file_default';
$expected['settings'] = array();
$component = $display->getComponent('field_test_filefield');
$this->assertIdentical($expected, $component);
$display = entity_load('entity_view_display', 'node.story.default');
$expected['type'] = 'file_url_plain';
$component = $display->getComponent('field_test_filefield');
$this->assertIdentical($expected, $component);
// Test the image field formatter settings.
$expected['weight'] = 9;
$expected['type'] = 'image';
$expected['settings'] = array('image_style' => '', 'image_link' => '');
$component = $display->getComponent('field_test_imagefield');
$this->assertIdentical($expected, $component);
$display = entity_load('entity_view_display', 'node.story.teaser');
$expected['settings']['image_link'] = 'file';
$component = $display->getComponent('field_test_imagefield');
$this->assertIdentical($expected, $component);
// Test phone field.
$expected['weight'] = 13;
$expected['type'] = 'basic_string';
$expected['settings'] = array();
$component = $display->getComponent('field_test_phone');
$this->assertIdentical($expected, $component);
// Test date field.
$defaults = array('format_type' => 'fallback', 'timezone_override' => '',);
$expected['weight'] = 10;
$expected['type'] = 'datetime_default';
$expected['settings'] = array('format_type' => 'fallback') + $defaults;
$component = $display->getComponent('field_test_date');
$this->assertIdentical($expected, $component);
$display = entity_load('entity_view_display', 'node.story.default');
$expected['settings']['format_type'] = 'long';
$component = $display->getComponent('field_test_date');
$this->assertIdentical($expected, $component);
// Test date stamp field.
$expected['weight'] = 11;
$expected['settings']['format_type'] = 'fallback';
$component = $display->getComponent('field_test_datestamp');
$this->assertIdentical($expected, $component);
$display = entity_load('entity_view_display', 'node.story.teaser');
$expected['settings'] = array('format_type' => 'medium') + $defaults;
$component = $display->getComponent('field_test_datestamp');
$this->assertIdentical($expected, $component);
// Test datetime field.
$expected['weight'] = 12;
$expected['settings'] = array('format_type' => 'short') + $defaults;
$component = $display->getComponent('field_test_datetime');
$this->assertIdentical($expected, $component);
$display = entity_load('entity_view_display', 'node.story.default');
$expected['settings']['format_type'] = 'fallback';
$component = $display->getComponent('field_test_datetime');
$this->assertIdentical($expected, $component);
// Test a date field with a random format which should be mapped
// to datetime_default.
$display = entity_load('entity_view_display', 'node.story.rss');
$expected['settings']['format_type'] = 'fallback';
$component = $display->getComponent('field_test_datetime');
$this->assertIdentical($expected, $component);
// Test that our Id map has the correct data.
$this->assertIdentical(array('node', 'story', 'teaser', 'field_test'), entity_load('migration', 'd6_field_formatter_settings')->getIdMap()->lookupDestinationID(array('story', 'teaser', 'node', 'field_test')));
}
}

View file

@ -1,181 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateFieldInstanceTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\field\Entity\FieldConfig;
use Drupal\link\LinkItemInterface;
/**
* Migrate field instances.
*
* @group migrate_drupal
*/
class MigrateFieldInstanceTest extends MigrateDrupal6TestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array(
'telephone',
'link',
'file',
'image',
'datetime',
'node',
'field',
'text',
);
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Add some id mappings for the dependant migrations.
$id_mappings = array(
'd6_field' => array(
array(array('field_test'), array('node', 'field_test')),
array(array('field_test_two'), array('node', 'field_test_two')),
array(array('field_test_three'), array('node', 'field_test_three')),
array(array('field_test_four'), array('node', 'field_test_four')),
array(array('field_test_email'), array('node', 'field_test_email')),
array(array('field_test_link'), array('node', 'field_test_link')),
array(array('field_test_filefield'), array('node', 'field_test_filefield')),
array(array('field_test_imagefield'), array('node', 'field_test_imagefield')),
array(array('field_test_phone'), array('node', 'field_test_phone')),
array(array('field_test_date'), array('node', 'field_test_date')),
array(array('field_test_datestamp'), array('node', 'field_test_datestamp')),
array(array('field_test_datetime'), array('node', 'field_test_datetime')),
),
'd6_node_type' => array(
array(array('page'), array('page')),
array(array('story'), array('story')),
array(array('test_page'), array('test_page')),
),
);
$this->prepareMigrations($id_mappings);
entity_create('node_type', array('type' => 'page'))->save();
entity_create('node_type', array('type' => 'story'))->save();
entity_create('node_type', array('type' => 'test_page'))->save();
$this->loadDumps([
'ContentNodeFieldInstance.php',
'ContentNodeField.php',
'ContentFieldTest.php',
'ContentFieldTestTwo.php',
'ContentFieldMultivalue.php',
]);
$this->createFields();
$this->executeMigration('d6_field_instance');
}
/**
* Tests migration of file variables to file.settings.yml.
*/
public function testFieldInstanceSettings() {
$entity = entity_create('node', array('type' => 'story'));
// Test a text field.
$field = FieldConfig::load('node.story.field_test');
$this->assertIdentical('Text Field', $field->label());
$expected = array('max_length' => 255);
$this->assertIdentical($expected, $field->getSettings());
$this->assertIdentical('text for default value', $entity->field_test->value);
// Test a number field.
$field = FieldConfig::load('node.story.field_test_two');
$this->assertIdentical('Integer Field', $field->label());
$expected = array(
'min' => 10,
'max' => 100,
'prefix' => 'pref',
'suffix' => 'suf',
'unsigned' => FALSE,
'size' => 'normal',
);
$this->assertIdentical($expected, $field->getSettings());
$field = FieldConfig::load('node.story.field_test_four');
$this->assertIdentical('Float Field', $field->label());
$expected = array(
'min' => 100.0,
'max' => 200.0,
'prefix' => 'id-',
'suffix' => '',
);
$this->assertIdentical($expected, $field->getSettings());
// Test email field.
$field = FieldConfig::load('node.story.field_test_email');
$this->assertIdentical('Email Field', $field->label());
$this->assertIdentical('benjy@example.com', $entity->field_test_email->value);
// Test a filefield.
$field = FieldConfig::load('node.story.field_test_filefield');
$this->assertIdentical('File Field', $field->label());
$expected = array(
'file_extensions' => 'txt pdf doc',
'file_directory' => 'images',
'description_field' => TRUE,
'max_filesize' => '200KB',
'target_type' => 'file',
'display_field' => FALSE,
'display_default' => FALSE,
'uri_scheme' => 'public',
// This value should be 'default:file' but the test does not migrate field
// storages so we end up with the default value for this setting.
'handler' => 'default:node',
'handler_settings' => array(),
'target_bundle' => NULL,
);
$field_settings = $field->getSettings();
ksort($expected);
ksort($field_settings);
// This is the only way to compare arrays.
$this->assertIdentical($expected, $field_settings);
// Test a link field.
$field = FieldConfig::load('node.story.field_test_link');
$this->assertIdentical('Link Field', $field->label());
$expected = array('title' => 2, 'link_type' => LinkItemInterface::LINK_GENERIC);
$this->assertIdentical($expected, $field->getSettings());
$this->assertIdentical('default link title', $entity->field_test_link->title, 'Field field_test_link default title is correct.');
$this->assertIdentical('https://www.drupal.org', $entity->field_test_link->url, 'Field field_test_link default title is correct.');
$this->assertIdentical([], $entity->field_test_link->options['attributes']);
}
/**
* Helper to create fields.
*/
protected function createFields() {
$fields = array(
'field_test' => 'text',
'field_test_two' => 'integer',
'field_test_three' => 'decimal',
'field_test_four' => 'float',
'field_test_email' => 'email',
'field_test_link' => 'link',
'field_test_filefield' => 'file',
'field_test_imagefield' => 'image',
'field_test_phone' => 'telephone',
'field_test_date' => 'datetime',
'field_test_datestamp' => 'datetime',
'field_test_datetime' => 'datetime',
);
foreach ($fields as $name => $type) {
entity_create('field_storage_config', array(
'field_name' => $name,
'entity_type' => 'node',
'type' => $type,
))->save();
}
}
}

View file

@ -1,113 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateFieldTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Migrate fields.
*
* @group migrate_drupal
*/
class MigrateFieldTest extends MigrateDrupal6TestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('field', 'telephone', 'link', 'file', 'image', 'datetime', 'node', 'options', 'text');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->loadDumps([
'ContentNodeFieldInstance.php',
'ContentNodeField.php',
'ContentFieldTest.php',
'ContentFieldTestTwo.php',
'ContentFieldMultivalue.php',
]);
$this->executeMigration('d6_field');
}
/**
* Tests the Drupal 6 field to Drupal 8 migration.
*/
public function testFields() {
// Text field.
/** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */
$field_storage = FieldStorageConfig::load('node.field_test');
$expected = array('max_length' => 255);
$this->assertIdentical("text", $field_storage->getType(), t('Field type is @fieldtype. It should be text.', array('@fieldtype' => $field_storage->getType())));
$this->assertIdentical($expected, $field_storage->getSettings(), "Field type text settings are correct");
// Integer field.
$field_storage = FieldStorageConfig::load('node.field_test_two');
$this->assertIdentical("integer", $field_storage->getType(), t('Field type is @fieldtype. It should be integer.', array('@fieldtype' => $field_storage->getType())));
// Float field.
$field_storage = FieldStorageConfig::load('node.field_test_three');
$this->assertIdentical("decimal", $field_storage->getType(), t('Field type is @fieldtype. It should be decimal.', array('@fieldtype' => $field_storage->getType())));
// Link field.
$field_storage = FieldStorageConfig::load('node.field_test_link');
$this->assertIdentical("link", $field_storage->getType(), t('Field type is @fieldtype. It should be link.', array('@fieldtype' => $field_storage->getType())));
// File field.
$field_storage = FieldStorageConfig::load('node.field_test_filefield');
$this->assertIdentical("file", $field_storage->getType(), t('Field type is @fieldtype. It should be file.', array('@fieldtype' => $field_storage->getType())));
$field_storage = FieldStorageConfig::load('node.field_test_imagefield');
$this->assertIdentical("image", $field_storage->getType(), t('Field type is @fieldtype. It should be image.', array('@fieldtype' => $field_storage->getType())));
$settings = $field_storage->getSettings();
$this->assertIdentical('file', $settings['target_type']);
$this->assertIdentical('public', $settings['uri_scheme']);
$this->assertIdentical(array(), array_filter($settings['default_image']));
// Phone field.
$field_storage = FieldStorageConfig::load('node.field_test_phone');
$this->assertIdentical("telephone", $field_storage->getType(), t('Field type is @fieldtype. It should be telephone.', array('@fieldtype' => $field_storage->getType())));
// Date field.
$field_storage = FieldStorageConfig::load('node.field_test_datetime');
$this->assertIdentical("datetime", $field_storage->getType(), t('Field type is @fieldtype. It should be datetime.', array('@fieldtype' => $field_storage->getType())));
// Decimal field with radio buttons.
$field_storage = FieldStorageConfig::load('node.field_test_decimal_radio_buttons');
$this->assertIdentical("list_float", $field_storage->getType(), t('Field type is @fieldtype. It should be list_float.', array('@fieldtype' => $field_storage->getType())));
$this->assertNotNull($field_storage->getSetting('allowed_values')['1.2'], t('First allowed value key is set to 1.2'));
$this->assertNotNull($field_storage->getSetting('allowed_values')['2.1'], t('Second allowed value key is set to 2.1'));
$this->assertIdentical('1.2', $field_storage->getSetting('allowed_values')['1.2'], t('First allowed value is set to 1.2'));
$this->assertIdentical('2.1', $field_storage->getSetting('allowed_values')['2.1'], t('Second allowed value is set to 1.2'));
// Float field with a single checkbox.
$field_storage = FieldStorageConfig::load('node.field_test_float_single_checkbox');
$this->assertIdentical("boolean", $field_storage->getType(), t('Field type is @fieldtype. It should be boolean.', array('@fieldtype' => $field_storage->getType())));
// Integer field with a select list.
$field_storage = FieldStorageConfig::load('node.field_test_integer_selectlist');
$this->assertIdentical("list_integer", $field_storage->getType(), t('Field type is @fieldtype. It should be list_integer.', array('@fieldtype' => $field_storage->getType())));
$this->assertNotNull($field_storage->getSetting('allowed_values')['1234'], t('First allowed value key is set to 1234'));
$this->assertNotNull($field_storage->getSetting('allowed_values')['2341'], t('Second allowed value key is set to 2341'));
$this->assertNotNull($field_storage->getSetting('allowed_values')['3412'], t('Third allowed value key is set to 3412'));
$this->assertNotNull($field_storage->getSetting('allowed_values')['4123'], t('Fourth allowed value key is set to 4123'));
$this->assertIdentical('1234', $field_storage->getSetting('allowed_values')['1234'], t('First allowed value is set to 1234'));
$this->assertIdentical('2341', $field_storage->getSetting('allowed_values')['2341'], t('Second allowed value is set to 2341'));
$this->assertIdentical('3412', $field_storage->getSetting('allowed_values')['3412'], t('Third allowed value is set to 3412'));
$this->assertIdentical('4123', $field_storage->getSetting('allowed_values')['4123'], t('Fourth allowed value is set to 4123'));
// Text field with a single checkbox.
$field_storage = FieldStorageConfig::load('node.field_test_text_single_checkbox');
$this->assertIdentical("boolean", $field_storage->getType(), t('Field type is @fieldtype. It should be boolean.', array('@fieldtype' => $field_storage->getType())));
}
}

View file

@ -1,149 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateFieldWidgetSettingsTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
/**
* Migrate field widget settings.
*
* @group migrate_drupal
*/
class MigrateFieldWidgetSettingsTest extends MigrateDrupal6TestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array(
'field',
'telephone',
'link',
'file',
'image',
'datetime',
'node',
'text',
);
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
entity_create('node_type', array('type' => 'test_page'))->save();
entity_create('node_type', array('type' => 'story'))->save();
// Add some id mappings for the dependant migrations.
$id_mappings = array(
'd6_field_instance' => array(
array(array('fieldname', 'page'), array('node', 'fieldname', 'page')),
),
'd6_field' => array(
array(array('field_test'), array('node', 'field_test')),
array(array('field_test_two'), array('node', 'field_test_two')),
array(array('field_test_three'), array('node', 'field_test_three')),
array(array('field_test_email'), array('node', 'field_test_email')),
array(array('field_test_link'), array('node', 'field_test_link')),
array(array('field_test_filefield'), array('node', 'field_test_filefield')),
array(array('field_test_imagefield'), array('node', 'field_test_imagefield')),
array(array('field_test_phone'), array('node', 'field_test_phone')),
array(array('field_test_date'), array('node', 'field_test_date')),
array(array('field_test_datestamp'), array('node', 'field_test_datestamp')),
array(array('field_test_datetime'), array('node', 'field_test_datetime')),
),
);
$this->prepareMigrations($id_mappings);
$this->loadDumps([
'ContentNodeFieldInstance.php',
'ContentNodeField.php',
'ContentFieldTest.php',
'ContentFieldTestTwo.php',
'ContentFieldMultivalue.php',
]);
$this->executeMigration('d6_field_instance_widget_settings');
}
/**
* Test that migrated view modes can be loaded using D8 API's.
*/
public function testWidgetSettings() {
// Test the config can be loaded.
$form_display = entity_load('entity_form_display', 'node.story.default');
$this->assertIdentical(FALSE, is_null($form_display), "Form display node.story.default loaded with config.");
// Text field.
$component = $form_display->getComponent('field_test');
$expected = array('weight' => 1, 'type' => 'text_textfield');
$expected['settings'] = array('size' => 60, 'placeholder' => '');
$expected['third_party_settings'] = array();
$this->assertIdentical($expected, $component, 'Text field settings are correct.');
// Integer field.
$component = $form_display->getComponent('field_test_two');
$expected['type'] = 'number';
$expected['weight'] = 1;
$expected['settings'] = array('placeholder' => '');
$this->assertIdentical($expected, $component);
// Float field.
$component = $form_display->getComponent('field_test_three');
$expected['weight'] = 2;
$this->assertIdentical($expected, $component);
// Email field.
$component = $form_display->getComponent('field_test_email');
$expected['type'] = 'email_default';
$expected['weight'] = 6;
$this->assertIdentical($expected, $component);
// Link field.
$component = $form_display->getComponent('field_test_link');
$this->assertIdentical('link_default', $component['type']);
$this->assertIdentical(7, $component['weight']);
$this->assertFalse(array_filter($component['settings']));
// File field.
$component = $form_display->getComponent('field_test_filefield');
$expected['type'] = 'file_generic';
$expected['weight'] = 8;
$expected['settings'] = array('progress_indicator' => 'bar');
$this->assertIdentical($expected, $component);
// Image field.
$component = $form_display->getComponent('field_test_imagefield');
$expected['type'] = 'image_image';
$expected['weight'] = 9;
$expected['settings'] = array('progress_indicator' => 'bar', 'preview_image_style' => 'thumbnail');
$this->assertIdentical($expected, $component);
// Phone field.
$component = $form_display->getComponent('field_test_phone');
$expected['type'] = 'telephone_default';
$expected['weight'] = 13;
$expected['settings'] = array('placeholder' => '');
$this->assertIdentical($expected, $component);
// Date fields.
$component = $form_display->getComponent('field_test_date');
$expected['type'] = 'datetime_default';
$expected['weight'] = 10;
$expected['settings'] = array();
$this->assertIdentical($expected, $component);
$component = $form_display->getComponent('field_test_datestamp');
$expected['weight'] = 11;
$this->assertIdentical($expected, $component);
$component = $form_display->getComponent('field_test_datetime');
$expected['weight'] = 12;
$this->assertIdentical($expected, $component);
}
}

View file

@ -1,48 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateFileConfigsTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\config\Tests\SchemaCheckTestTrait;
/**
* Upgrade variables to file.settings.yml.
*
* @group migrate_drupal
*/
class MigrateFileConfigsTest extends MigrateDrupal6TestBase {
use SchemaCheckTestTrait;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('file');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->loadDumps(['Variable.php']);
$this->executeMigration('d6_file_settings');
}
/**
* Tests migration of file variables to file.settings.yml.
*/
public function testFileSettings() {
$config = $this->config('file.settings');
$this->assertIdentical('textfield', $config->get('description.type'));
$this->assertIdentical(128, $config->get('description.length'));
$this->assertIdentical('sites/default/files/icons', $config->get('icon.directory'));
$this->assertConfigSchema(\Drupal::service('config.typed'), 'file.settings', $config->get());
}
}

View file

@ -1,132 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateFileTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\Component\Utility\Random;
use Drupal\migrate\Tests\MigrateDumpAlterInterface;
use Drupal\Core\Database\Database;
use Drupal\simpletest\TestBase;
use Drupal\file\Entity\File;
/**
* file migration.
*
* @group migrate_drupal
*/
class MigrateFileTest extends MigrateDrupal6TestBase implements MigrateDumpAlterInterface {
/**
* The filename of a file used to test temporary file migration.
*
* @var string
*/
protected static $tempFilename;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('file');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('file');
$this->installConfig(['file']);
$this->loadDumps(['Files.php']);
/** @var \Drupal\migrate\Entity\MigrationInterface $migration */
$migration = entity_load('migration', 'd6_file');
$source = $migration->get('source');
$source['site_path'] = 'core/modules/simpletest';
$migration->set('source', $source);
$this->executeMigration($migration);
$this->standalone = TRUE;
}
/**
* Tests the Drupal 6 files to Drupal 8 migration.
*/
public function testFiles() {
/** @var \Drupal\file\FileInterface $file */
$file = File::load(1);
$this->assertIdentical('Image1.png', $file->getFilename());
$this->assertIdentical('39325', $file->getSize());
$this->assertIdentical('public://image-1.png', $file->getFileUri());
$this->assertIdentical('image/png', $file->getMimeType());
$this->assertIdentical("1", $file->getOwnerId());
// It is pointless to run the second half from MigrateDrupal6Test.
if (empty($this->standalone)) {
return;
}
// Test that we can re-import and also test with file_directory_path set.
db_truncate(entity_load('migration', 'd6_file')->getIdMap()->mapTableName())->execute();
$this->loadDumps(['Variable.php']);
// Update the file_directory_path.
Database::getConnection('default', 'migrate')
->update('variable')
->fields(array('value' => serialize('files/test')))
->condition('name', 'file_directory_path')
->execute();
Database::getConnection('default', 'migrate')
->update('variable')
->fields(array('value' => serialize($this->getTempFilesDirectory())))
->condition('name', 'file_directory_temp')
->execute();
$migration = entity_load_unchanged('migration', 'd6_file');
$this->executeMigration($migration);
$file = File::load(2);
$this->assertIdentical('public://core/modules/simpletest/files/image-2.jpg', $file->getFileUri());
// Ensure that a temporary file has been migrated.
$file = File::load(6);
$this->assertIdentical('temporary://' . static::getUniqueFilename(), $file->getFileUri());
}
/**
* @return string
* A filename based upon the test.
*/
public static function getUniqueFilename() {
return static::$tempFilename;
}
/**
* {@inheritdoc}
*/
public static function migrateDumpAlter(TestBase $test) {
// Creates a random filename and updates the source database.
$random = new Random();
$temp_directory = $test->getTempFilesDirectory();
file_prepare_directory($temp_directory, FILE_CREATE_DIRECTORY);
static::$tempFilename = $test->getDatabasePrefix() . $random->name() . '.jpg';
$file_path = $temp_directory . '/' . static::$tempFilename;
file_put_contents($file_path, '');
Database::getConnection('default', 'migrate')
->update('files')
->condition('fid', 6)
->fields(array(
'filename' => static::$tempFilename,
'filepath' => $file_path,
))
->execute();
return static::$tempFilename;
}
}

View file

@ -1,100 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateUploadBase.
*/
namespace Drupal\migrate_drupal\Tests\d6;
/**
* Base class for file/upload migration tests.
*/
abstract class MigrateUploadBase extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
static $modules = array('file', 'node');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('file');
$this->installEntitySchema('node');
$this->installSchema('file', ['file_usage']);
$this->installSchema('node', ['node_access']);
// Create new file entities.
for ($i = 1; $i <= 3; $i++) {
$file = entity_create('file', array(
'fid' => $i,
'uid' => 1,
'filename' => 'druplicon.txt',
'uri' => "public://druplicon-$i.txt",
'filemime' => 'text/plain',
'created' => 1,
'changed' => 1,
'status' => FILE_STATUS_PERMANENT,
));
$file->enforceIsNew();
file_put_contents($file->getFileUri(), 'hello world');
// Save it, inserting a new record.
$file->save();
$id_mappings['d6_file'][] = array(array($i), array($i));
}
// Add a node type.
$node_type = entity_create('node_type', array('type' => 'story'));
$node_type->save();
// Add a file field.
entity_create('field_storage_config', array(
'field_name' => 'upload',
'entity_type' => 'node',
'type' => 'file',
'cardinality' => -1,
'settings' => array(
'display_field' => TRUE,
),
))->save();
entity_create('field_config', array(
'field_name' => 'upload',
'entity_type' => 'node',
'bundle' => 'story',
))->save();
$id_mappings['d6_node'] = array(
array(array(1), array(1)),
array(array(2), array(2)),
);
$this->prepareMigrations($id_mappings);
$vids = array(1, 2, 3);
for ($i = 1; $i <= 2; $i++) {
$node = entity_create('node', array(
'type' => 'story',
'nid' => $i,
'vid' => array_shift($vids),
));
$node->enforceIsNew();
$node->save();
if ($i == 1) {
$node->vid->value = array_shift($vids);
$node->enforceIsNew(FALSE);
$node->isDefaultRevision(FALSE);
$node->save();
}
}
$this->loadDumps([
'Node.php',
'NodeRevisions.php',
'ContentTypeStory.php',
'ContentTypeTestPlanet.php',
'Upload.php',
]);
}
}

View file

@ -1,65 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateUploadEntityDisplayTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
/**
* Upload entity display.
*
* @group migrate_drupal
*/
class MigrateUploadEntityDisplayTest extends MigrateDrupal6TestBase {
/**
* The modules to be enabled during the test.
*
* @var array
*/
static $modules = array('node', 'file');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
entity_create('node_type', array('type' => 'article'))->save();
entity_create('node_type', array('type' => 'story'))->save();
entity_create('node_type', array('type' => 'page'))->save();
$id_mappings = array(
'd6_upload_field_instance' => array(
array(array(1), array('node', 'page', 'upload')),
),
);
$this->prepareMigrations($id_mappings);
$this->loadDumps(['NodeType.php', 'Variable.php']);
$this->executeMigration('d6_upload_entity_display');
}
/**
* Tests the Drupal 6 upload settings to Drupal 8 entity display migration.
*/
public function testUploadEntityDisplay() {
$display = entity_get_display('node', 'page', 'default');
$component = $display->getComponent('upload');
$this->assertIdentical('file_default', $component['type']);
$display = entity_get_display('node', 'story', 'default');
$component = $display->getComponent('upload');
$this->assertIdentical('file_default', $component['type']);
// Assure this doesn't exist.
$display = entity_get_display('node', 'article', 'default');
$component = $display->getComponent('upload');
$this->assertTrue(is_null($component));
$this->assertIdentical(array('node', 'page', 'default', 'upload'), entity_load('migration', 'd6_upload_entity_display')->getIdMap()->lookupDestinationID(array('page')));
}
}

View file

@ -1,65 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateUploadEntityFormDisplayTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
/**
* Upload form entity display.
*
* @group migrate_drupal
*/
class MigrateUploadEntityFormDisplayTest extends MigrateDrupal6TestBase {
/**
* The modules to be enabled during the test.
*
* @var array
*/
static $modules = array('file', 'node');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
entity_create('node_type', array('type' => 'article'))->save();
entity_create('node_type', array('type' => 'story'))->save();
entity_create('node_type', array('type' => 'page'))->save();
$id_mappings = array(
'd6_upload_field_instance' => array(
array(array(1), array('node', 'page', 'upload')),
),
);
$this->prepareMigrations($id_mappings);
$this->loadDumps(['NodeType.php', 'Variable.php']);
$this->executeMigration('d6_upload_entity_form_display');
}
/**
* Tests the Drupal 6 upload settings to Drupal 8 entity form display migration.
*/
public function testUploadEntityFormDisplay() {
$display = entity_get_form_display('node', 'page', 'default');
$component = $display->getComponent('upload');
$this->assertIdentical('file_generic', $component['type']);
$display = entity_get_form_display('node', 'story', 'default');
$component = $display->getComponent('upload');
$this->assertIdentical('file_generic', $component['type']);
// Assure this doesn't exist.
$display = entity_get_form_display('node', 'article', 'default');
$component = $display->getComponent('upload');
$this->assertTrue(is_null($component));
$this->assertIdentical(array('node', 'page', 'default', 'upload'), entity_load('migration', 'd6_upload_entity_form_display')->getIdMap()->lookupDestinationID(array('page')));
}
}

View file

@ -1,43 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateUploadFieldTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Uploads migration.
*
* @group migrate_drupal
*/
class MigrateUploadFieldTest extends MigrateDrupal6TestBase {
/**
* The modules to be enabled during the test.
*
* @var array
*/
static $modules = array('file', 'node');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->executeMigration('d6_upload_field');
}
/**
* Tests the Drupal 6 upload settings to Drupal 8 field migration.
*/
public function testUpload() {
$field_storage = FieldStorageConfig::load('node.upload');
$this->assertIdentical('node.upload', $field_storage->id());
$this->assertIdentical(array('node', 'upload'), entity_load('migration', 'd6_upload_field')->getIdMap()->lookupDestinationID(array('')));
}
}

View file

@ -1,78 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateUploadInstanceTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\field\Entity\FieldConfig;
/**
* Upload field instance migration.
*
* @group migrate_drupal
*/
class MigrateUploadInstanceTest extends MigrateDrupal6TestBase {
/**
* The modules to be enabled during the test.
*
* @var array
*/
static $modules = array('file', 'node');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Add some node mappings to get past checkRequirements().
$id_mappings = array(
'd6_upload_field' => array(
array(array(1), array('node', 'upload')),
),
'd6_node_type' => array(
array(array('page'), array('page')),
array(array('story'), array('story')),
),
);
$this->prepareMigrations($id_mappings);
foreach (array('page', 'story') as $type) {
entity_create('node_type', array('type' => $type))->save();
}
entity_create('field_storage_config', array(
'entity_type' => 'node',
'field_name' => 'upload',
'type' => 'file',
'translatable' => '0',
))->save();
$this->loadDumps(['NodeType.php', 'Variable.php']);
$this->executeMigration('d6_upload_field_instance');
}
/**
* Tests the Drupal 6 upload settings to Drupal 8 field instance migration.
*/
public function testUploadFieldInstance() {
$field = FieldConfig::load('node.page.upload');
$settings = $field->getSettings();
$this->assertIdentical('node.page.upload', $field->id());
$this->assertIdentical('jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp', $settings['file_extensions']);
$this->assertIdentical('1MB', $settings['max_filesize']);
$this->assertIdentical(TRUE, $settings['description_field']);
$field = FieldConfig::load('node.story.upload');
$this->assertIdentical('node.story.upload', $field->id());
// Shouldn't exist.
$field = FieldConfig::load('node.article.upload');
$this->assertTrue(is_null($field));
$this->assertIdentical(array('node', 'page', 'upload'), entity_load('migration', 'd6_upload_field_instance')->getIdMap()->lookupDestinationID(array('page')));
}
}

View file

@ -1,50 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateUploadTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\node\Entity\Node;
/**
* Migrate association data between nodes and files.
*
* @group migrate_drupal
*/
class MigrateUploadTest extends MigrateUploadBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->executeMigration('d6_upload');
}
/**
* Test upload migration from Drupal 6 to Drupal 8.
*/
function testUpload() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$node_storage->resetCache(array(1, 2));
$nodes = Node::loadMultiple(array(1, 2));
$node = $nodes[1];
$this->assertIdentical(1, count($node->upload));
$this->assertIdentical('1', $node->upload[0]->target_id);
$this->assertIdentical('file 1-1-1', $node->upload[0]->description);
$this->assertIdentical(FALSE, $node->upload[0]->isDisplayed());
$node = $nodes[2];
$this->assertIdentical(2, count($node->upload));
$this->assertIdentical('3', $node->upload[0]->target_id);
$this->assertIdentical('file 2-3-3', $node->upload[0]->description);
$this->assertIdentical(FALSE, $node->upload[0]->isDisplayed());
$this->assertIdentical('2', $node->upload[1]->target_id);
$this->assertIdentical(TRUE, $node->upload[1]->isDisplayed());
$this->assertIdentical('file 2-3-2', $node->upload[1]->description);
}
}

View file

@ -1,65 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateUserConfigsTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\config\Tests\SchemaCheckTestTrait;
/**
* Upgrade variables to user.*.yml.
*
* @group migrate_drupal
*/
class MigrateUserConfigsTest extends MigrateDrupal6TestBase {
use SchemaCheckTestTrait;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->loadDumps(['Variable.php']);
$this->executeMigration('d6_user_mail');
$this->executeMigration('d6_user_settings');
}
/**
* Tests migration of user variables to user.mail.yml.
*/
public function testUserMail() {
$config = $this->config('user.mail');
$this->assertIdentical('Account details for !username at !site (approved)', $config->get('status_activated.subject'));
$this->assertIdentical("!username,\n\nYour account at !site has been activated.\n\nYou may now log in by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.\n\nOnce you have set your own password, you will be able to log in to !login_uri in the future using:\n\nusername: !username\n", $config->get('status_activated.body'));
$this->assertIdentical('Replacement login information for !username at !site', $config->get('password_reset.subject'));
$this->assertIdentical("!username,\n\nA request to reset the password for your account has been made at !site.\n\nYou may now log in to !uri_brief by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once. It expires after one day and nothing will happen if it's not used.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.", $config->get('password_reset.body'));
$this->assertIdentical('Account details for !username at !site (deleted)', $config->get('cancel_confirm.subject'));
$this->assertIdentical("!username,\n\nYour account on !site has been deleted.", $config->get('cancel_confirm.body'));
$this->assertIdentical('An administrator created an account for you at !site', $config->get('register_admin_created.subject'));
$this->assertIdentical("!username,\n\nA site administrator at !site has created an account for you. You may now log in to !login_uri using the following username and password:\n\nusername: !username\npassword: !password\n\nYou may also log in by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.\n\n\n-- !site team", $config->get('register_admin_created.body'));
$this->assertIdentical('Account details for !username at !site', $config->get('register_no_approval_required.subject'));
$this->assertIdentical("!username,\n\nThank you for registering at !site. You may now log in to !login_uri using the following username and password:\n\nusername: !username\npassword: !password\n\nYou may also log in by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.\n\n\n-- !site team", $config->get('register_no_approval_required.body'));
$this->assertIdentical('Account details for !username at !site (pending admin approval)', $config->get('register_pending_approval.subject'));
$this->assertIdentical("!username,\n\nThank you for registering at !site. Your application for an account is currently pending approval. Once it has been approved, you will receive another email containing information about how to log in, set your password, and other details.\n\n\n-- !site team", $config->get('register_pending_approval.body'));
$this->assertIdentical('Account details for !username at !site (blocked)', $config->get('status_blocked.subject'));
$this->assertIdentical("!username,\n\nYour account on !site has been blocked.", $config->get('status_blocked.body'));
$this->assertConfigSchema(\Drupal::service('config.typed'), 'user.mail', $config->get());
}
/**
* Tests migration of user variables to user.settings.yml.
*/
public function testUserSettings() {
$config = $this->config('user.settings');
$this->assertIdentical(TRUE, $config->get('notify.status_blocked'));
$this->assertIdentical(FALSE, $config->get('notify.status_activated'));
$this->assertIdentical(FALSE, $config->get('verify_mail'));
$this->assertIdentical('admin_only', $config->get('register'));
$this->assertIdentical('Guest', $config->get('anonymous'));
}
}

View file

@ -1,68 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateUserContactSettingsTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
/**
* Users contact settings migration.
*
* @group migrate_drupal
*/
class MigrateUserContactSettingsTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['contact'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installSchema('user', array('users_data'));
$this->loadDumps([
'Users.php',
'ProfileValues.php',
'UsersRoles.php',
'EventTimezones.php',
]);
$id_mappings = array(
'd6_user' => array(
array(array(2), array(2)),
array(array(8), array(8)),
array(array(15), array(15)),
),
);
$this->prepareMigrations($id_mappings);
$this->executeMigration('d6_user_contact_settings');
}
/**
* Tests the Drupal6 user contact settings migration.
*/
public function testUserContactSettings() {
$user_data = \Drupal::service('user.data');
$module = $key = 'contact';
$uid = 2;
$setting = $user_data->get($module, $uid, $key);
$this->assertIdentical('1', $setting);
$uid = 8;
$setting = $user_data->get($module, $uid, $key);
$this->assertIdentical('0', $setting);
$uid = 15;
$setting = $user_data->get($module, $uid, $key);
$this->assertIdentical(NULL, $setting);
}
}

View file

@ -1,51 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateUserPictureEntityDisplayTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
/**
* User picture entity display.
*
* @group migrate_drupal
*/
class MigrateUserPictureEntityDisplayTest extends MigrateDrupal6TestBase {
/**
* Modules to enable.
*
* @var array
*/
static $modules = array('image');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$id_mappings = array(
'd6_user_picture_field_instance' => array(
array(array(1), array('user', 'user', 'user_picture')),
),
);
$this->prepareMigrations($id_mappings);
$this->executeMigration('d6_user_picture_entity_display');
}
/**
* Tests the Drupal 6 user picture to Drupal 8 entity display migration.
*/
public function testUserPictureEntityDisplay() {
$display = entity_get_display('user', 'user', 'default');
$component = $display->getComponent('user_picture');
$this->assertIdentical('image', $component['type']);
$this->assertIdentical('content', $component['settings']['image_link']);
$this->assertIdentical(array('user', 'user', 'default', 'user_picture'), entity_load('migration', 'd6_user_picture_entity_display')->getIdMap()->lookupDestinationID(array('')));
}
}

View file

@ -1,50 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateUserPictureEntityFormDisplayTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
/**
* User picture entity form display.
*
* @group migrate_drupal
*/
class MigrateUserPictureEntityFormDisplayTest extends MigrateDrupal6TestBase {
/**
* Modules to enable.
*
* @var array
*/
static $modules = array('image');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$id_mappings = array(
'd6_user_picture_field_instance' => array(
array(array(1), array('user', 'user', 'user_picture')),
),
);
$this->prepareMigrations($id_mappings);
$this->executeMigration('d6_user_picture_entity_form_display');
}
/**
* Tests the Drupal 6 user picture to Drupal 8 entity form display migration.
*/
public function testUserPictureEntityFormDisplay() {
$display = entity_get_form_display('user', 'user', 'default');
$component = $display->getComponent('user_picture');
$this->assertIdentical('image_image', $component['type']);
$this->assertIdentical('throbber', $component['settings']['progress_indicator']);
$this->assertIdentical(array('user', 'user', 'default', 'user_picture'), entity_load('migration', 'd6_user_picture_entity_form_display')->getIdMap()->lookupDestinationID(array('')));
}
}

View file

@ -1,38 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateUserPictureFieldTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\field\Entity\FieldStorageConfig;
/**
* User picture field migration.
*
* @group migrate_drupal
*/
class MigrateUserPictureFieldTest extends MigrateDrupal6TestBase {
static $modules = array('image', 'file');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->executeMigration('d6_user_picture_field');
}
/**
* Test the user picture field migration.
*/
public function testUserPictureField() {
$field_storage = FieldStorageConfig::load('user.user_picture');
$this->assertIdentical('user.user_picture', $field_storage->id());
$this->assertIdentical(array('user', 'user_picture'), entity_load('migration', 'd6_user_picture_field')->getIdMap()->lookupDestinationID(array('')));
}
}

View file

@ -1,72 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateUserPictureFileTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\file\Entity\File;
/**
* User pictures migration.
*
* @group migrate_drupal
*/
class MigrateUserPictureFileTest extends MigrateDrupal6TestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('file');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('file');
$this->loadDumps([
'Users.php',
'ProfileValues.php',
'UsersRoles.php',
'EventTimezones.php',
]);
/** @var \Drupal\migrate\Entity\MigrationInterface $migration */
$migration = entity_load('migration', 'd6_user_picture_file');
$source = $migration->get('source');
$source['site_path'] = 'core/modules/simpletest';
$migration->set('source', $source);
$this->executeMigration($migration);
}
/**
* Tests the Drupal 6 user pictures to Drupal 8 migration.
*/
public function testUserPictures() {
$file_ids = array();
foreach (entity_load('migration', 'd6_user_picture_file')->getIdMap() as $destination_ids) {
$file_ids[] = reset($destination_ids);
}
$files = File::loadMultiple($file_ids);
/** @var \Drupal\file\FileInterface $file */
$file = array_shift($files);
$this->assertIdentical('image-test.jpg', $file->getFilename());
$this->assertIdentical('public://image-test.jpg', $file->getFileUri());
$this->assertIdentical('2', $file->getOwnerId());
$this->assertIdentical('1901', $file->getSize());
$this->assertIdentical('image/jpeg', $file->getMimeType());
$file = array_shift($files);
$this->assertIdentical('image-test.png', $file->getFilename());
$this->assertIdentical('public://image-test.png', $file->getFileUri());
$this->assertIdentical('8', $file->getOwnerId());
$this->assertFalse($files);
}
}

View file

@ -1,62 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateUserPictureInstanceTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\field\Entity\FieldConfig;
/**
* User picture field instance migration.
*
* @group migrate_drupal
*/
class MigrateUserPictureInstanceTest extends MigrateDrupal6TestBase {
/**
* Modules to enable.
*
* @var array
*/
static $modules = array('image', 'file');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Add some node mappings to get past checkRequirements().
$id_mappings = array(
'd6_user_picture_field' => array(
array(array('user_upload'), array('name', 'bundle')),
),
);
$this->prepareMigrations($id_mappings);
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'user_picture',
'type' => 'image',
'translatable' => '0',
))->save();
$this->executeMigration('d6_user_picture_field_instance');
}
/**
* Tests the Drupal 6 user picture to Drupal 8 picture field instance migration.
*/
public function testUserPictureFieldInstance() {
$field = FieldConfig::load('user.user.user_picture');
$settings = $field->getSettings();
$this->assertIdentical('png gif jpg jpeg', $settings['file_extensions']);
$this->assertIdentical('pictures', $settings['file_directory']);
$this->assertIdentical('30KB', $settings['max_filesize']);
$this->assertIdentical('85x85', $settings['max_resolution']);
$this->assertIdentical(array('user', 'user', 'user_picture'), entity_load('migration', 'd6_user_picture_field_instance')->getIdMap()->lookupDestinationID(array('')));
}
}

View file

@ -1,127 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateUserProfileEntityDisplayTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\Core\Database\Database;
/**
* Tests the user profile entity display migration.
*
* @group migrate_drupal
*/
class MigrateUserProfileEntityDisplayTest extends MigrateDrupal6TestBase {
/**
* Modules to enable.
*
* @var array
*/
static $modules = array('link', 'options', 'datetime', 'text');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Create some fields so the data gets stored.
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'profile_color',
'type' => 'text',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'profile_biography',
'type' => 'text_long',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'profile_sell_address',
'type' => 'boolean',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'profile_sold_to',
'type' => 'list_string',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'profile_bands',
'type' => 'text',
'cardinality' => -1,
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'profile_blog',
'type' => 'link',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'profile_birthdate',
'type' => 'datetime',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'profile_love_migrations',
'type' => 'boolean',
))->save();
$this->loadDumps([
'ProfileFields.php',
'Users.php',
'ProfileValues.php',
'UsersRoles.php',
'EventTimezones.php',
]);
$field_data = Database::getConnection('default', 'migrate')
->select('profile_fields', 'u')
->fields('u')
->execute()
->fetchAll();
foreach ($field_data as $field) {
entity_create('field_config', array(
'label' => $field->title,
'description' => '',
'field_name' => $field->name,
'entity_type' => 'user',
'bundle' => 'user',
'required' => 1,
))->save();
}
$this->executeMigration('d6_user_profile_entity_display');
}
/**
* Tests migration of user profile fields.
*/
public function testUserProfileFields() {
$display = entity_get_display('user', 'user', 'default');
// Test a text field.
$component = $display->getComponent('profile_color');
$this->assertIdentical('text_default', $component['type']);
// Test a list field.
$component = $display->getComponent('profile_bands');
$this->assertIdentical('text_default', $component['type']);
// Test a date field.
$component = $display->getComponent('profile_birthdate');
$this->assertIdentical('datetime_default', $component['type']);
// Test PROFILE_PRIVATE field is hidden.
$this->assertNull($display->getComponent('profile_sell_address'));
// Test PROFILE_HIDDEN field is hidden.
$this->assertNull($display->getComponent('profile_sold_to'));
}
}

View file

@ -1,127 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateUserProfileEntityFormDisplayTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\Core\Database\Database;
/**
* Tests the user profile entity form display migration.
*
* @group migrate_drupal
*/
class MigrateUserProfileEntityFormDisplayTest extends MigrateDrupal6TestBase {
static $modules = array('link', 'options', 'datetime', 'text');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Create some fields so the data gets stored.
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'profile_color',
'type' => 'text',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'profile_biography',
'type' => 'text_long',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'profile_sell_address',
'type' => 'boolean',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'profile_sold_to',
'type' => 'list_string',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'profile_bands',
'type' => 'text',
'cardinality' => -1,
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'profile_blog',
'type' => 'link',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'profile_birthdate',
'type' => 'datetime',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'profile_love_migrations',
'type' => 'boolean',
))->save();
$this->loadDumps([
'ProfileFields.php',
'Users.php',
'ProfileValues.php',
'UsersRoles.php',
'EventTimezones.php',
]);
$field_data = Database::getConnection('default', 'migrate')
->select('profile_fields', 'u')
->fields('u')
->execute()
->fetchAll();
foreach ($field_data as $field) {
entity_create('field_config', array(
'label' => $field->title,
'description' => '',
'field_name' => $field->name,
'entity_type' => 'user',
'bundle' => 'user',
'required' => 1,
))->save();
}
$this->executeMigration('d6_user_profile_entity_form_display');
}
/**
* Tests migration of user profile fields.
*/
public function testUserProfileEntityFormDisplay() {
$display = entity_get_form_display('user', 'user', 'default');
// Test a text field.
$component = $display->getComponent('profile_color');
$this->assertIdentical('text_textfield', $component['type']);
// Test a list field.
$component = $display->getComponent('profile_bands');
$this->assertIdentical('text_textfield', $component['type']);
// Test a date field.
$component = $display->getComponent('profile_birthdate');
$this->assertIdentical('datetime_default', $component['type']);
// Test PROFILE_PRIVATE field is hidden.
$this->assertNull($display->getComponent('profile_sell_address'));
// Test PROFILE_HIDDEN field is hidden.
$this->assertNull($display->getComponent('profile_sold_to'));
// Test that a checkbox field has the proper display label setting.
$component = $display->getComponent('profile_love_migrations');
$this->assertIdentical('boolean_checkbox', $component['type']);
$this->assertIdentical(true, $component['settings']['display_label']);
}
}

View file

@ -1,114 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateUserProfileFieldInstanceTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\field\Entity\FieldConfig;
/**
* Tests the user profile field instance migration.
*
* @group migrate_drupal
*/
class MigrateUserProfileFieldInstanceTest extends MigrateDrupal6TestBase {
static $modules = array('field', 'link', 'options', 'datetime', 'text');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Add some id mappings for the dependant migrations.
$id_mappings = array(
'd6_user_profile_field' => array(
array(array(1), array('user', 'profile_color')),
),
);
$this->prepareMigrations($id_mappings);
$this->createFields();
$this->loadDumps(array(
'ProfileFields.php',
'Users.php',
'ProfileValues.php',
'UsersRoles.php',
'EventTimezones.php',
));
$this->executeMigration('d6_user_profile_field_instance');
}
/**
* Tests migration of user profile fields.
*/
public function testUserProfileFields() {
// Migrated a text field.
$field = FieldConfig::load('user.user.profile_color');
$this->assertIdentical('Favorite color', $field->label());
$this->assertIdentical('List your favorite color', $field->getDescription());
// Migrated a textarea.
$field = FieldConfig::load('user.user.profile_biography');
$this->assertIdentical('Biography', $field->label());
$this->assertIdentical('Tell people a little bit about yourself', $field->getDescription());
// Migrated checkbox field.
$field = FieldConfig::load('user.user.profile_sell_address');
$this->assertIdentical('Sell your email address?', $field->label());
$this->assertIdentical("If you check this box, we'll sell your address to spammers to help line the pockets of our shareholders. Thanks!", $field->getDescription());
// Migrated selection field.
$field = FieldConfig::load('user.user.profile_sold_to');
$this->assertIdentical('Sales Category', $field->label());
$this->assertIdentical("Select the sales categories to which this user's address was sold.", $field->getDescription());
// Migrated list field.
$field = FieldConfig::load('user.user.profile_bands');
$this->assertIdentical('Favorite bands', $field->label());
$this->assertIdentical("Enter your favorite bands. When you've saved your profile, you'll be able to find other people with the same favorites.", $field->getDescription());
/*
// Migrated URL field.
$field = FieldConfig::load('user.user.profile_blog');
$this->assertIdentical('Your blog', $field->label());
$this->assertIdentical("Paste the full URL, $field->getDescription(), including http://, of your personal blog.");
*/
// Migrated date field.
$field = FieldConfig::load('user.user.profile_birthdate');
$this->assertIdentical('Birthdate', $field->label());
$this->assertIdentical("Enter your birth date and we'll send you a coupon.", $field->getDescription());
// Another migrated checkbox field, with a different source visibility setting.
$field = FieldConfig::load('user.user.profile_love_migrations');
$this->assertIdentical('I love migrations', $field->label());
$this->assertIdentical("If you check this box, you love migrations.", $field->getDescription());
}
/**
* Helper to create fields.
*/
protected function createFields() {
$fields = array(
'profile_color' => 'text',
'profile_biography' => 'text_long',
'profile_sell_address' => 'boolean',
'profile_sold_to' => 'list_string',
'profile_bands' => 'text',
'profile_blog' => 'link',
'profile_birthdate' => 'datetime',
'profile_love_migrations' => 'boolean',
);
foreach ($fields as $name => $type) {
entity_create('field_storage_config', array(
'field_name' => $name,
'entity_type' => 'user',
'type' => $type,
))->save();
}
}
}

View file

@ -1,85 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateUserProfileFieldTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests the user profile field migration.
*
* @group migrate_drupal
*/
class MigrateUserProfileFieldTest extends MigrateDrupal6TestBase {
static $modules = array('link', 'options', 'datetime', 'text');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->loadDumps([
'ProfileFields.php',
'Users.php',
'ProfileValues.php',
'UsersRoles.php',
'EventTimezones.php',
]);
$this->executeMigration('d6_user_profile_field');
}
/**
* Tests migration of user profile fields.
*/
public function testUserProfileFields() {
// Migrated a text field.
$field_storage = FieldStorageConfig::load('user.profile_color');
$this->assertIdentical('text', $field_storage->getType(), 'Field type is text.');
$this->assertIdentical(1, $field_storage->getCardinality(), 'Text field has correct cardinality');
// Migrated a textarea.
$field_storage = FieldStorageConfig::load('user.profile_biography');
$this->assertIdentical('text_long', $field_storage->getType(), 'Field type is text_long.');
// Migrated checkbox field.
$field_storage = FieldStorageConfig::load('user.profile_sell_address');
$this->assertIdentical('boolean', $field_storage->getType(), 'Field type is boolean.');
// Migrated selection field.
$field_storage = FieldStorageConfig::load('user.profile_sold_to');
$this->assertIdentical('list_string', $field_storage->getType(), 'Field type is list_string.');
$settings = $field_storage->getSettings();
$this->assertEqual($settings['allowed_values'], array(
'Pill spammers' => 'Pill spammers',
'Fitness spammers' => 'Fitness spammers',
'Back\slash' => 'Back\slash',
'Forward/slash' => 'Forward/slash',
'Dot.in.the.middle' => 'Dot.in.the.middle',
'Faithful servant' => 'Faithful servant',
'Anonymous donor' => 'Anonymous donor',
));
$this->assertIdentical('list_string', $field_storage->getType(), 'Field type is list_string.');
// Migrated list field.
$field_storage = FieldStorageConfig::load('user.profile_bands');
$this->assertIdentical('text', $field_storage->getType(), 'Field type is text.');
$this->assertIdentical(-1, $field_storage->getCardinality(), 'List field has correct cardinality');
/*
// Migrated URL field.
$field_storage = FieldStorageConfig::load('user.profile_blog');
$this->assertIdentical('link', $field_storage->getType(), 'Field type is link.');
*/
// Migrated date field.
$field_storage = FieldStorageConfig::load('user.profile_birthdate');
$this->assertIdentical('datetime', $field_storage->getType(), 'Field type is datetime.');
$this->assertIdentical('date', $field_storage->getSettings()['datetime_type']);
}
}

View file

@ -1,174 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateUserProfileValuesTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\migrate\MigrateExecutable;
use Drupal\Core\Database\Database;
use Drupal\user\Entity\User;
/**
* User profile values migration.
*
* @group migrate_drupal
*/
class MigrateUserProfileValuesTest extends MigrateDrupal6TestBase {
/**
* The modules to be enabled during the test.
*
* @var array
*/
static $modules = array(
'link',
'options',
'datetime',
'text',
'file',
'image',
);
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Create some fields so the data gets stored.
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'profile_color',
'type' => 'text',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'profile_biography',
'type' => 'text_long',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'profile_sell_address',
'type' => 'boolean',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'profile_sold_to',
'type' => 'list_string',
'settings' => array(
'allowed_values' => array(
'Pill spammers' => 'Pill spammers',
'Fitness spammers' => 'Fitness spammers',
)
)
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'profile_bands',
'type' => 'text',
'cardinality' => -1,
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'profile_blog',
'type' => 'link',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'profile_birthdate',
'type' => 'datetime',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'profile_love_migrations',
'type' => 'boolean',
))->save();
// Add some id mappings for the dependant migrations.
$id_mappings = array(
'd6_user_profile_field_instance' => array(
array(array(1), array('user', 'user', 'fieldname')),
),
'd6_user_profile_entity_display' => array(
array(array(1), array('user', 'user', 'default', 'fieldname')),
),
'd6_user_profile_entity_form_display' => array(
array(array(1), array('user', 'user', 'default', 'fieldname')),
),
'd6_user' => array(
array(array(2), array(2)),
array(array(8), array(8)),
array(array(15), array(15)),
),
);
$this->prepareMigrations($id_mappings);
$this->loadDumps([
'ProfileFields.php',
'Users.php',
'ProfileValues.php',
'UsersRoles.php',
'EventTimezones.php',
]);
$field_data = Database::getConnection('default', 'migrate')
->select('profile_fields', 'u')
->fields('u')
->execute()
->fetchAll();
// Create the field instances.
foreach ($field_data as $field) {
entity_create('field_config', array(
'label' => $field->title,
'description' => '',
'field_name' => $field->name,
'entity_type' => 'user',
'bundle' => 'user',
'required' => 0,
))->save();
}
// Create our users for the node authors.
$query = Database::getConnection('default', 'migrate')->query('SELECT * FROM {users} WHERE uid NOT IN (0, 1)');
while(($row = $query->fetchAssoc()) !== FALSE) {
$user = entity_create('user', $row);
$user->enforceIsNew();
$user->save();
}
$migration_format = entity_load('migration', 'd6_profile_values:user');
$this->executeMigration($migration_format);
}
/**
* Tests Drupal 6 profile values to Drupal 8 migration.
*/
public function testUserProfileValues() {
$user = User::load(2);
$this->assertFalse(is_null($user));
$this->assertIdentical('red', $user->profile_color->value);
$expected = <<<EOT
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam nulla sapien, congue nec risus ut, adipiscing aliquet felis. Maecenas quis justo vel nulla varius euismod. Quisque metus metus, cursus sit amet sem non, bibendum vehicula elit. Cras dui nisl, eleifend at iaculis vitae, lacinia ut felis. Nullam aliquam ligula volutpat nulla consectetur accumsan. Maecenas tincidunt molestie diam, a accumsan enim fringilla sit amet. Morbi a tincidunt tellus. Donec imperdiet scelerisque porta. Sed quis sem bibendum eros congue sodales. Vivamus vel fermentum est, at rutrum orci. Nunc consectetur purus ut dolor pulvinar, ut volutpat felis congue. Cras tincidunt odio sed neque sollicitudin, vehicula tempor metus scelerisque.
EOT;
$this->assertIdentical($expected, $user->profile_biography->value);
$this->assertIdentical('1', $user->profile_sell_address->value);
$this->assertIdentical('Back\slash', $user->profile_sold_to->value);
$this->assertIdentical('AC/DC', $user->profile_bands[0]->value);
$this->assertIdentical('Eagles', $user->profile_bands[1]->value);
$this->assertIdentical('Elton John', $user->profile_bands[2]->value);
$this->assertIdentical('Lemonheads', $user->profile_bands[3]->value);
$this->assertIdentical('Rolling Stones', $user->profile_bands[4]->value);
$this->assertIdentical('Queen', $user->profile_bands[5]->value);
$this->assertIdentical('The White Stripes', $user->profile_bands[6]->value);
$this->assertIdentical('1974-06-02', $user->profile_birthdate->value);
$user = User::load(8);
$this->assertIdentical('Forward/slash', $user->profile_sold_to->value);
$user = User::load(15);
$this->assertIdentical('Dot.in.the.middle', $user->profile_sold_to->value);
}
}

View file

@ -1,98 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateUserRoleTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\user\Entity\Role;
/**
* Upgrade user roles to user.role.*.yml.
*
* @group migrate_drupal
*/
class MigrateUserRoleTest extends MigrateDrupal6TestBase {
/**
* The modules to be enabled during the test.
*
* @var array
*/
static $modules = array('filter', 'node');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// We need some sample data so we can use the Migration process plugin.
$id_mappings = array(
'd6_filter_format' => array(
array(array(1), array('filtered_html')),
array(array(2), array('full_html'))
),
);
$this->prepareMigrations($id_mappings);
$this->loadDumps([
'Permission.php',
'Role.php',
'Filters.php',
'FilterFormats.php',
'Variable.php',
]);
$this->executeMigration('d6_user_role');
}
/**
* Tests user role migration.
*/
public function testUserRole() {
/** @var \Drupal\migrate\entity\Migration $migration */
$migration = entity_load('migration', 'd6_user_role');
$rid = 'anonymous';
$anonymous = Role::load($rid);
$this->assertIdentical($rid, $anonymous->id());
$this->assertIdentical(array('migrate test anonymous permission', 'use text format filtered_html'), $anonymous->getPermissions());
$this->assertIdentical(array($rid), $migration->getIdMap()->lookupDestinationId(array(1)));
$rid = 'authenticated';
$authenticated = Role::load($rid);
$this->assertIdentical($rid, $authenticated->id());
$this->assertIdentical(array('migrate test authenticated permission', 'use text format filtered_html'), $authenticated->getPermissions());
$this->assertIdentical(array($rid), $migration->getIdMap()->lookupDestinationId(array(2)));
$rid = 'migrate_test_role_1';
$migrate_test_role_1 = Role::load($rid);
$this->assertIdentical($rid, $migrate_test_role_1->id());
$this->assertIdentical(array(0 => 'migrate test role 1 test permission', 'use text format full_html'), $migrate_test_role_1->getPermissions());
$this->assertIdentical(array($rid), $migration->getIdMap()->lookupDestinationId(array(3)));
$rid = 'migrate_test_role_2';
$migrate_test_role_2 = Role::load($rid);
$this->assertIdentical(array(
'migrate test role 2 test permission',
'use PHP for settings',
'administer contact forms',
'skip comment approval',
'edit own blog content',
'edit any blog content',
'delete own blog content',
'delete any blog content',
'create forum content',
'delete any forum content',
'delete own forum content',
'edit any forum content',
'edit own forum content',
'administer nodes',
'access content overview',
), $migrate_test_role_2->getPermissions());
$this->assertIdentical($rid, $migrate_test_role_2->id());
$this->assertIdentical(array($rid), $migration->getIdMap()->lookupDestinationId(array(4)));
$rid = 'migrate_test_role_3_that_is_long';
$migrate_test_role_3 = Role::load($rid);
$this->assertIdentical($rid, $migrate_test_role_3->id());
$this->assertIdentical(array($rid), $migration->getIdMap()->lookupDestinationId(array(5)));
}
}

View file

@ -1,184 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateUserTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\user\Entity\User;
use Drupal\file\Entity\File;
use Drupal\Core\Database\Database;
use Drupal\user\RoleInterface;
/**
* Users migration.
*
* @group migrate_drupal
*/
class MigrateUserTest extends MigrateDrupal6TestBase {
/**
* The modules to be enabled during the test.
*
* @var array
*/
static $modules = array(
'link',
'options',
'datetime',
'text',
'file',
'image',
);
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('file');
$this->installSchema('file', ['file_usage']);
// Create the user profile field and instance.
entity_create('field_storage_config', array(
'entity_type' => 'user',
'field_name' => 'user_picture',
'type' => 'image',
'translatable' => '0',
))->save();
entity_create('field_config', array(
'label' => 'User Picture',
'description' => '',
'field_name' => 'user_picture',
'entity_type' => 'user',
'bundle' => 'user',
'required' => 0,
))->save();
$file = entity_create('file', array(
'fid' => 2,
'uid' => 2,
'filename' => 'image-test.jpg',
'uri' => "public://image-test.jpg",
'filemime' => 'image/jpeg',
'created' => 1,
'changed' => 1,
'status' => FILE_STATUS_PERMANENT,
));
$file->enforceIsNew();
file_put_contents($file->getFileUri(), file_get_contents('core/modules/simpletest/files/image-1.png'));
$file->save();
$file = entity_create('file', array(
'fid' => 8,
'uid' => 8,
'filename' => 'image-test.png',
'uri' => "public://image-test.png",
'filemime' => 'image/png',
'created' => 1,
'changed' => 1,
'status' => FILE_STATUS_PERMANENT,
));
$file->enforceIsNew();
file_put_contents($file->getFileUri(), file_get_contents('core/modules/simpletest/files/image-2.jpg'));
$file->save();
$this->loadDumps([
'Filters.php',
'FilterFormats.php',
'Variable.php',
'ProfileFields.php',
'Permission.php',
'Role.php',
'Users.php',
'ProfileValues.php',
'UsersRoles.php',
'EventTimezones.php',
]);
$id_mappings = array(
'd6_user_role' => array(
array(array(1), array('anonymous user')),
array(array(2), array('authenticated user')),
array(array(3), array('migrate test role 1')),
array(array(4), array('migrate test role 2')),
array(array(5), array('migrate test role 3')),
),
'd6_user_picture_entity_display' => array(
array(array(1), array('user', 'user', 'default', 'user_picture')),
),
'd6_user_picture_entity_form_display' => array(
array(array(1), array('user', 'user', 'default', 'user_picture')),
),
'd6_user_picture_file' => array(
array(array(2), array(2)),
array(array(8), array(8)),
),
);
$this->prepareMigrations($id_mappings);
$this->executeMigration('d6_user');
}
/**
* Tests the Drupal6 user to Drupal 8 migration.
*/
public function testUser() {
$users = Database::getConnection('default', 'migrate')
->select('users', 'u')
->fields('u')
->execute()
->fetchAll();
foreach ($users as $source) {
// Get roles directly from the source.
$rids = Database::getConnection('default', 'migrate')
->select('users_roles', 'ur')
->fields('ur', array('rid'))
->condition('ur.uid', $source->uid)
->execute()
->fetchCol();
$roles = array(RoleInterface::AUTHENTICATED_ID);
$migration_role = entity_load('migration', 'd6_user_role');
foreach ($rids as $rid) {
$role = $migration_role->getIdMap()->lookupDestinationId(array($rid));
$roles[] = reset($role);
}
/** @var \Drupal\user\UserInterface $user */
$user = User::load($source->uid);
$this->assertIdentical($source->uid, $user->id());
$this->assertIdentical($source->name, $user->label());
$this->assertIdentical($source->mail, $user->getEmail());
$this->assertIdentical($source->created, $user->getCreatedTime());
$this->assertIdentical($source->access, $user->getLastAccessedTime());
$this->assertIdentical($source->login, $user->getLastLoginTime());
$is_blocked = $source->status == 0;
$this->assertIdentical($is_blocked, $user->isBlocked());
// $user->getPreferredLangcode() might fallback to default language if the
// user preferred language is not configured on the site. We just want to
// test if the value was imported correctly.
$this->assertIdentical($source->language, $user->preferred_langcode->value);
$time_zone = $source->expected_timezone ?: $this->config('system.date')->get('timezone.default');
$this->assertIdentical($time_zone, $user->getTimeZone());
$this->assertIdentical($source->init, $user->getInitialEmail());
$this->assertIdentical($roles, $user->getRoles());
// We have one empty picture in the data so don't try load that.
if (!empty($source->picture)) {
// Test the user picture.
$file = File::load($user->user_picture->target_id);
$this->assertIdentical(basename($source->picture), $file->getFilename());
}
// Use the API to check if the password has been salted and re-hashed to
// conform the Drupal >= 7.
$this->assertTrue(\Drupal::service('password')->check($source->pass_plain, $user->getPassword()));
}
}
}