Update Composer, update everything

This commit is contained in:
Oliver Davies 2018-11-23 12:29:20 +00:00
parent ea3e94409f
commit dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions

View file

@ -0,0 +1,250 @@
<?php
namespace Drupal\Tests\text\Functional;
use Drupal\Component\Utility\Html;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\filter\Entity\FilterFormat;
use Drupal\Tests\field\Functional\String\StringFieldTest;
use Drupal\Tests\TestFileCreationTrait;
/**
* Tests the creation of text fields.
*
* @group text
*/
class TextFieldTest extends StringFieldTest {
use TestFileCreationTrait {
getTestFiles as drupalGetTestFiles;
}
/**
* A user with relevant administrative privileges.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
protected function setUp() {
parent::setUp();
$this->adminUser = $this->drupalCreateUser(['administer filters']);
}
// Test fields.
/**
* Test text field validation.
*/
public function testTextFieldValidation() {
// Create a field with settings to validate.
$max_length = 3;
$field_name = mb_strtolower($this->randomMachineName());
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'text',
'settings' => [
'max_length' => $max_length,
],
]);
$field_storage->save();
FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'entity_test',
])->save();
// Test validation with valid and invalid values.
$entity = EntityTest::create();
for ($i = 0; $i <= $max_length + 2; $i++) {
$entity->{$field_name}->value = str_repeat('x', $i);
$violations = $entity->{$field_name}->validate();
if ($i <= $max_length) {
$this->assertEqual(count($violations), 0, "Length $i does not cause validation error when max_length is $max_length");
}
else {
$this->assertEqual(count($violations), 1, "Length $i causes validation error when max_length is $max_length");
}
}
}
/**
* Test required long text with file upload.
*/
public function testRequiredLongTextWithFileUpload() {
// Create a text field.
$text_field_name = 'text_long';
$field_storage = FieldStorageConfig::create([
'field_name' => $text_field_name,
'entity_type' => 'entity_test',
'type' => 'text_with_summary',
]);
$field_storage->save();
FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'entity_test',
'label' => $this->randomMachineName() . '_label',
'required' => TRUE,
])->save();
// Create a file field.
$file_field_name = 'file_field';
$field_storage = FieldStorageConfig::create([
'field_name' => $file_field_name,
'entity_type' => 'entity_test',
'type' => 'file',
]);
$field_storage->save();
FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'entity_test',
'label' => $this->randomMachineName() . '_label',
])->save();
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($text_field_name, [
'type' => 'text_textarea_with_summary',
])
->setComponent($file_field_name, [
'type' => 'file_generic',
])
->save();
entity_get_display('entity_test', 'entity_test', 'full')
->setComponent($text_field_name)
->setComponent($file_field_name)
->save();
$test_file = current($this->drupalGetTestFiles('text'));
$edit['files[file_field_0]'] = \Drupal::service('file_system')->realpath($test_file->uri);
$this->drupalPostForm('entity_test/add', $edit, 'Upload');
$this->assertResponse(200);
$edit = [
'text_long[0][value]' => 'Long text',
];
$this->drupalPostForm(NULL, $edit, 'Save');
$this->assertResponse(200);
$this->drupalGet('entity_test/1');
$this->assertText('Long text');
}
/**
* Test widgets.
*/
public function testTextfieldWidgets() {
$this->_testTextfieldWidgets('text', 'text_textfield');
$this->_testTextfieldWidgets('text_long', 'text_textarea');
}
/**
* Test widgets + 'formatted_text' setting.
*/
public function testTextfieldWidgetsFormatted() {
$this->_testTextfieldWidgetsFormatted('text', 'text_textfield');
$this->_testTextfieldWidgetsFormatted('text_long', 'text_textarea');
}
/**
* Helper function for testTextfieldWidgetsFormatted().
*/
public function _testTextfieldWidgetsFormatted($field_type, $widget_type) {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = $this->container->get('renderer');
// Create a field.
$field_name = mb_strtolower($this->randomMachineName());
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => $field_type,
]);
$field_storage->save();
FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'entity_test',
'label' => $this->randomMachineName() . '_label',
])->save();
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($field_name, [
'type' => $widget_type,
])
->save();
entity_get_display('entity_test', 'entity_test', 'full')
->setComponent($field_name)
->save();
// Disable all text formats besides the plain text fallback format.
$this->drupalLogin($this->adminUser);
foreach (filter_formats() as $format) {
if (!$format->isFallbackFormat()) {
$this->drupalPostForm('admin/config/content/formats/manage/' . $format->id() . '/disable', [], t('Disable'));
}
}
$this->drupalLogin($this->webUser);
// Display the creation form. Since the user only has access to one format,
// no format selector will be displayed.
$this->drupalGet('entity_test/add');
$this->assertFieldByName("{$field_name}[0][value]", '', 'Widget is displayed');
$this->assertNoFieldByName("{$field_name}[0][format]", '', 'Format selector is not displayed');
// Submit with data that should be filtered.
$value = '<em>' . $this->randomMachineName() . '</em>';
$edit = [
"{$field_name}[0][value]" => $value,
];
$this->drupalPostForm(NULL, $edit, t('Save'));
preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match);
$id = $match[1];
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created');
// Display the entity.
$entity = EntityTest::load($id);
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
$content = $display->build($entity);
$rendered_entity = \Drupal::service('renderer')->renderRoot($content);
$this->assertNotContains($value, (string) $rendered_entity);
$this->assertContains(Html::escape($value), (string) $rendered_entity);
// Create a new text format that does not escape HTML, and grant the user
// access to it.
$this->drupalLogin($this->adminUser);
$edit = [
'format' => mb_strtolower($this->randomMachineName()),
'name' => $this->randomMachineName(),
];
$this->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration'));
filter_formats_reset();
$format = FilterFormat::load($edit['format']);
$format_id = $format->id();
$permission = $format->getPermissionName();
$roles = $this->webUser->getRoles();
$rid = $roles[0];
user_role_grant_permissions($rid, [$permission]);
$this->drupalLogin($this->webUser);
// Display edition form.
// We should now have a 'text format' selector.
$this->drupalGet('entity_test/manage/' . $id . '/edit');
$this->assertFieldByName("{$field_name}[0][value]", NULL, 'Widget is displayed');
$this->assertFieldByName("{$field_name}[0][format]", NULL, 'Format selector is displayed');
// Edit and change the text format to the new one that was created.
$edit = [
"{$field_name}[0][format]" => $format_id,
];
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertText(t('entity_test @id has been updated.', ['@id' => $id]), 'Entity was updated');
// Display the entity.
$this->container->get('entity.manager')->getStorage('entity_test')->resetCache([$id]);
$entity = EntityTest::load($id);
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
$content = $display->build($entity);
$rendered_entity = \Drupal::service('renderer')->renderRoot($content);
$this->assertContains($value, (string) $rendered_entity);
}
}

