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,8 @@
name: Link test base field
description: Tests link field as an optional base field
type: module
core: 8.x
hidden: true
dependencies:
- drupal:link
- drupal:entity_test

View file

@ -0,0 +1,35 @@
<?php
/**
* @file
* Contains main module functions.
*/
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\link\LinkItemInterface;
/**
* Implements hook_entity_base_field_info().
*/
function link_test_base_field_entity_base_field_info(EntityTypeInterface $entity_type) {
$fields = [];
if ($entity_type->id() === 'entity_test') {
$fields['links'] = BaseFieldDefinition::create('link')
->setLabel(t('Links'))
->setRevisionable(TRUE)
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setDescription(t('Add links to the entity.'))
->setRequired(FALSE)
->setSettings([
'link_type' => LinkItemInterface::LINK_GENERIC,
'title' => DRUPAL_REQUIRED,
])
->setDisplayOptions('form', [
'type' => 'link_default',
'weight' => 49,
]);
}
return $fields;
}

View file

@ -5,6 +5,6 @@ package: Testing
version: VERSION
core: 8.x
dependencies:
- node
- views
- link
- drupal:node
- drupal:views
- drupal:link

View file

@ -24,7 +24,12 @@ class LinkFieldTest extends BrowserTestBase {
*
* @var array
*/
public static $modules = ['entity_test', 'link', 'node'];
public static $modules = [
'entity_test',
'link',
'node',
'link_test_base_field',
];
/**
* A field to use in this test class.
@ -54,7 +59,7 @@ class LinkFieldTest extends BrowserTestBase {
* Tests link field URL validation.
*/
public function testURLValidation() {
$field_name = Unicode::strtolower($this->randomMachineName());
$field_name = mb_strtolower($this->randomMachineName());
// Create a field with settings to validate.
$this->fieldStorage = FieldStorageConfig::create([
'field_name' => $field_name,
@ -116,6 +121,10 @@ class LinkFieldTest extends BrowserTestBase {
'/?example=llama' => '&lt;front&gt;?example=llama',
'/#example' => '&lt;front&gt;#example',
// Trailing spaces should be ignored.
'/ ' => '&lt;front&gt;',
'/path with spaces ' => '/path with spaces',
// @todo '<front>' is valid input for BC reasons, may be removed by
// https://www.drupal.org/node/2421941
'<front>' => '&lt;front&gt;',
@ -195,7 +204,7 @@ class LinkFieldTest extends BrowserTestBase {
preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match);
$id = $match[1];
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]));
$this->assertRaw($string);
$this->assertRaw('"' . $string . '"');
}
}
@ -221,7 +230,7 @@ class LinkFieldTest extends BrowserTestBase {
* Tests the link title settings of a link field.
*/
public function testLinkTitle() {
$field_name = Unicode::strtolower($this->randomMachineName());
$field_name = mb_strtolower($this->randomMachineName());
// Create a field with settings to validate.
$this->fieldStorage = FieldStorageConfig::create([
'field_name' => $field_name,
@ -276,13 +285,21 @@ class LinkFieldTest extends BrowserTestBase {
$this->assertRaw('placeholder="Enter the text for this link"');
$this->assertFieldByName("{$field_name}[0][title]", '', 'Link text field found.');
if ($title_setting === DRUPAL_OPTIONAL) {
// Verify that the URL is required, if the link text is non-empty.
$edit = [
"{$field_name}[0][title]" => 'Example',
];
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertText(t('The URL field is required when the @title field is specified.', ['@title' => t('Link text')]));
}
if ($title_setting === DRUPAL_REQUIRED) {
// Verify that the link text is required, if the URL is non-empty.
$edit = [
"{$field_name}[0][uri]" => 'http://www.example.com',
];
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertText(t('@name field is required.', ['@name' => t('Link text')]));
$this->assertText(t('@title field is required if there is @uri input.', ['@title' => t('Link text'), '@uri' => t('URL')]));
// Verify that the link text is not required, if the URL is empty.
$edit = [
@ -335,7 +352,7 @@ class LinkFieldTest extends BrowserTestBase {
* Tests the default 'link' formatter.
*/
public function testLinkFormatter() {
$field_name = Unicode::strtolower($this->randomMachineName());
$field_name = mb_strtolower($this->randomMachineName());
// Create a field with settings to validate.
$this->fieldStorage = FieldStorageConfig::create([
'field_name' => $field_name,
@ -490,7 +507,7 @@ class LinkFieldTest extends BrowserTestBase {
* merged, since they involve different configuration and output.
*/
public function testLinkSeparateFormatter() {
$field_name = Unicode::strtolower($this->randomMachineName());
$field_name = mb_strtolower($this->randomMachineName());
// Create a field with settings to validate.
$this->fieldStorage = FieldStorageConfig::create([
'field_name' => $field_name,
@ -606,6 +623,48 @@ class LinkFieldTest extends BrowserTestBase {
}
}
/**
* Test '#link_type' property exists on 'link_default' widget.
*
* Make sure the 'link_default' widget exposes a '#link_type' property on
* its element. Modules can use it to understand if a text form element is
* a link and also which LinkItemInterface::LINK_* is (EXTERNAL, GENERIC,
* INTERNAL).
*/
public function testLinkTypeOnLinkWidget() {
$link_type = LinkItemInterface::LINK_EXTERNAL;
$field_name = mb_strtolower($this->randomMachineName());
// Create a field with settings to validate.
$this->fieldStorage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'link',
'cardinality' => 1,
]);
$this->fieldStorage->save();
FieldConfig::create([
'field_storage' => $this->fieldStorage,
'label' => 'Read more about this entity',
'bundle' => 'entity_test',
'settings' => [
'title' => DRUPAL_OPTIONAL,
'link_type' => $link_type,
],
])->save();
$this->container->get('entity.manager')
->getStorage('entity_form_display')
->load('entity_test.entity_test.default')
->setComponent($field_name, [
'type' => 'link_default',
])
->save();
$form = \Drupal::service('entity.form_builder')->getForm(EntityTest::create());
$this->assertEqual($form[$field_name]['widget'][0]['uri']['#link_type'], $link_type);
}
/**
* Tests editing a link to a non-node entity.

View file

@ -2,10 +2,13 @@
namespace Drupal\Tests\link\Functional;
use Drupal\Component\Utility\Unicode;
use Drupal\field_ui\Tests\FieldUiTestTrait;
use Drupal\Component\Utility\Html;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\link\LinkItemInterface;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\field_ui\Traits\FieldUiTestTrait;
/**
* Tests link field UI functionality.
@ -30,14 +33,37 @@ class LinkFieldUITest extends BrowserTestBase {
*/
protected $adminUser;
/**
* A user that should see the help texts.
*
* @var \Drupal\user\Entity\User
*/
protected $helpTextUser;
/**
* The first content type to add fields to.
*
* @var \Drupal\node\Entity\NodeType
*/
protected $firstContentType;
/**
* The second content type to add fields to.
*
* @var \Drupal\node\Entity\NodeType
*/
protected $secondContentType;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->firstContentType = $this->drupalCreateContentType();
$this->secondContentType = $this->drupalCreateContentType();
$this->adminUser = $this->drupalCreateUser(['administer content types', 'administer node fields', 'administer node display']);
$this->drupalLogin($this->adminUser);
$this->helpTextUser = $this->drupalCreateUser(['create ' . $this->secondContentType->id() . ' content']);
$this->drupalPlaceBlock('system_breadcrumb_block');
}
@ -45,16 +71,91 @@ class LinkFieldUITest extends BrowserTestBase {
* Tests the link field UI.
*/
public function testFieldUI() {
// Add a content type.
$type = $this->drupalCreateContentType();
$type_path = 'admin/structure/types/manage/' . $type->id();
$add_path = 'node/add/' . $type->id();
foreach ($this->providerTestFieldUI() as $item) {
list($cardinality, $link_type, $title, $label, $field_name) = $item;
$this->runFieldUIItem($cardinality, $link_type, $title, $label, $field_name);
}
}
/**
* Provides test data for ::testFieldUI().
*/
protected function providerTestFieldUI() {
// There are many combinations of field settings: where the description
// should show: variation on internal, external, both; cardinality (where
// the fieldset is hidden or used); and link text shown (required or
// optional) or disabled. There are two descriptions: field and URL help
// text.
$cardinalities = [1, 2];
$title_settings = [
DRUPAL_DISABLED,
DRUPAL_OPTIONAL,
];
$link_types = [
LinkItemInterface::LINK_EXTERNAL,
LinkItemInterface::LINK_GENERIC,
LinkItemInterface::LINK_INTERNAL,
];
// Test all variations of link types on all cardinalities.
foreach ($cardinalities as $cardinality) {
foreach ($link_types as $link_type) {
// Now, test this with both the title enabled and disabled.
foreach ($title_settings as $title_setting) {
// Test both empty and non-empty labels.
foreach ([TRUE, FALSE] as $label_provided) {
// Generate a unique machine name for the field so it can be
// identified in the test.
$id = implode('_', [
'link',
$cardinality,
$link_type,
$title_setting,
(int) $label_provided,
]);
// Use a unique label that contains some HTML.
$label = '<img src="http://example.com">' . $id;
yield [
$cardinality,
$link_type,
$title_setting,
$label_provided ? $label : '',
$id,
];
}
}
}
}
}
/**
* Tests one link field UI item.
*
* @param int $cardinality
* The field cardinality.
* @param int $link_type
* Determine if the link is external, internal or both.
* @param int $title
* Determine if the field will display the link text field.
* @param string $label
* The field label.
* @param string $field_name
* The unique machine name for the field.
*/
public function runFieldUIItem($cardinality, $link_type, $title, $label, $field_name) {
$this->drupalLogin($this->adminUser);
$type_path = 'admin/structure/types/manage/' . $this->firstContentType->id();
// Add a link field to the newly-created type. It defaults to allowing both
// internal and external links.
$label = $this->randomMachineName();
$field_name = Unicode::strtolower($label);
$this->fieldUIAddNewField($type_path, $field_name, $label, 'link');
$field_label = str_replace('_', ' ', $field_name);
$description = 'link field description';
$field_edit = [
'description' => $description,
];
$this->fieldUIAddNewField($type_path, $field_name, $field_label, 'link', [], $field_edit);
// Load the formatter page to check that the settings summary does not
// generate warnings.
@ -62,31 +163,94 @@ class LinkFieldUITest extends BrowserTestBase {
$this->drupalGet("$type_path/display");
$this->assertText(t('Link text trimmed to @limit characters', ['@limit' => 80]));
// Test the help text displays when the link field allows both internal and
// external links.
$this->drupalLogin($this->drupalCreateUser(['create ' . $type->id() . ' content']));
$storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'node',
'type' => 'link',
'cardinality' => $cardinality,
]);
$storage->save();
FieldConfig::create([
'field_storage' => $storage,
'label' => $label,
'bundle' => $this->secondContentType->id(),
'settings' => [
'title' => $title,
'link_type' => $link_type,
],
])->save();
// Make the fields visible in the form display.
$form_display_id = implode('.', ['node', $this->secondContentType->id(), 'default']);
$form_display = EntityFormDisplay::load($form_display_id);
$form_display->setComponent($field_name, ['region' => 'content']);
$form_display->save();
// Log in a user that is allowed to create this content type, see if
// the user can see the expected help text.
$this->drupalLogin($this->helpTextUser);
$add_path = 'node/add/' . $this->secondContentType->id();
$this->drupalGet($add_path);
$this->assertRaw('You can also enter an internal path such as <em class="placeholder">/node/add</em> or an external URL such as <em class="placeholder">http://example.com</em>.');
// Log in an admin to set up the next content type.
$this->drupalLogin($this->adminUser);
$expected_help_texts = [
LinkItemInterface::LINK_EXTERNAL => 'This must be an external URL such as <em class="placeholder">http://example.com</em>.',
LinkItemInterface::LINK_GENERIC => 'You can also enter an internal path such as <em class="placeholder">/node/add</em> or an external URL such as <em class="placeholder">http://example.com</em>. Enter <em class="placeholder">&lt;front&gt;</em> to link to the front page.',
LinkItemInterface::LINK_INTERNAL => rtrim(\Drupal::url('<front>', [], ['absolute' => TRUE]), '/'),
];
// Add a different content type.
$type = $this->drupalCreateContentType();
$type_path = 'admin/structure/types/manage/' . $type->id();
$add_path = 'node/add/' . $type->id();
// Check that the help texts we assume should be there, is there.
$this->assertFieldContainsRawText($field_name, $expected_help_texts[$link_type]);
if ($link_type === LinkItemInterface::LINK_INTERNAL) {
// Internal links have no "system" description. Test that none
// of the other help texts show here.
$this->assertNoFieldContainsRawText($field_name, $expected_help_texts[LinkItemInterface::LINK_EXTERNAL]);
$this->assertNoFieldContainsRawText($field_name, $expected_help_texts[LinkItemInterface::LINK_GENERIC]);
}
// Also assert that the description we made is here, no matter what the
// cardinality or link setting.
if (!empty($label)) {
$this->assertFieldContainsRawText($field_name, $label);
}
}
// Add a link field to the newly-created type. Specify it must allow
// external only links.
$label = $this->randomMachineName();
$field_name = Unicode::strtolower($label);
$field_edit = ['settings[link_type]' => LinkItemInterface::LINK_EXTERNAL];
$this->fieldUIAddNewField($type_path, $field_name, $label, 'link', [], $field_edit);
/**
* Checks that given field contains the given raw text.
*
* @param string $field_name
* The name of the field to check.
* @param string $text
* The text to check.
*/
protected function assertFieldContainsRawText($field_name, $text) {
$this->assertTrue((bool) preg_match('/' . preg_quote($text, '/') . '/ui', $this->getFieldHtml($field_name)));
}
// Test the help text displays when link allows only external links.
$this->drupalLogin($this->drupalCreateUser(['create ' . $type->id() . ' content']));
$this->drupalGet($add_path);
$this->assertRaw('This must be an external URL such as <em class="placeholder">http://example.com</em>.');
/**
* Checks that given field does not contain the given raw text.
*
* @param string $field_name
* The name of the field to check.
* @param string $text
* The text to check.
*/
protected function assertNoFieldContainsRawText($field_name, $text) {
$this->assertFalse((bool) preg_match('/' . preg_quote($text, '/') . '/ui', $this->getFieldHtml($field_name)));
}
/**
* Returns the raw HTML for the given field.
*
* @param $field_name
* The name of the field for which to return the HTML.
*
* @return string
* The raw HTML.
*/
protected function getFieldHtml($field_name) {
$css_id = Html::cleanCssIdentifier('edit-' . $field_name . '-wrapper');
return $this->xpath('//*[@id=:id]', [':id' => $css_id])[0]->getHtml();
}
}

View file

@ -0,0 +1,98 @@
<?php
namespace Drupal\Tests\link\Functional\Views;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
/**
* Tests the views integration for link tokens.
*
* @group link
*/
class LinkViewsTokensTest extends ViewTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['link_test_views'];
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_link_tokens'];
/**
* The field name used for the link field.
*
* @var string
*/
protected $fieldName = 'field_link';
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
ViewTestData::createTestViews(get_class($this), ['link_test_views']);
// Create Basic page node type.
$this->drupalCreateContentType([
'type' => 'page',
'name' => 'Basic page',
]);
// Create a field.
FieldStorageConfig::create([
'field_name' => $this->fieldName,
'type' => 'link',
'entity_type' => 'node',
'cardinality' => 1,
])->save();
FieldConfig::create([
'field_name' => $this->fieldName,
'entity_type' => 'node',
'bundle' => 'page',
'label' => 'link field',
])->save();
}
public function testLinkViewsTokens() {
// Array of URI's to test.
$uris = [
'http://www.drupal.org' => 'Drupal.org',
];
// Add nodes with the URI's and titles.
foreach ($uris as $uri => $title) {
$values = ['type' => 'page'];
$values[$this->fieldName][] = ['uri' => $uri, 'title' => $title, 'options' => ['attributes' => ['class' => 'test-link-class']]];
$this->drupalCreateNode($values);
}
$this->drupalGet('test_link_tokens');
foreach ($uris as $uri => $title) {
// Formatted link: {{ field_link }}<br />
$this->assertRaw("Formated: <a href=\"$uri\" class=\"test-link-class\">$title</a>");
// Raw uri: {{ field_link__uri }}<br />
$this->assertRaw("Raw uri: $uri");
// Raw title: {{ field_link__title }}<br />
$this->assertRaw("Raw title: $title");
// Raw options: {{ field_link__options }}<br />
// Options is an array and should return empty after token replace.
$this->assertRaw("Raw options: .");
}
}
}

View file

@ -0,0 +1,83 @@
<?php
namespace Drupal\Tests\link\Kernel;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldConfig;
use Drupal\link\LinkItemInterface;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Tests\field\Kernel\FieldKernelTestBase;
/**
* Tests link field serialization.
*
* @group link
*/
class LinkItemSerializationTest extends FieldKernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['link', 'serialization'];
/**
* The serializer service.
*
* @var \Symfony\Component\Serializer\SerializerInterface
*/
protected $serializer;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('user');
$this->serializer = \Drupal::service('serializer');
// Create a generic, external, and internal link fields for validation.
FieldStorageConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'field_test',
'type' => 'link',
])->save();
FieldConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'field_test',
'bundle' => 'entity_test',
'settings' => ['link_type' => LinkItemInterface::LINK_GENERIC],
])->save();
}
/**
* Tests the serialization.
*/
public function testLinkSerialization() {
// Create entity.
$entity = EntityTest::create();
$url = 'https://www.drupal.org?test_param=test_value';
$parsed_url = UrlHelper::parse($url);
$title = $this->randomMachineName();
$class = $this->randomMachineName();
$entity->field_test->uri = $parsed_url['path'];
$entity->field_test->title = $title;
$entity->field_test->first()
->get('options')
->set('query', $parsed_url['query']);
$entity->field_test->first()
->get('options')
->set('attributes', ['class' => $class]);
$entity->save();
$serialized = $this->serializer->serialize($entity, 'json');
$deserialized = $this->serializer->deserialize($serialized, EntityTest::class, 'json');
$options_expected = [
'query' => $parsed_url['query'],
'attributes' => ['class' => $class],
];
$this->assertSame($options_expected, $deserialized->field_test->options);
}
}

View file

@ -0,0 +1,18 @@
<?php
namespace Drupal\Tests\link\Kernel\Plugin\migrate\cckfield\d7;
/**
* @group link
* @group legacy
*/
class LinkCckDeprecationTest extends LinkCckTest {
/**
* @expectedDeprecation Deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use alterFieldInstanceMigration() instead. See https://www.drupal.org/node/2944598.
*/
public function testAlterFieldInstanceMigration($method = 'processFieldInstance') {
parent::testAlterFieldInstanceMigration($method);
}
}

View file

@ -0,0 +1,73 @@
<?php
namespace Drupal\Tests\link\Kernel\Plugin\migrate\cckfield\d7;
use Drupal\KernelTests\KernelTestBase;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\link\Plugin\migrate\cckfield\d7\LinkField;
use Prophecy\Argument;
/**
* @coversDefaultClass \Drupal\link\Plugin\migrate\cckfield\d7\LinkField
* @group link
* @group legacy
*/
class LinkCckTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['system'];
/**
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface
*/
protected $plugin;
/**
* @var \Drupal\migrate\Plugin\MigrationInterface
*/
protected $migration;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->plugin = new LinkField([], 'link', []);
$migration = $this->prophesize(MigrationInterface::class);
// The plugin's alterFieldInstanceMigration() method will call
// mergeProcessOfProperty() 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 mergeProcessOfProperty().
$migration->mergeProcessOfProperty(Argument::type('string'), Argument::type('array'))
->will(function ($arguments) use ($migration) {
$migration->getProcess()->willReturn($arguments[1]);
});
$this->migration = $migration->reveal();
}
/**
* @covers ::alterFieldInstanceMigration
*/
public function testAlterFieldInstanceMigration($method = 'alterFieldInstanceMigration') {
$this->plugin->$method($this->migration);
$expected = [
'plugin' => 'static_map',
'source' => 'settings/title',
'bypass' => TRUE,
'map' => [
'disabled' => DRUPAL_DISABLED,
'optional' => DRUPAL_OPTIONAL,
'required' => DRUPAL_REQUIRED,
],
];
$this->assertSame($expected, $this->migration->getProcess());
}
}

