function EntityReferenceRevisionsCompositeTest::testCompositeRelationshipWithTranslationNonTranslatableField in Entity Reference Revisions 8
Tests composite relationship with translations and an untranslatable field.
File
- tests/
src/ Kernel/ EntityReferenceRevisionsCompositeTest.php, line 228
Class
- EntityReferenceRevisionsCompositeTest
- Tests the entity_reference_revisions composite relationship.
Namespace
Drupal\Tests\entity_reference_revisions\KernelCode
function testCompositeRelationshipWithTranslationNonTranslatableField() {
ConfigurableLanguage::createFromLangcode('de')
->save();
// Create the test composite entity with a translation.
$composite = EntityTestCompositeRelationship::create(array(
'uuid' => $this
->randomMachineName(),
'name' => $this
->randomMachineName(),
));
$composite
->addTranslation('de', $composite
->toArray());
$composite
->save();
// Create a node with a reference to the test composite entity.
$node = Node::create(array(
'title' => $this
->randomMachineName(),
'type' => 'article',
'composite_reference' => $composite,
));
$node
->addTranslation('de', $node
->toArray());
$node
->save();
// Verify the value of parent type and id after create a node.
$composite = EntityTestCompositeRelationship::load($composite
->id());
$this
->assertEquals($node
->getEntityTypeId(), $composite->parent_type->value);
$this
->assertEquals($node
->id(), $composite->parent_id->value);
$this
->assertEquals('composite_reference', $composite->parent_field_name->value);
$this
->assertTrue($composite
->hasTranslation('de'));
// Test that the composite entity is not deleted when the german translation
// of the parent is deleted.
$node
->removeTranslation('de');
$node
->save();
$composite = EntityTestCompositeRelationship::load($composite
->id());
$this
->assertNotNull($composite);
$this
->assertFalse($composite
->hasTranslation('de'));
// Change the language of the entity, ensure that doesn't try to delete
// the default translation.
$node
->set('langcode', 'de');
$node
->save();
$composite = EntityTestCompositeRelationship::load($composite
->id());
$this
->assertNotNull($composite);
// Test that the composite entity is deleted when its parent is deleted.
$node
->delete();
$this->cron
->run();
$composite = EntityTestCompositeRelationship::load($composite
->id());
$this
->assertNull($composite);
}