View file

@ -0,0 +1,85 @@
<?php
namespace Drupal\Tests\text\FunctionalJavascript;
use Drupal\field\Entity\FieldConfig;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
/**
* Tests the JavaScript functionality of the text_textarea_with_summary widget.
*
* @group text
*/
class TextareaWithSummaryTest extends WebDriverTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['text', 'node'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->drupalCreateContentType(['type' => 'page']);
$account = $this->drupalCreateUser(['create page content', 'edit own page content']);
$this->drupalLogin($account);
}
/**
* Helper to test toggling the summary area.
*/
protected function assertSummaryToggle() {
$this->drupalGet('node/add/page');
$widget = $this->getSession()->getPage()->findById('edit-body-wrapper');
$summary_field = $widget->findField('edit-body-0-summary');
$this->assertEquals(FALSE, $summary_field->isVisible(), 'Summary field is hidden by default.');
$this->assertEquals(FALSE, $widget->hasButton('Hide summary'), 'No Hide summary link by default.');
$widget->pressButton('Edit summary');
$this->assertEquals(FALSE, $widget->hasButton('Edit summary'), 'Edit summary link is removed after clicking.');
$this->assertEquals(TRUE, $summary_field->isVisible(), 'Summary field is shown.');
$widget->pressButton('Hide summary');
$this->assertEquals(FALSE, $widget->hasButton('Hide summary'), 'Hide summary link is removed after clicking.');
$this->assertEquals(FALSE, $summary_field->isVisible(), 'Summary field is hidden again.');
$this->assertEquals(TRUE, $widget->hasButton('Edit summary'), 'Edit summary link is visible again.');
}
/**
* Tests the textSummary javascript behavior.
*/
public function testTextSummaryBehavior() {
// Test with field defaults.
$this->assertSummaryToggle();
// Repeat test with non-empty field description.
$body_field = FieldConfig::loadByName('node', 'page', 'body');
$body_field->set('description', 'Text with Summary field description.');
$body_field->save();
$this->assertSummaryToggle();
// Test summary is shown when non-empty.
$node = $this->createNode([
'body' => [
[
'value' => $this->randomMachineName(32),
'summary' => $this->randomMachineName(32),
'format' => filter_default_format(),
],
],
]);
$this->drupalGet('node/' . $node->id() . '/edit');
$page = $this->getSession()->getPage();
$summary_field = $page->findField('edit-body-0-summary');
$this->assertEquals(TRUE, $summary_field->isVisible(), 'Non-empty summary field is shown by default.');
}
}

