You are here

public function PhpTransliterationTest::testSafeInclude in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php \Drupal\Tests\Component\Transliteration\PhpTransliterationTest::testSafeInclude()

Tests inclusion is safe.

@covers ::readLanguageOverrides

File

core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php, line 177
Contains \Drupal\Tests\Component\Transliteration\PhpTransliterationTest.

Class

PhpTransliterationTest
Tests Transliteration component functionality.

Namespace

Drupal\Tests\Component\Transliteration

Code

public function testSafeInclude() {

  // The overrides in the transliteration data directory transliterates 0x82
  // into "safe" but the overrides one directory higher transliterates the
  // same character into "security hole". So by using "../index" as the
  // language code we can test the ../ is stripped from the langcode.
  vfsStream::setup('transliteration', NULL, [
    'index.php' => '<?php $overrides = ["../index" => [0x82 => "security hole"]];',
    'dir' => [
      'index.php' => '<?php $overrides = ["../index" => [0x82 => "safe"]];',
    ],
  ]);
  $transliteration = new PhpTransliteration(vfsStream::url('transliteration/dir'));
  $transliterated = $transliteration
    ->transliterate(chr(0xc2) . chr(0x82), '../index');
  $this
    ->assertSame($transliterated, 'safe');
}