commit d809236ccc7decbb0d8bec3e5abcaf6522604d45 Author: Sam Date: Fri Jun 17 09:48:22 2016 +0800 test diff --git a/core/modules/link/src/Plugin/migrate/process/d6/CckLink.php b/core/modules/link/src/Plugin/migrate/process/d6/CckLink.php index 1df0550..ad6fb26 100644 --- a/core/modules/link/src/Plugin/migrate/process/d6/CckLink.php +++ b/core/modules/link/src/Plugin/migrate/process/d6/CckLink.php @@ -47,7 +47,7 @@ public static function create(ContainerInterface $container, array $configuratio * * @see \Drupal\link\Plugin\Field\FieldWidget\LinkWidget::getUserEnteredStringAsUri() */ - protected static function canonicalizeUri($uri) { + protected function canonicalizeUri($uri) { // If we already have a scheme, we're fine. if (empty($uri) || !is_null(parse_url($uri, PHP_URL_SCHEME))) { return $uri; @@ -80,7 +80,7 @@ public function transform($value, MigrateExecutableInterface $migrate_executable } // Massage the values into the correct form for the link. - $route['uri'] = self::canonicalizeUri($value['url']); + $route['uri'] = $this->canonicalizeUri($value['url']); $route['options']['attributes'] = $attributes; $route['title'] = $value['title']; return $route; diff --git a/core/modules/link/tests/src/Unit/Plugin/migrate/process/d6/CckLinkTest.php b/core/modules/link/tests/src/Unit/Plugin/migrate/process/d6/CckLinkTest.php new file mode 100644 index 0000000..b8eeb40 --- /dev/null +++ b/core/modules/link/tests/src/Unit/Plugin/migrate/process/d6/CckLinkTest.php @@ -0,0 +1,52 @@ +getMock('\Drupal\migrate\Plugin\MigrationInterface')); + $transformed = $link_plugin->transform([ + 'url' => $url, + 'title' => '', + 'attributes' => serialize([]), + ], $this->getMock('\Drupal\migrate\MigrateExecutableInterface'), $this->getMockBuilder('\Drupal\migrate\Row')->disableOriginalConstructor()->getMock(), NULL); + $this->assertEquals($expected, $transformed['uri']); + } + + /** + * Data provider for testCanonicalizeUri. + */ + public function canonicalizeUriDataProvider() { + return [ + 'Simple front-page' => [ + '', + 'internal:/', + ], + 'Front page with query' => [ + '?query=1', + 'internal:/?query=1', + ], + 'No leading forward slash' => [ + 'node/10', + 'internal:/node/10', + ], + 'Existing scheme' => [ + 'scheme:test', + 'scheme:test', + ], + ]; + } + +}