View file

@ -35,10 +35,15 @@ class TextSummaryTest extends KernelTestBase {
* Test summary with long example.
*/
public function testLongSentence() {
$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ' . // 125
'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ' . // 108
'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ' . // 103
'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'; // 110
// 125.
$text =
'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ' .
// 108.
'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ' .
// 103.
'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ' .
// 110.
'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
$expected = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ' .
'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ' .
'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.';
@ -202,6 +207,15 @@ class TextSummaryTest extends KernelTestBase {
$this->assertTextSummary($text, "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>", $format, $i++);
}
/**
* Test text_summary() returns an empty string without any error when called
* with an invalid format.
*/
public function testInvalidFilterFormat() {
$this->assertTextSummary($this->randomString(100), '', 'non_existent_format');
}
/**
* Calls text_summary() and asserts that the expected teaser is returned.
*/

View file

@ -26,7 +26,7 @@ class TextWithSummaryItemTest extends FieldKernelTestBase {
/**
* Field storage entity.
*
* @var \Drupal\field\Entity\FieldStorageConfig.
* @var \Drupal\field\Entity\FieldStorageConfig
*/
protected $fieldStorage;
@ -37,7 +37,6 @@ class TextWithSummaryItemTest extends FieldKernelTestBase {
*/
protected $field;
protected function setUp() {
parent::setUp();
@ -106,7 +105,7 @@ class TextWithSummaryItemTest extends FieldKernelTestBase {
'type' => 'text_with_summary',
'settings' => [
'max_length' => 10,
]
],
]);
$this->fieldStorage->save();
$this->field = FieldConfig::create([

View file

@ -11,8 +11,9 @@ use Prophecy\Argument;
/**
* @coversDefaultClass \Drupal\text\Plugin\migrate\cckfield\TextField
* @group text
* @group legacy
*/
class TextFieldTest extends UnitTestCase {
class TextCckTest extends UnitTestCase {
/**
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface
@ -37,7 +38,7 @@ class TextFieldTest extends UnitTestCase {
// process pipeline created by the plugin, we need to ensure that
// getProcess() always returns the last input to setProcessOfProperty().
$migration->setProcessOfProperty(Argument::type('string'), Argument::type('array'))
->will(function($arguments) use ($migration) {
->will(function ($arguments) use ($migration) {
$migration->getProcess()->willReturn($arguments[1]);
});
@ -54,7 +55,7 @@ class TextFieldTest extends UnitTestCase {
$this->plugin->processCckFieldValues($this->migration, 'body', $field_info);
$process = $this->migration->getProcess();
$this->assertSame('iterator', $process['plugin']);
$this->assertSame('sub_process', $process['plugin']);
$this->assertSame('body', $process['source']);
$this->assertSame('value', $process['process']['value']);
@ -75,7 +76,7 @@ class TextFieldTest extends UnitTestCase {
'widget_type' => 'optionwidgets_onoff',
'global_settings' => [
'allowed_values' => "foo\nbar",
]
],
];
$this->plugin->processCckFieldValues($this->migration, 'field', $info);
@ -100,7 +101,7 @@ class TextFieldTest extends UnitTestCase {
'widget_type' => 'optionwidgets_onoff',
'global_settings' => [
'allowed_values' => "foo|Foo\nbaz|Baz",
]
],
];
$this->plugin->processCckFieldValues($this->migration, 'field', $info);
@ -122,37 +123,33 @@ class TextFieldTest extends UnitTestCase {
*/
public function getFieldTypeProvider() {
return [
['string_long', 'text_textfield', [
'text_processing' => FALSE,
]],
['string_long', 'text_textfield', ['text_processing' => FALSE]],
['string', 'text_textfield', [
'text_processing' => FALSE,
'max_length' => 128,
]],
'text_processing' => FALSE,
'max_length' => 128,
],
],
['string_long', 'text_textfield', [
'text_processing' => FALSE,
'max_length' => 4096,
]],
['text_long', 'text_textfield', [
'text_processing' => TRUE,
]],
'text_processing' => FALSE,
'max_length' => 4096,
],
],
['text_long', 'text_textfield', ['text_processing' => TRUE]],
['text', 'text_textfield', [
'text_processing' => TRUE,
'max_length' => 128,
]],
'text_processing' => TRUE,
'max_length' => 128,
],
],
['text_long', 'text_textfield', [
'text_processing' => TRUE,
'max_length' => 4096,
]],
'text_processing' => TRUE,
'max_length' => 4096,
],
],
['list_string', 'optionwidgets_buttons'],
['list_string', 'optionwidgets_select'],
['boolean', 'optionwidgets_onoff'],
['text_long', 'text_textarea', [
'text_processing' => TRUE,
]],
['string_long', 'text_textarea', [
'text_processing' => FALSE,
]],
['text_long', 'text_textarea', ['text_processing' => TRUE]],
['string_long', 'text_textarea', ['text_processing' => FALSE]],
[NULL, 'undefined'],
];
}
@ -162,8 +159,7 @@ class TextFieldTest extends UnitTestCase {
* @dataProvider getFieldTypeProvider
*/
public function testGetFieldType($expected_type, $widget_type, array $settings = []) {
$row = new Row();
$row->setSourceProperty('widget_type', $widget_type);
$row = new Row(['widget_type' => $widget_type], ['widget_type' => []]);
$row->setSourceProperty('global_settings', $settings);
$this->assertSame($expected_type, $this->plugin->getFieldType($row));
}

View file

@ -0,0 +1,253 @@
<?php
namespace Drupal\Tests\text\Unit\Migrate\d6;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Row;
use Drupal\Tests\UnitTestCase;
use Drupal\text\Plugin\migrate\field\d6\TextField;
use Prophecy\Argument;
/**
* @coversDefaultClass \Drupal\text\Plugin\migrate\field\d6\TextField
* @group text
* @group legacy
*/
class TextFieldTest extends UnitTestCase {
/**
* @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
*/
protected $plugin;
/**
* @var \Drupal\migrate\Plugin\MigrationInterface
*/
protected $migration;
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->plugin = new TextField([], 'text', []);
$migration = $this->prophesize(MigrationInterface::class);
// The plugin's defineValueProcessPipeline() method will call
// setProcessOfProperty() and return nothing. So, in order to examine the
// process pipeline created by the plugin, we need to ensure that
// getProcess() always returns the last input to setProcessOfProperty().
$migration->setProcessOfProperty(Argument::type('string'), Argument::type('array'))
->will(function ($arguments) use ($migration) {
$migration->getProcess()->willReturn($arguments[1]);
});
$this->migration = $migration->reveal();
}
/**
* Calls the deprecated processFieldValues() method to test BC.
*
* @covers ::processFieldValues
*
* @depends testFilteredTextValueProcessPipeline
*/
public function testProcessFilteredTextFieldValues() {
$field_info = [
'widget_type' => 'text_textfield',
];
$this->plugin->processFieldValues($this->migration, 'body', $field_info);
$process = $this->migration->getProcess();
$this->assertSame('sub_process', $process['plugin']);
$this->assertSame('body', $process['source']);
$this->assertSame('value', $process['process']['value']);
// Ensure that filter format IDs will be looked up in the filter format
// migrations.
$lookup = $process['process']['format'][2];
$this->assertSame('migration', $lookup['plugin']);
$this->assertContains('d6_filter_format', $lookup['migration']);
$this->assertContains('d7_filter_format', $lookup['migration']);
$this->assertSame('format', $lookup['source']);
}
/**
* @covers ::defineValueProcessPipeline
*/
public function testFilteredTextValueProcessPipeline() {
$field_info = [
'widget_type' => 'text_textfield',
];
$this->plugin->defineValueProcessPipeline($this->migration, 'body', $field_info);
$process = $this->migration->getProcess();
$this->assertSame('sub_process', $process['plugin']);
$this->assertSame('body', $process['source']);
$this->assertSame('value', $process['process']['value']);
// Ensure that filter format IDs will be looked up in the filter format
// migrations.
$lookup = $process['process']['format'][2];
$this->assertSame('migration', $lookup['plugin']);
$this->assertContains('d6_filter_format', $lookup['migration']);
$this->assertContains('d7_filter_format', $lookup['migration']);
$this->assertSame('format', $lookup['source']);
}
/**
* Calls the deprecated processFieldValues() method to test BC.
*
* @covers ::processFieldValues
*
* @depends testBooleanTextImplicitValueProcessPipeline
*/
public function testProcessBooleanTextImplicitValues() {
$info = [
'widget_type' => 'optionwidgets_onoff',
'global_settings' => [
'allowed_values' => "foo\nbar",
],
];
$this->plugin->processFieldValues($this->migration, 'field', $info);
$expected = [
'value' => [
'plugin' => 'static_map',
'source' => 'value',
'default_value' => 0,
'map' => [
'bar' => 1,
],
],
];
$this->assertSame($expected, $this->migration->getProcess()['process']);
}
/**
* @covers ::defineValueProcessPipeline
*/
public function testBooleanTextImplicitValueProcessPipeline() {
$info = [
'widget_type' => 'optionwidgets_onoff',
'global_settings' => [
'allowed_values' => "foo\nbar",
],
];
$this->plugin->defineValueProcessPipeline($this->migration, 'field', $info);
$expected = [
'value' => [
'plugin' => 'static_map',
'source' => 'value',
'default_value' => 0,
'map' => [
'bar' => 1,
],
],
];
$this->assertSame($expected, $this->migration->getProcess()['process']);
}
/**
* Calls the deprecated processFieldValues() method to test BC.
*
* @covers ::processFieldValues
*
* @depends testBooleanTextExplicitValueProcessPipeline
*/
public function testProcessBooleanTextExplicitValues() {
$info = [
'widget_type' => 'optionwidgets_onoff',
'global_settings' => [
'allowed_values' => "foo|Foo\nbaz|Baz",
],
];
$this->plugin->processFieldValues($this->migration, 'field', $info);
$expected = [
'value' => [
'plugin' => 'static_map',
'source' => 'value',
'default_value' => 0,
'map' => [
'baz' => 1,
],
],
];
$this->assertSame($expected, $this->migration->getProcess()['process']);
}
/**
* @covers ::defineValueProcessPipeline
*/
public function testBooleanTextExplicitValueProcessPipeline() {
$info = [
'widget_type' => 'optionwidgets_onoff',
'global_settings' => [
'allowed_values' => "foo|Foo\nbaz|Baz",
],
];
$this->plugin->defineValueProcessPipeline($this->migration, 'field', $info);
$expected = [
'value' => [
'plugin' => 'static_map',
'source' => 'value',
'default_value' => 0,
'map' => [
'baz' => 1,
],
],
];
$this->assertSame($expected, $this->migration->getProcess()['process']);
}
/**
* Data provider for testGetFieldType().
*/
public function getFieldTypeProvider() {
return [
['string_long', 'text_textfield', ['text_processing' => FALSE]],
['string', 'text_textfield', [
'text_processing' => FALSE,
'max_length' => 128,
],
],
['string_long', 'text_textfield', [
'text_processing' => FALSE,
'max_length' => 4096,
],
],
['text_long', 'text_textfield', ['text_processing' => TRUE]],
['text', 'text_textfield', [
'text_processing' => TRUE,
'max_length' => 128,
],
],
['text_long', 'text_textfield', [
'text_processing' => TRUE,
'max_length' => 4096,
],
],
['list_string', 'optionwidgets_buttons'],
['list_string', 'optionwidgets_select'],
['boolean', 'optionwidgets_onoff'],
['text_long', 'text_textarea', ['text_processing' => TRUE]],
['string_long', 'text_textarea', ['text_processing' => FALSE]],
[NULL, 'undefined'],
];
}
/**
* @covers ::getFieldType
* @dataProvider getFieldTypeProvider
*/
public function testGetFieldType($expected_type, $widget_type, array $settings = []) {
$row = new Row();
$row->setSourceProperty('widget_type', $widget_type);
$row->setSourceProperty('global_settings', $settings);
$this->assertSame($expected_type, $this->plugin->getFieldType($row));
}
}

