Unverified Commit f4e81e05 authored by alexpott's avatar alexpott

Issue #2893029 by phenaproxima, Sam152, tim.plunkett, dawehner, a.dmitriiev,...

Issue #2893029 by phenaproxima, Sam152, tim.plunkett, dawehner, a.dmitriiev, Berdir: StringTranslationTrait consumers cannot be reliably serialized without DependencySerializationTrait
parent e4c48af8
......@@ -3,6 +3,7 @@
namespace Drupal\Core\Entity;
use Drupal\Component\Plugin\Definition\PluginDefinition;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Entity\Exception\EntityTypeIdLengthException;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslatableMarkup;
......@@ -14,6 +15,7 @@
*/
class EntityType extends PluginDefinition implements EntityTypeInterface {
use DependencySerializationTrait;
use StringTranslationTrait;
/**
......
......@@ -5,6 +5,7 @@
use Drupal\Core\Entity\EntityType;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Tests\UnitTestCase;
/**
......@@ -476,4 +477,22 @@ protected function assertNoPublicProperties(EntityTypeInterface $entity_type) {
$this->assertEmpty($reflection->getProperties(\ReflectionProperty::IS_PUBLIC));
}
/**
* Test the EntityType object it serializable.
*/
public function testIsSerializable() {
$entity_type = $this->setUpEntityType([]);
$translation = $this->prophesize(TranslationInterface::class);
$translation->willImplement(\Serializable::class);
$translation->serialize()->willThrow(\Exception::class);
$translation_service = $translation->reveal();
$translation_service->_serviceId = 'string_translation';
$entity_type->setStringTranslation($translation_service);
$entity_type = unserialize(serialize($entity_type));
$this->assertEquals('example_entity_type', $entity_type->id());
}
}
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