4b4eda2249871fb6fc0310d7ed721e8f0765af5b
[yaffs-website] / web / core / modules / link / tests / src / Unit / Plugin / migrate / process / d6 / FieldLinkTest.php
1 <?php
2
3 namespace Drupal\Tests\link\Unit\Plugin\migrate\process\d6;
4
5 use Drupal\link\Plugin\migrate\process\d6\FieldLink;
6 use Drupal\Tests\UnitTestCase;
7
8 /**
9  * @group Link
10  */
11 class FieldLinkTest extends UnitTestCase {
12
13   /**
14    * Test the url transformations in the FieldLink process plugin.
15    *
16    * @dataProvider canonicalizeUriDataProvider
17    */
18   public function testCanonicalizeUri($url, $expected) {
19     $link_plugin = new FieldLink([], '', [], $this->getMock('\Drupal\migrate\Plugin\MigrationInterface'));
20     $transformed = $link_plugin->transform([
21       'url' => $url,
22       'title' => '',
23       'attributes' => serialize([]),
24     ], $this->getMock('\Drupal\migrate\MigrateExecutableInterface'), $this->getMockBuilder('\Drupal\migrate\Row')->disableOriginalConstructor()->getMock(), NULL);
25     $this->assertEquals($expected, $transformed['uri']);
26   }
27
28   /**
29    * Data provider for testCanonicalizeUri.
30    */
31   public function canonicalizeUriDataProvider() {
32     return [
33       'Simple front-page' => [
34         '<front>',
35         'internal:/',
36       ],
37       'Front page with query' => [
38         '<front>?query=1',
39         'internal:/?query=1',
40       ],
41       'No leading forward slash' => [
42         'node/10',
43         'internal:/node/10',
44       ],
45       'Leading forward slash' => [
46         '/node/10',
47         'internal:/node/10',
48       ],
49       'Existing scheme' => [
50         'scheme:test',
51         'scheme:test',
52       ],
53     ];
54   }
55
56 }