View file

@ -0,0 +1,18 @@
<?php
namespace Drupal\Tests\link\Kernel\Plugin\migrate\field\d7;
/**
* @group legacy
* @group link
*/
class LinkFieldLegacyTest extends LinkFieldTest {
/**
* @expectedDeprecation Deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use alterFieldInstanceMigration() instead. See https://www.drupal.org/node/2944598.
*/
public function testAlterFieldInstanceMigration($method = 'processFieldInstance') {
parent::testAlterFieldInstanceMigration($method);
}
}

View file

@ -0,0 +1,72 @@
<?php
namespace Drupal\Tests\link\Kernel\Plugin\migrate\field\d7;
use Drupal\KernelTests\KernelTestBase;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\link\Plugin\migrate\field\d7\LinkField;
use Prophecy\Argument;
/**
* @coversDefaultClass \Drupal\link\Plugin\migrate\field\d7\LinkField
* @group link
*/
class LinkFieldTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['system'];
/**
* @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
*/
protected $plugin;
/**
* @var \Drupal\migrate\Plugin\MigrationInterface
*/
protected $migration;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->plugin = new LinkField([], 'link', []);
$migration = $this->prophesize(MigrationInterface::class);
// The plugin's alterFieldInstanceMigration() method will call
// mergeProcessOfProperty() 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 mergeProcessOfProperty().
$migration->mergeProcessOfProperty(Argument::type('string'), Argument::type('array'))
->will(function ($arguments) use ($migration) {
$migration->getProcess()->willReturn($arguments[1]);
});
$this->migration = $migration->reveal();
}
/**
* @covers ::alterFieldInstanceMigration
*/
public function testAlterFieldInstanceMigration($method = 'alterFieldInstanceMigration') {
$this->plugin->$method($this->migration);
$expected = [
'plugin' => 'static_map',
'source' => 'settings/title',
'bypass' => TRUE,
'map' => [
'disabled' => DRUPAL_DISABLED,
'optional' => DRUPAL_OPTIONAL,
'required' => DRUPAL_REQUIRED,
],
];
$this->assertSame($expected, $this->migration->getProcess());
}
}

