You are here

public function UrlEncodeTest::testUrlEncodeString in Tamper 8

Tests url encoding using the 'legacy' method.

The legacy method uses the PHP function urlencode().

The following cases are tested:

  • encoding symbols;
  • encoding a string with spaces;
  • encoding special characters.

File

tests/src/Unit/Plugin/Tamper/UrlEncodeTest.php, line 33

Class

UrlEncodeTest
Tests the url encode plugin.

Namespace

Drupal\Tests\tamper\Unit\Plugin\Tamper

Code

public function testUrlEncodeString() {
  $config = [
    UrlEncode::SETTING_METHOD => 'urlencode',
  ];
  $plugin = new UrlEncode($config, 'url_encode', [], $this
    ->getMockSourceDefinition());
  $this
    ->assertEquals('%24+%26+%3C+%3E+%3F+%3B+%23+%3A+%3D+%2C+%22+%27+%7E+%2B+%25', $plugin
    ->tamper('$ & < > ? ; # : = , " \' ~ + %'));
  $this
    ->assertEquals('String+with+spaces', $plugin
    ->tamper('String with spaces'));
  $this
    ->assertEquals('special+chars%3A+%26%25%2A', $plugin
    ->tamper('special chars: &%*'));
}