Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[yaffs-website] / web / core / modules / migrate / tests / src / Unit / process / UrlEncodeTest.php
1 <?php
2
3 namespace Drupal\Tests\migrate\Unit\process;
4
5 use Drupal\migrate\Plugin\migrate\process\UrlEncode;
6 use Drupal\migrate\MigrateExecutable;
7 use Drupal\migrate\Row;
8 use Drupal\Tests\migrate\Unit\MigrateTestCase;
9
10 /**
11  * @coversDefaultClass \Drupal\migrate\Plugin\migrate\process\UrlEncode
12  * @group file
13  */
14 class UrlEncodeTest extends MigrateTestCase {
15
16   /**
17    * @inheritdoc
18    */
19   protected $migrationConfiguration = [
20     'id' => 'test',
21   ];
22
23   /**
24    * The data provider for testing URL encoding scenarios.
25    *
26    * @return array
27    *   An array of URLs to test.
28    */
29   public function urlDataProvider() {
30     return [
31       'A URL with no characters requiring encoding' => ['http://example.com/normal_url.html', 'http://example.com/normal_url.html'],
32       'The definitive use case - encoding spaces in URLs' => ['http://example.com/url with spaces.html', 'http://example.com/url%20with%20spaces.html'],
33       'Definitive use case 2 - spaces in directories' => ['http://example.com/dir with spaces/foo.html', 'http://example.com/dir%20with%20spaces/foo.html'],
34       'Local filespecs without spaces should not be transformed' => ['/tmp/normal.txt', '/tmp/normal.txt'],
35       'Local filespecs with spaces should not be transformed' => ['/tmp/with spaces.txt', '/tmp/with spaces.txt'],
36       'Make sure URL characters (:, ?, &) are not encoded but others are.' => ['https://example.com/?a=b@c&d=e+f%', 'https://example.com/?a%3Db%40c&d%3De%2Bf%25'],
37     ];
38   }
39
40   /**
41    * Cover various encoding scenarios.
42    * @dataProvider urlDataProvider
43    */
44   public function testUrls($input, $output) {
45     $this->assertEquals($output, $this->doTransform($input));
46   }
47
48   /**
49    * Perform the urlencode process plugin over the given value.
50    *
51    * @param string $value
52    *   URL to be encoded.
53    *
54    * @return string
55    *   Encoded URL.
56    */
57   protected function doTransform($value) {
58     $executable = new MigrateExecutable($this->getMigration());
59     $row = new Row();
60
61     return (new UrlEncode([], 'urlencode', []))
62       ->transform($value, $executable, $row, 'foobaz');
63   }
64
65 }