Issue #3128389 by clayfreeman, jungle, cliddell, john.oltman, acbramley, larowlan: [backport] LocaleTranslation is not serializable

merge-requests/597/head
Alex Pott 2021-02-03 16:02:39 +00:00 committed by catch
parent db7ab7ef7a
commit 4821bf7980
2 changed files with 37 additions and 0 deletions

View File

@ -4,6 +4,7 @@ namespace Drupal\locale;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\DestructableInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Language\LanguageManagerInterface;
@ -19,6 +20,8 @@ use Symfony\Component\HttpFoundation\RequestStack;
*/
class LocaleTranslation implements TranslatorInterface, DestructableInterface {
use DependencySerializationTrait;
/**
* Storage for strings.
*

View File

@ -0,0 +1,34 @@
<?php
namespace Drupal\Tests\locale\Kernel;
use Drupal\locale\LocaleTranslation;
use Drupal\KernelTests\KernelTestBase;
/**
* @coversDefaultClass \Drupal\locale\LocaleTranslation
* @group locale
*/
class LocaleTranslationTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'locale',
];
/**
* Tests that \Drupal\locale\LocaleTranslation is serializable.
*/
public function testSerializable() {
$translation = $this->container->get('string_translator.locale.lookup');
$this->assertInstanceOf(LocaleTranslation::class, $translation);
// Prove that serialization and deserialization works without errors.
$this->assertNotNull($translation);
$unserialized = unserialize(serialize($translation));
$this->assertInstanceOf(LocaleTranslation::class, $unserialized);
}
}