1.20.x locale.test public LocaleStringIsSafeTest::testLocaleStringIsSafe()

Tests for locale_string_is_safe().

File

modules/locale/tests/locale.test, line 2923
Tests for locale.module.

Class

LocaleStringIsSafeTest
Tests locale translation safe string handling.

Code

public function testLocaleStringIsSafe() {
  // Check a translatable string without HTML.
  $string = 'Hello world!';
  $result = locale_string_is_safe($string);
  $this->assertTrue($result);

  // Check a translatable string which includes trustable HTML.
  $string = 'Hello <strong>world</strong>!';
  $result = locale_string_is_safe($string);
  $this->assertTrue($result);

  // Check an untranslatable string which includes untrustable HTML (according
  // to the locale_string_is_safe() function definition).
  $string = 'Hello <img src="world.png" alt="world" />!';
  $result = locale_string_is_safe($string);
  $this->assertFalse($result);

  // Check a translatable string which includes a token in an href attribute.
  $string = 'Hi <a href="[current-user:url]">user</a>';
  $result = locale_string_is_safe($string);
  $this->assertTrue($result);
}