public function EntityReferenceItemTest::testEntitySaveOrder in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/field/src/Tests/EntityReference/EntityReferenceItemTest.php \Drupal\field\Tests\EntityReference\EntityReferenceItemTest::testEntitySaveOrder()
Test saving order sequence doesn't matter.
File
- core/
modules/ field/ src/ Tests/ EntityReference/ EntityReferenceItemTest.php, line 279 - Contains \Drupal\field\Tests\EntityReference\EntityReferenceItemTest.
Class
- EntityReferenceItemTest
- Tests the new entity API for the entity reference field type.
Namespace
Drupal\field\Tests\EntityReferenceCode
public function testEntitySaveOrder() {
// The term entity is unsaved here.
$term = entity_create('taxonomy_term', array(
'name' => $this
->randomMachineName(),
'vid' => $this->term
->bundle(),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
$entity = entity_create('entity_test');
// Now assign the unsaved term to the field.
$entity->field_test_taxonomy_term->entity = $term;
$entity->name->value = $this
->randomMachineName();
// Now get the field value.
$value = $entity
->get('field_test_taxonomy_term');
$this
->assertTrue(empty($value['target_id']));
$this
->assertNull($entity->field_test_taxonomy_term->target_id);
// And then set it.
$entity->field_test_taxonomy_term = $value;
// Now save the term.
$term
->save();
// And then the entity.
$entity
->save();
$this
->assertEqual($entity->field_test_taxonomy_term->entity
->id(), $term
->id());
}