Same filename and directory in other branches
- 8.9.x core/modules/menu_link_content/tests/src/Kernel/Plugin/migrate/process/LinkUriTest.php
- 9 core/modules/menu_link_content/tests/src/Kernel/Plugin/migrate/process/LinkUriTest.php
Namespace
Drupal\Tests\menu_link_content\Kernel\Plugin\migrate\process
File
core/modules/menu_link_content/tests/src/Kernel/Plugin/migrate/process/LinkUriTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\menu_link_content\Kernel\Plugin\migrate\process;
use Drupal\KernelTests\KernelTestBase;
use Drupal\menu_link_content\Plugin\migrate\process\LinkUri;
use Drupal\migrate\MigrateException;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
use Drupal\node\Entity\Node;
use Drupal\Tests\user\Traits\UserCreationTrait;
class LinkUriTest extends KernelTestBase {
use UserCreationTrait;
protected static $modules = [
'node',
'user',
];
protected function setUp() : void {
parent::setUp();
$this
->setUpCurrentUser();
$this
->installEntitySchema('node');
}
public function testRouted($value, $expected) {
$actual = $this
->doTransform($value);
$this
->assertSame($expected, $actual);
}
public static function providerTestRouted() {
$tests = [];
$value = 'http://example.com';
$expected = 'http://example.com';
$tests['with_scheme'] = [
$value,
$expected,
];
$value = '<front>';
$expected = 'internal:/';
$tests['front'] = [
$value,
$expected,
];
$value = '<nolink>';
$expected = 'route:<nolink>';
$tests['nolink'] = [
$value,
$expected,
];
return $tests;
}
public function testNotRouted($value, $exception_message) {
$this
->expectException(MigrateException::class);
$this
->expectExceptionMessage($exception_message);
$this
->doTransform($value);
}
public static function providerTestNotRouted() {
$tests = [];
$message = 'The path "%s" failed validation.';
$value = '/test';
$expected = 'internal:/test';
$exception_message = sprintf($message, $expected);
$tests['leading_slash'] = [
$value,
$exception_message,
];
$value = 'test';
$expected = 'internal:/test';
$exception_message = sprintf($message, $expected);
$tests['without_scheme'] = [
$value,
$exception_message,
];
return $tests;
}
public function testDisablingRouteValidation($value, $expected) {
Node::create([
'nid' => 1,
'title' => 'test',
'type' => 'page',
])
->save();
$actual = $this
->doTransform($value, [
'validate_route' => FALSE,
]);
$this
->assertSame($expected, $actual);
}
public static function providerTestDisablingRouteValidation() {
$tests = [];
$value = 'node/1';
$expected = 'entity:node/1';
$tests['routed'] = [
$value,
$expected,
];
$value = 'node/2';
$expected = 'base:node/2';
$tests['unrouted'] = [
$value,
$expected,
];
return $tests;
}
public function doTransform($value, $configuration = []) {
$entityTypeManager = $this->container
->get('entity_type.manager');
$row = new Row();
$executable = $this
->prophesize(MigrateExecutableInterface::class)
->reveal();
$plugin = new LinkUri($configuration, 'link_uri', [], $entityTypeManager);
$actual = $plugin
->transform($value, $executable, $row, 'destination_property');
return $actual;
}
}
Classes