View file

@ -31,7 +31,6 @@ class LinkNotExistingInternalConstraintValidatorTest extends UnitTestCase {
->method('addViolation');
}
$constraint = new LinkNotExistingInternalConstraint();
$validator = new LinkNotExistingInternalConstraintValidator();

View file

@ -0,0 +1,61 @@
<?php
namespace Drupal\Tests\link\Unit\Plugin\migrate\cckfield;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\link\Plugin\migrate\cckfield\LinkField;
use Prophecy\Argument;
/**
* @coversDefaultClass \Drupal\link\Plugin\migrate\cckfield\LinkField
* @group link
* @group legacy
*/
class LinkCckTest extends UnitTestCase {
/**
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface
*/
protected $plugin;
/**
* @var \Drupal\migrate\Plugin\MigrationInterface
*/
protected $migration;
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->plugin = new LinkField([], 'link', []);
$migration = $this->prophesize(MigrationInterface::class);
// The plugin's processCckFieldValues() method will call
// mergeProcessOfProperty() 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 mergeProcessOfProperty().
$migration->mergeProcessOfProperty(Argument::type('string'), Argument::type('array'))
->will(function ($arguments) use ($migration) {
$migration->getProcess()->willReturn($arguments[1]);
});
$this->migration = $migration->reveal();
}
/**
* @covers ::processCckFieldValues
* @expectedDeprecation LinkField is deprecated in Drupal 8.3.x and will be be removed before Drupal 9.0.x. Use \Drupal\link\Plugin\migrate\field\d6\LinkField instead.
*/
public function testProcessCckFieldValues() {
$this->plugin->processCckFieldValues($this->migration, 'somefieldname', []);
$expected = [
'plugin' => 'd6_cck_link',
'source' => 'somefieldname',
];
$this->assertSame($expected, $this->migration->getProcess());
}
}

