3 namespace Drupal\Tests\migrate\Unit\process;
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;
11 * @coversDefaultClass \Drupal\migrate\Plugin\migrate\process\UrlEncode
14 class UrlEncodeTest extends MigrateTestCase {
19 protected $migrationConfiguration = [
24 * The data provider for testing URL encoding scenarios.
27 * An array of URLs to test.
29 public function urlDataProvider() {
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'],
41 * Cover various encoding scenarios.
42 * @dataProvider urlDataProvider
44 public function testUrls($input, $output) {
45 $this->assertEquals($output, $this->doTransform($input));
49 * Perform the urlencode process plugin over the given value.
51 * @param string $value
57 protected function doTransform($value) {
58 $executable = new MigrateExecutable($this->getMigration());
61 return (new UrlEncode([], 'urlencode', []))
62 ->transform($value, $executable, $row, 'foobaz');