Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / field / tests / src / Kernel / EntityReference / EntityReferenceItemTest.php
index 391d8db065e3324250d7c83e3cb1f9abe9f22e7e..c0e58e04e9e5917a20001014862f9b2d032e7990 100644 (file)
@@ -16,6 +16,7 @@ use Drupal\field\Entity\FieldConfig;
 use Drupal\field\Entity\FieldStorageConfig;
 use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
 use Drupal\node\NodeInterface;
+use Drupal\taxonomy\TermInterface;
 use Drupal\Tests\field\Kernel\FieldKernelTestBase;
 use Drupal\file\Entity\File;
 use Drupal\node\Entity\Node;
@@ -193,6 +194,24 @@ class EntityReferenceItemTest extends FieldKernelTestBase {
     $entity = EntityTest::create(['user_id' => ['target_id' => (int) $user->id(), 'entity' => $user]]);
   }
 
+  /**
+   * Tests the ::generateSampleValue() method.
+   */
+  public function testGenerateSampleValue() {
+    $entity = EntityTest::create();
+
+    // Test while a term exists.
+    $entity->field_test_taxonomy_term->generateSampleItems();
+    $this->assertInstanceOf(TermInterface::class, $entity->field_test_taxonomy_term->entity);
+    $this->entityValidateAndSave($entity);
+
+    // Delete the term and test again.
+    $this->term->delete();
+    $entity->field_test_taxonomy_term->generateSampleItems();
+    $this->assertInstanceOf(TermInterface::class, $entity->field_test_taxonomy_term->entity);
+    $this->entityValidateAndSave($entity);
+  }
+
   /**
    * Tests referencing content entities with string IDs.
    */