View file

@ -0,0 +1,12 @@
<?php
namespace Drupal\Tests\text\Unit\Migrate\d7;
use Drupal\Tests\text\Unit\Migrate\d6\TextFieldTest as D6TextFieldTest;
/**
* @coversDefaultClass \Drupal\text\Plugin\migrate\field\d7\TextField
* @group text
* @group legacy
*/
class TextFieldTest extends D6TextFieldTest {}

View file

@ -0,0 +1,167 @@
<?php
namespace Drupal\Tests\text\Unit\Plugin\migrate\cckfield;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Row;
use Drupal\Tests\UnitTestCase;
use Drupal\text\Plugin\migrate\cckfield\TextField;
use Prophecy\Argument;
/**
* @coversDefaultClass \Drupal\text\Plugin\migrate\cckfield\TextField
* @group text
* @group legacy
*/
class TextCckTest extends UnitTestCase {
/**
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface
*/
protected $plugin;
/**
* @var \Drupal\migrate\Plugin\MigrationInterface
*/
protected $migration;
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->plugin = new TextField([], 'text', []);
$migration = $this->prophesize(MigrationInterface::class);
// The plugin's processCckFieldValues() method will call
// setProcessOfProperty() and return nothing. So, in order to examine the
// process pipeline created by the plugin, we need to ensure that
// getProcess() always returns the last input to setProcessOfProperty().
$migration->setProcessOfProperty(Argument::type('string'), Argument::type('array'))
->will(function ($arguments) use ($migration) {
$migration->getProcess()->willReturn($arguments[1]);
});
$this->migration = $migration->reveal();
}
/**
* @covers ::processCckFieldValues
*/
public function testProcessFilteredTextFieldValues() {
$field_info = [
'widget_type' => 'text_textfield',
];
$this->plugin->processCckFieldValues($this->migration, 'body', $field_info);
$process = $this->migration->getProcess();
$this->assertSame('sub_process', $process['plugin']);
$this->assertSame('body', $process['source']);
$this->assertSame('value', $process['process']['value']);
// Ensure that filter format IDs will be looked up in the filter format
// migrations.
$lookup = $process['process']['format'][2];
$this->assertSame('migration', $lookup['plugin']);
$this->assertContains('d6_filter_format', $lookup['migration']);
$this->assertContains('d7_filter_format', $lookup['migration']);
$this->assertSame('format', $lookup['source']);
}
/**
* @covers ::processCckFieldValues
*/
public function testProcessBooleanTextImplicitValues() {
$info = [
'widget_type' => 'optionwidgets_onoff',
'global_settings' => [
'allowed_values' => "foo\nbar",
],
];
$this->plugin->processCckFieldValues($this->migration, 'field', $info);
$expected = [
'value' => [
'plugin' => 'static_map',
'source' => 'value',
'default_value' => 0,
'map' => [
'bar' => 1,
],
],
];
$this->assertSame($expected, $this->migration->getProcess()['process']);
}
/**
* @covers ::processCckFieldValues
*/
public function testProcessBooleanTextExplicitValues() {
$info = [
'widget_type' => 'optionwidgets_onoff',
'global_settings' => [
'allowed_values' => "foo|Foo\nbaz|Baz",
],
];
$this->plugin->processCckFieldValues($this->migration, 'field', $info);
$expected = [
'value' => [
'plugin' => 'static_map',
'source' => 'value',
'default_value' => 0,
'map' => [
'baz' => 1,
],
],
];
$this->assertSame($expected, $this->migration->getProcess()['process']);
}
/**
* Data provider for testGetFieldType().
*/
public function getFieldTypeProvider() {
return [
['string_long', 'text_textfield', ['text_processing' => FALSE]],
['string', 'text_textfield', [
'text_processing' => FALSE,
'max_length' => 128,
],
],
['string_long', 'text_textfield', [
'text_processing' => FALSE,
'max_length' => 4096,
],
],
['text_long', 'text_textfield', ['text_processing' => TRUE]],
['text', 'text_textfield', [
'text_processing' => TRUE,
'max_length' => 128,
],
],
['text_long', 'text_textfield', [
'text_processing' => TRUE,
'max_length' => 4096,
],
],
['list_string', 'optionwidgets_buttons'],
['list_string', 'optionwidgets_select'],
['boolean', 'optionwidgets_onoff'],
['text_long', 'text_textarea', ['text_processing' => TRUE]],
['string_long', 'text_textarea', ['text_processing' => FALSE]],
[NULL, 'undefined'],
];
}
/**
* @covers ::getFieldType
* @dataProvider getFieldTypeProvider
*/
public function testGetFieldType($expected_type, $widget_type, array $settings = []) {
$row = new Row(['widget_type' => $widget_type], ['widget_type' => []]);
$row->setSourceProperty('global_settings', $settings);
$this->assertSame($expected_type, $this->plugin->getFieldType($row));
}
}

