X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fmenu_link_content%2Ftests%2Fsrc%2FKernel%2FPlugin%2Fmigrate%2Fprocess%2FLinkUriTest.php;fp=web%2Fcore%2Fmodules%2Fmenu_link_content%2Ftests%2Fsrc%2FKernel%2FPlugin%2Fmigrate%2Fprocess%2FLinkUriTest.php;h=5ae840f766b710c6db5c6025df9eafc96fe5ce08;hp=74e88d18174c49f97c733deca9d5ef66c8ed7563;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/modules/menu_link_content/tests/src/Kernel/Plugin/migrate/process/LinkUriTest.php b/web/core/modules/menu_link_content/tests/src/Kernel/Plugin/migrate/process/LinkUriTest.php index 74e88d181..5ae840f76 100644 --- a/web/core/modules/menu_link_content/tests/src/Kernel/Plugin/migrate/process/LinkUriTest.php +++ b/web/core/modules/menu_link_content/tests/src/Kernel/Plugin/migrate/process/LinkUriTest.php @@ -6,6 +6,7 @@ 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\KernelTests\KernelTestBase; /** @@ -17,6 +18,22 @@ use Drupal\KernelTests\KernelTestBase; */ class LinkUriTest extends KernelTestBase { + /** + * Modules to enable. + * + * @var array + */ + public static $modules = ['node', 'user']; + + /** + * {@inheritdoc} + */ + public function setUp() { + parent::setUp(); + $this->installEntitySchema('node'); + $this->installEntitySchema('user'); + } + /** * Tests LinkUri::transform(). * @@ -98,22 +115,70 @@ class LinkUriTest extends KernelTestBase { return $tests; } + /** + * Tests disabling route validation in LinkUri::transform(). + * + * @param array $value + * The value to pass to LinkUri::transform(). + * @param string $expected + * The expected return value of LinkUri::transform(). + * + * @dataProvider providerTestDisablingRouteValidation + * + * @covers ::transform + */ + public function testDisablingRouteValidation(array $value, $expected) { + // Create a node so we have a valid route. + Node::create([ + 'nid' => 1, + 'title' => 'test', + 'type' => 'page', + ])->save(); + + $actual = $this->doTransform($value, ['validate_route' => FALSE]); + $this->assertSame($expected, $actual); + } + + /** + * Provides test cases for LinkUriTest::testDisablingRouteValidation(). + * + * @return array + * An array of test cases, each which the following values: + * - The value array to pass to LinkUri::transform(). + * - The expected path returned by LinkUri::transform(). + */ + public 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; + } + /** * Transforms a link path into an 'internal:' or 'entity:' URI. * * @param array $value * The value to pass to LinkUri::transform(). + * @param array $configuration + * The plugin configuration. * * @return string * The transformed link. */ - public function doTransform(array $value) { + public function doTransform(array $value, $configuration = []) { $entityTypeManager = $this->container->get('entity_type.manager'); $routeBuilder = $this->container->get('router.builder'); $row = new Row(); $executable = $this->prophesize(MigrateExecutableInterface::class)->reveal(); - $plugin = new LinkUri([], 'link_uri', [], $entityTypeManager, $routeBuilder); + $plugin = new LinkUri($configuration, 'link_uri', [], $entityTypeManager, $routeBuilder); $actual = $plugin->transform($value, $executable, $row, 'destinationproperty'); return $actual;