View source
<?php
namespace Drupal\Tests\range\Kernel\Migrate\d6;
use Drupal\node\Entity\Node;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\FieldStorageConfigInterface;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
class MigrateRangeFieldTest extends MigrateDrupal6TestBase {
protected static $modules = [
'node',
'range',
'text',
'system',
];
protected function setUp() : void {
parent::setUp();
$this
->migrateUsers(FALSE);
$this
->migrateContentTypes();
$this
->executeMigrations([
'd6_field',
'd6_field_instance',
'd6_field_instance_widget_settings',
'd6_view_modes',
'd6_field_formatter_settings',
'd6_node_settings',
'd6_node',
]);
}
protected function getFixtureFilePath() {
return __DIR__ . '/../../../../fixtures/drupal6.php';
}
public function testFieldMigration($id, $type, $settings) {
$field = FieldStorageConfig::load($id);
$this
->assertInstanceOf(FieldStorageConfigInterface::class, $field);
$this
->assertSame($type, $field
->getType());
$this
->assertSame($settings, $field
->getSettings());
}
public function fieldMigrationDataProvider() {
return [
'range_decimal' => [
'node.field_decimal',
'range_decimal',
[
'precision' => 12,
'scale' => 1,
],
],
'range_float' => [
'node.field_float',
'range_float',
[],
],
'range_integer' => [
'node.field_integer',
'range_integer',
[],
],
];
}
public function testFieldInstanceMigration($id, $default_value, $settings) {
$field = FieldConfig::load($id);
$this
->assertSame($default_value, $field
->getDefaultValueLiteral());
$this
->assertSame($settings, $field
->getSettings());
}
public function fieldInstanceMigrationDataProvider() {
return [
'range_decimal' => [
'node.page.field_decimal',
[
[
'from' => 15.0,
'to' => 15.0,
],
],
[
'min' => 5.0,
'max' => 50.0,
'field' => [
'prefix' => '',
'suffix' => '',
],
'from' => [
'prefix' => '',
'suffix' => '',
],
'to' => [
'prefix' => '',
'suffix' => '',
],
'combined' => [
'prefix' => '',
'suffix' => '',
],
'precision' => 12,
'scale' => 1,
],
],
'range_float' => [
'node.page.field_float',
[],
[
'min' => NULL,
'max' => 1000.0,
'field' => [
'prefix' => '',
'suffix' => 'SUFFIX',
],
'from' => [
'prefix' => '',
'suffix' => '',
],
'to' => [
'prefix' => '',
'suffix' => '',
],
'combined' => [
'prefix' => '',
'suffix' => '',
],
],
],
'range_integer' => [
'node.page.field_integer',
[],
[
'min' => NULL,
'max' => NULL,
'field' => [
'prefix' => '',
'suffix' => '',
],
'from' => [
'prefix' => '',
'suffix' => '',
],
'to' => [
'prefix' => '',
'suffix' => '',
],
'combined' => [
'prefix' => '',
'suffix' => '',
],
],
],
];
}
public function testFieldWidgetMigration($display_id, $component_id, $type, $settings) {
$component = EntityFormDisplay::load($display_id)
->getComponent($component_id);
$this
->assertSame($type, $component['type']);
$this
->assertSame($settings, $component['settings']);
}
public function fieldWidgetMigrationDataProvider() {
return [
'range_decimal' => [
'node.page.default',
'field_decimal',
'range',
[
'placeholder' => [
'from' => '',
'to' => '',
],
'label' => [
'from' => 'From',
'to' => 'to',
],
],
],
'range_float' => [
'node.page.default',
'field_float',
'range',
[
'placeholder' => [
'from' => '',
'to' => '',
],
'label' => [
'from' => 'From',
'to' => 'to',
],
],
],
'range_integer' => [
'node.page.default',
'field_integer',
'range',
[
'placeholder' => [
'from' => '',
'to' => '',
],
'label' => [
'from' => 'From',
'to' => 'to',
],
],
],
];
}
public function testFieldFormatterMigration($display_id, $component_id, $type, $settings) {
$component = EntityViewDisplay::load($display_id)
->getComponent($component_id);
$this
->assertIsArray($component);
$this
->assertSame($type, $component['type']);
$this
->assertSame($settings, $component['settings']);
}
public function fieldFormatterMigrationDataProvider() {
return [
'unformatted range_decimal' => [
'node.page.default',
'field_decimal',
'range_unformatted',
[
'field_prefix_suffix' => TRUE,
'range_separator' => '-',
'range_combine' => TRUE,
'from_prefix_suffix' => FALSE,
'to_prefix_suffix' => FALSE,
'combined_prefix_suffix' => FALSE,
],
],
'default range_decimal' => [
'node.page.teaser',
'field_decimal',
'range_decimal',
[
'field_prefix_suffix' => TRUE,
'decimal_separator' => '.',
'scale' => 2,
'thousand_separator' => '',
'range_separator' => '-',
'range_combine' => TRUE,
'from_prefix_suffix' => FALSE,
'to_prefix_suffix' => FALSE,
'combined_prefix_suffix' => FALSE,
],
],
'us_2 range_decimal' => [
'node.page.rss',
'field_decimal',
'range_decimal',
[
'scale' => 2,
'decimal_separator' => '.',
'thousand_separator' => ',',
'field_prefix_suffix' => TRUE,
'range_separator' => '-',
'range_combine' => TRUE,
'from_prefix_suffix' => FALSE,
'to_prefix_suffix' => FALSE,
'combined_prefix_suffix' => FALSE,
],
],
'unformatted range_float' => [
'node.page.default',
'field_float',
'range_unformatted',
[
'field_prefix_suffix' => TRUE,
'range_separator' => '-',
'range_combine' => TRUE,
'from_prefix_suffix' => FALSE,
'to_prefix_suffix' => FALSE,
'combined_prefix_suffix' => FALSE,
],
],
'default range_float' => [
'node.page.teaser',
'field_float',
'range_decimal',
[
'field_prefix_suffix' => TRUE,
'decimal_separator' => '.',
'scale' => 2,
'thousand_separator' => '',
'range_separator' => '-',
'range_combine' => TRUE,
'from_prefix_suffix' => FALSE,
'to_prefix_suffix' => FALSE,
'combined_prefix_suffix' => FALSE,
],
],
'be_1 range_float' => [
'node.page.rss',
'field_float',
'range_decimal',
[
'scale' => 1,
'decimal_separator' => ',',
'thousand_separator' => '.',
'field_prefix_suffix' => TRUE,
'range_separator' => '-',
'range_combine' => TRUE,
'from_prefix_suffix' => FALSE,
'to_prefix_suffix' => FALSE,
'combined_prefix_suffix' => FALSE,
],
],
'unformatted range_integer' => [
'node.page.default',
'field_integer',
'range_unformatted',
[
'field_prefix_suffix' => TRUE,
'range_separator' => '-',
'range_combine' => TRUE,
'from_prefix_suffix' => FALSE,
'to_prefix_suffix' => FALSE,
'combined_prefix_suffix' => FALSE,
],
],
'default range_integer' => [
'node.page.teaser',
'field_integer',
'range_integer',
[
'field_prefix_suffix' => TRUE,
'thousand_separator' => '',
'range_separator' => '-',
'range_combine' => TRUE,
'from_prefix_suffix' => FALSE,
'to_prefix_suffix' => FALSE,
'combined_prefix_suffix' => FALSE,
],
],
'fr_0 range_integer' => [
'node.page.rss',
'field_integer',
'range_integer',
[
'thousand_separator' => ' ',
'field_prefix_suffix' => TRUE,
'range_separator' => '-',
'range_combine' => TRUE,
'from_prefix_suffix' => FALSE,
'to_prefix_suffix' => FALSE,
'combined_prefix_suffix' => FALSE,
],
],
];
}
public function testFieldDataMigration($field_name, $expected) {
$node = Node::load(1);
$this
->assertSame($expected, $node->{$field_name}
->getValue());
}
public function fieldDataMigrationDataProvider() {
return [
'range_decimal' => [
'field_decimal',
[
[
'from' => '55.6',
'to' => '55.6',
],
[
'from' => '67.7',
'to' => '67.7',
],
[
'from' => '88.9',
'to' => '88.9',
],
],
],
'range_float' => [
'field_float',
[],
],
'range_integer' => [
'field_integer',
[
[
'from' => '120',
'to' => '120',
],
],
],
];
}
}