View file

@ -0,0 +1,18 @@
<?php
namespace Drupal\Tests\link\Unit\Plugin\migrate\field\d6;
/**
* @group legacy
* @group link
*/
class LinkFieldLegacyTest extends LinkFieldTest {
/**
* @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 testDefineValueProcessPipeline($method = 'processFieldValues') {
parent::testDefineValueProcessPipeline($method);
}
}

View file

@ -0,0 +1,59 @@
<?php
namespace Drupal\Tests\link\Unit\Plugin\migrate\field\d6;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\link\Plugin\migrate\field\d6\LinkField;
use Prophecy\Argument;
/**
* @coversDefaultClass \Drupal\link\Plugin\migrate\field\d6\LinkField
* @group link
*/
class LinkFieldTest extends UnitTestCase {
/**
* @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
*/
protected $plugin;
/**
* @var \Drupal\migrate\Plugin\MigrationInterface
*/
protected $migration;
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->plugin = new LinkField([], 'link', []);
$migration = $this->prophesize(MigrationInterface::class);
// The plugin's defineValueProcessPipeline() method will call
// mergeProcessOfProperty() 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 mergeProcessOfProperty().
$migration->mergeProcessOfProperty(Argument::type('string'), Argument::type('array'))
->will(function ($arguments) use ($migration) {
$migration->getProcess()->willReturn($arguments[1]);
});
$this->migration = $migration->reveal();
}
/**
* @covers ::defineValueProcessPipeline
*/
public function testDefineValueProcessPipeline($method = 'defineValueProcessPipeline') {
$this->plugin->$method($this->migration, 'somefieldname', []);
$expected = [
'plugin' => 'field_link',
'source' => 'somefieldname',
];
$this->assertSame($expected, $this->migration->getProcess());
}
}

