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