function LocaleTranslationTest::testSerializable

Same name and namespace in other branches
  1. 9 core/modules/locale/tests/src/Kernel/LocaleTranslationTest.php \Drupal\Tests\locale\Kernel\LocaleTranslationTest::testSerializable()
  2. 8.9.x core/modules/locale/tests/src/Kernel/LocaleTranslationTest.php \Drupal\Tests\locale\Kernel\LocaleTranslationTest::testSerializable()
  3. 10 core/modules/locale/tests/src/Kernel/LocaleTranslationTest.php \Drupal\Tests\locale\Kernel\LocaleTranslationTest::testSerializable()

Tests that \Drupal\locale\LocaleTranslation is serializable.

File

core/modules/locale/tests/src/Kernel/LocaleTranslationTest.php, line 39

Class

LocaleTranslationTest
@coversDefaultClass \Drupal\locale\LocaleTranslation[[api-linebreak]] @group locale

Namespace

Drupal\Tests\locale\Kernel

Code

public function testSerializable() : void {
  /** @var \Drupal\locale\LocaleTranslation $translation */
  $translation = $this->container
    ->get('string_translator.locale.lookup');
  $this->assertInstanceOf(LocaleTranslation::class, $translation);
  // Ensure that the \Drupal\locale\LocaleTranslation::$translations property
  // has some cached translations in it. Without this, serialization will not
  // actually be tested fully.
  $translation->getStringTranslation('es', 'test', '');
  // Prove that serialization and deserialization works without errors.
  $this->assertNotNull($translation);
  $unserialized = unserialize(serialize($translation));
  $this->assertInstanceOf(LocaleTranslation::class, $unserialized);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.