View file

@ -0,0 +1,92 @@
<?php
namespace Drupal\Tests\link\Unit\Plugin\migrate\process;
use Drupal\link\Plugin\migrate\process\FieldLink;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Row;
use Drupal\Tests\UnitTestCase;
/**
* @group Link
*/
class FieldLinkTest extends UnitTestCase {
/**
* Test the url transformations in the FieldLink process plugin.
*
* @dataProvider canonicalizeUriDataProvider
*/
public function testCanonicalizeUri($url, $expected, $configuration = []) {
$link_plugin = new FieldLink($configuration, '', [], $this->getMock(MigrationInterface::class));
$transformed = $link_plugin->transform([
'url' => $url,
'title' => '',
'attributes' => serialize([]),
], $this->getMock(MigrateExecutableInterface::class), $this->getMockBuilder(Row::class)->disableOriginalConstructor()->getMock(), NULL);
$this->assertEquals($expected, $transformed['uri']);
}
/**
* Data provider for testCanonicalizeUri.
*/
public function canonicalizeUriDataProvider() {
return [
'Simple front-page' => [
'<front>',
'internal:/',
],
'Front page with query' => [
'<front>?query=1',
'internal:/?query=1',
],
'No leading forward slash' => [
'node/10',
'internal:/node/10',
],
'Leading forward slash' => [
'/node/10',
'internal:/node/10',
],
'Existing scheme' => [
'scheme:test',
'scheme:test',
],
'Absolute URL with protocol prefix' => [
'http://www.google.com',
'http://www.google.com',
],
'Absolute URL without protocol prefix' => [
'www.yahoo.com',
'http://www.yahoo.com',
],
'Absolute URL without protocol prefix nor www' => [
'yahoo.com',
'https://yahoo.com',
['uri_scheme' => 'https://'],
],
'Absolute URL with non-standard characters' => [
'http://www.ßÀÑÐ¥ƒå¢ë.com',
'http://www.ßÀÑÐ¥ƒå¢ë.com',
],
'Absolute URL with non-standard characters, without protocol prefix' => [
'www.ÐØÑ¢åþë.com',
'http://www.ÐØÑ¢åþë.com',
],
'Absolute URL with non-standard top level domain' => [
'http://www.example.xxx',
'http://www.example.xxx',
],
'Internal link with fragment' => [
'/node/10#top',
'internal:/node/10#top',
],
'External link with fragment' => [
'http://www.example.com/page#links',
'http://www.example.com/page#links',
],
];
}
}

View file

@ -7,6 +7,7 @@ use Drupal\Tests\UnitTestCase;
/**
* @group Link
* @group legacy
*/
class FieldLinkTest extends UnitTestCase {