Commit 15d68a7d authored by alexpott's avatar alexpott

Issue #2844181 by maxocub, Alex Bukach, alexpott: PluralTranslatableMarkup serialization error

(cherry picked from commit 87c1e2ee)
parent 704c66e8
......@@ -157,4 +157,11 @@ protected function getPluralIndex() {
return -1;
}
/**
* {@inheritdoc}
*/
public function __sleep() {
return array_merge(parent::__sleep(), array('count'));
}
}
<?php
namespace Drupal\Tests\Core\StringTranslation;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
use Drupal\Tests\UnitTestCase;
/**
* Tests the TranslatableMarkup class.
*
* @coversDefaultClass \Drupal\Core\StringTranslation\PluralTranslatableMarkup
* @group StringTranslation
*/
class PluralTranslatableMarkupTest extends UnitTestCase {
/**
* Tests serialization of PluralTranslatableMarkup().
*
* @dataProvider providerPluralTranslatableMarkupSerialization
*/
public function testPluralTranslatableMarkupSerialization($count, $expected_text) {
// Add a mock string translation service to the container.
$container = new ContainerBuilder();
$container->set('string_translation', $this->getStringTranslationStub());
\Drupal::setContainer($container);
// Create an object to serialize and unserialize.
$markup = new PluralTranslatableMarkup($count, 'singular @count', 'plural @count');
$serialized_markup = unserialize(serialize($markup));
$this->assertEquals($expected_text, $serialized_markup->render());
}
/**
* Data provider for ::testPluralTranslatableMarkupSerialization().
*/
public function providerPluralTranslatableMarkupSerialization() {
return [
[1, 'singular 1'],
[2, 'plural 2'],
];
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment