X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Ftests%2FDrupal%2FKernelTests%2FCore%2FEntity%2FEntityTranslationTest.php;fp=web%2Fcore%2Ftests%2FDrupal%2FKernelTests%2FCore%2FEntity%2FEntityTranslationTest.php;h=4ef59db08ee2df5b5c506feeca4943eee8df6c41;hp=bcd702ae026389700e0eef62ad759251ba391b29;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/tests/Drupal/KernelTests/Core/Entity/EntityTranslationTest.php b/web/core/tests/Drupal/KernelTests/Core/Entity/EntityTranslationTest.php index bcd702ae0..4ef59db08 100644 --- a/web/core/tests/Drupal/KernelTests/Core/Entity/EntityTranslationTest.php +++ b/web/core/tests/Drupal/KernelTests/Core/Entity/EntityTranslationTest.php @@ -2,9 +2,10 @@ namespace Drupal\KernelTests\Core\Entity; -use Drupal\Component\Utility\SafeMarkup; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\TypedData\TranslationStatusInterface; +use Drupal\entity_test\Entity\EntityTestMul; use Drupal\entity_test\Entity\EntityTestMulRev; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; @@ -806,7 +807,7 @@ class EntityTranslationTest extends EntityLanguageTestBase { foreach ($langcodes as $langcode) { $adapter = $entity->getTranslation($langcode)->getTypedData(); $name = $adapter->get('name')->value; - $this->assertEqual($name, $values[$langcode]['name'], SafeMarkup::format('Name correctly retrieved from "@langcode" adapter', ['@langcode' => $langcode])); + $this->assertEqual($name, $values[$langcode]['name'], new FormattableMarkup('Name correctly retrieved from "@langcode" adapter', ['@langcode' => $langcode])); } } @@ -1013,4 +1014,31 @@ class EntityTranslationTest extends EntityLanguageTestBase { } } + /** + * Tests the translation object cache. + */ + public function testTranslationObjectCache() { + $default_langcode = $this->langcodes[1]; + $translation_langcode = $this->langcodes[2]; + + $entity = EntityTestMul::create([ + 'name' => 'test', + 'langcode' => $default_langcode, + ]); + $entity->save(); + $entity->addTranslation($translation_langcode)->save(); + + // Test that the default translation object is put into the translation + // object cache when a new translation object is initialized. + $entity = \Drupal::entityTypeManager()->getStorage($entity->getEntityTypeId())->loadUnchanged($entity->id()); + $default_translation_spl_object_hash = spl_object_hash($entity); + $this->assertEquals($default_translation_spl_object_hash, spl_object_hash($entity->getTranslation($translation_langcode)->getTranslation($default_langcode))); + + // Test that non-default translations are always served from the translation + // object cache. + $entity = \Drupal::entityTypeManager()->getStorage($entity->getEntityTypeId())->loadUnchanged($entity->id()); + $this->assertEquals(spl_object_hash($entity->getTranslation($translation_langcode)), spl_object_hash($entity->getTranslation($translation_langcode))); + $this->assertEquals(spl_object_hash($entity->getTranslation($translation_langcode)), spl_object_hash($entity->getTranslation($translation_langcode)->getTranslation($default_langcode)->getTranslation($translation_langcode))); + } + }