View file

@ -0,0 +1,36 @@
<?php
namespace Drupal\Tests\text\Unit\Plugin\migrate\field\d6;
/**
* @coversDefaultClass \Drupal\text\Plugin\migrate\field\d6\TextField
* @group text
* @group legacy
*/
class TextFieldLegacyTest extends TextFieldTest {
/**
* @covers ::processFieldValues
* @expectedDeprecation Deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use defineValueProcessPipeline() instead. See https://www.drupal.org/node/2944598.
*/
public function testProcessFilteredTextFieldValues($method = 'processFieldValues') {
parent::testProcessFilteredTextFieldValues($method);
}
/**
* @covers ::processFieldValues
* @expectedDeprecation Deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use defineValueProcessPipeline() instead. See https://www.drupal.org/node/2944598.
*/
public function testProcessBooleanTextImplicitValues($method = 'processFieldValues') {
parent::testProcessBooleanTextImplicitValues($method);
}
/**
* @covers ::processFieldValues
* @expectedDeprecation Deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use defineValueProcessPipeline() instead. See https://www.drupal.org/node/2944598.
*/
public function testProcessBooleanTextExplicitValues($method = 'processFieldValues') {
parent::testProcessBooleanTextExplicitValues($method);
}
}

View file

@ -0,0 +1,167 @@
<?php
namespace Drupal\Tests\text\Unit\Plugin\migrate\field\d6;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Row;
use Drupal\Tests\UnitTestCase;
use Drupal\text\Plugin\migrate\field\d6\TextField;
use Prophecy\Argument;
/**
* @coversDefaultClass \Drupal\text\Plugin\migrate\field\d6\TextField
* @group text
*/
class TextFieldTest extends UnitTestCase {
/**
* @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
*/
protected $plugin;
/**
* @var \Drupal\migrate\Plugin\MigrationInterface
*/
protected $migration;
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->plugin = new TextField([], 'text', []);
$migration = $this->prophesize(MigrationInterface::class);
// The plugin's defineValueProcessPipeline() method will call
// setProcessOfProperty() and return nothing. So, in order to examine the
// process pipeline created by the plugin, we need to ensure that
// getProcess() always returns the last input to setProcessOfProperty().
$migration->setProcessOfProperty(Argument::type('string'), Argument::type('array'))
->will(function ($arguments) use ($migration) {
$migration->getProcess()->willReturn($arguments[1]);
});
$this->migration = $migration->reveal();
}
/**
* @covers ::defineValueProcessPipeline
*/
public function testProcessFilteredTextFieldValues($method = 'defineValueProcessPipeline') {
$field_info = [
'widget_type' => 'text_textfield',
];
$this->plugin->$method($this->migration, 'body', $field_info);
$process = $this->migration->getProcess();
$this->assertSame('sub_process', $process['plugin']);
$this->assertSame('body', $process['source']);
$this->assertSame('value', $process['process']['value']);
// Ensure that filter format IDs will be looked up in the filter format
// migrations.
$lookup = $process['process']['format'][2];
$this->assertSame('migration', $lookup['plugin']);
$this->assertContains('d6_filter_format', $lookup['migration']);
$this->assertContains('d7_filter_format', $lookup['migration']);
$this->assertSame('format', $lookup['source']);
}
/**
* @covers ::defineValueProcessPipeline
*/
public function testProcessBooleanTextImplicitValues($method = 'defineValueProcessPipeline') {
$info = [
'widget_type' => 'optionwidgets_onoff',
'global_settings' => [
'allowed_values' => "foo\nbar",
],
];
$this->plugin->$method($this->migration, 'field', $info);
$expected = [
'value' => [
'plugin' => 'static_map',
'source' => 'value',
'default_value' => 0,
'map' => [
'bar' => 1,
],
],
];
$this->assertSame($expected, $this->migration->getProcess()['process']);
}
/**
* @covers ::defineValueProcessPipeline
*/
public function testProcessBooleanTextExplicitValues($method = 'defineValueProcessPipeline') {
$info = [
'widget_type' => 'optionwidgets_onoff',
'global_settings' => [
'allowed_values' => "foo|Foo\nbaz|Baz",
],
];
$this->plugin->$method($this->migration, 'field', $info);
$expected = [
'value' => [
'plugin' => 'static_map',
'source' => 'value',
'default_value' => 0,
'map' => [
'baz' => 1,
],
],
];
$this->assertSame($expected, $this->migration->getProcess()['process']);
}
/**
* Data provider for testGetFieldType().
*/
public function getFieldTypeProvider() {
return [
['string_long', 'text_textfield', ['text_processing' => FALSE]],
['string', 'text_textfield', [
'text_processing' => FALSE,
'max_length' => 128,
],
],
['string_long', 'text_textfield', [
'text_processing' => FALSE,
'max_length' => 4096,
],
],
['text_long', 'text_textfield', ['text_processing' => TRUE]],
['text', 'text_textfield', [
'text_processing' => TRUE,
'max_length' => 128,
],
],
['text_long', 'text_textfield', [
'text_processing' => TRUE,
'max_length' => 4096,
],
],
['list_string', 'optionwidgets_buttons'],
['list_string', 'optionwidgets_select'],
['boolean', 'optionwidgets_onoff'],
['text_long', 'text_textarea', ['text_processing' => TRUE]],
['string_long', 'text_textarea', ['text_processing' => FALSE]],
[NULL, 'undefined'],
];
}
/**
* @covers ::getFieldType
* @dataProvider getFieldTypeProvider
*/
public function testGetFieldType($expected_type, $widget_type, array $settings = []) {
$row = new Row();
$row->setSourceProperty('widget_type', $widget_type);
$row->setSourceProperty('global_settings', $settings);
$this->assertSame($expected_type, $this->plugin->getFieldType($row));
}
}

View file

@ -0,0 +1,11 @@
<?php
namespace Drupal\Tests\text\Unit\Plugin\migrate\field\d7;
use Drupal\Tests\text\Unit\Plugin\migrate\field\d6\TextFieldTest as D6TextFieldTest;
/**
* @coversDefaultClass \Drupal\text\Plugin\migrate\field\d7\TextField
* @group text
*/
class TextFieldTest extends D6TextFieldTest {}