Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / menu_link_content / tests / src / Kernel / Plugin / migrate / process / LinkUriTest.php
index 74e88d18174c49f97c733deca9d5ef66c8ed7563..5ae840f766b710c6db5c6025df9eafc96fe5ce08 100644 (file)
@@ -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;