3 namespace Drupal\Tests\menu_link_content\Kernel\Plugin\migrate\process;
5 use Drupal\menu_link_content\Plugin\migrate\process\LinkUri;
6 use Drupal\migrate\MigrateException;
7 use Drupal\migrate\MigrateExecutableInterface;
8 use Drupal\migrate\Row;
9 use Drupal\KernelTests\KernelTestBase;
12 * Tests \Drupal\menu_link_content\Plugin\migrate\process\LinkUri.
14 * @group menu_link_content
16 * @coversDefaultClass \Drupal\menu_link_content\Plugin\migrate\process\LinkUri
18 class LinkUriTest extends KernelTestBase {
21 * Tests LinkUri::transform().
24 * The value to pass to LinkUri::transform().
25 * @param string $expected
26 * The expected return value of LinkUri::transform().
28 * @dataProvider providerTestRouted
32 public function testRouted(array $value, $expected) {
33 $actual = $this->doTransform($value);
34 $this->assertSame($expected, $actual);
38 * Provides test cases for LinkUriTest::testTransform().
41 * An array of test cases, each which the following values:
42 * - The value array to pass to LinkUri::transform().
43 * - The expected path returned by LinkUri::transform().
45 public function providerTestRouted() {
48 $value = ['http://example.com'];
49 $expected = 'http://example.com';
50 $tests['with_scheme'] = [$value, $expected];
53 $expected = 'internal:/';
54 $tests['front'] = [$value, $expected];
60 * Tests that Non routed URLs throws an exception.
63 * The value to pass to LinkUri::transform().
64 * @param string $exception_message
65 * The expected exception message.
67 * @dataProvider providerTestNotRouted
69 public function testNotRouted(array $value, $exception_message) {
70 $this->setExpectedException(MigrateException::class, $exception_message);
71 $this->doTransform($value);
75 * Provides test cases for LinkUriTest::testNotRouted().
78 * An array of test cases, each which the following values:
79 * - The value array to pass to LinkUri::transform().
80 * - The expected path returned by LinkUri::transform().
81 * - (optional) A URL object that the path validator prophecy will return.
83 public function providerTestNotRouted() {
86 $message = 'The path "%s" failed validation.';
89 $expected = 'internal:/test';
90 $exception_message = sprintf($message, $expected);
91 $tests['leading_slash'] = [$value, $exception_message];
94 $expected = 'internal:/test';
95 $exception_message = sprintf($message, $expected);
96 $tests['without_scheme'] = [$value, $exception_message];
102 * Transforms a link path into an 'internal:' or 'entity:' URI.
104 * @param array $value
105 * The value to pass to LinkUri::transform().
108 * The transformed link.
110 public function doTransform(array $value) {
111 $entityTypeManager = $this->container->get('entity_type.manager');
112 $routeBuilder = $this->container->get('router.builder');
114 $executable = $this->prophesize(MigrateExecutableInterface::class)->reveal();
116 $plugin = new LinkUri([], 'link_uri', [], $entityTypeManager, $routeBuilder);
117 $actual = $plugin->transform($value, $executable, $row, 'destinationproperty');