You are here

public function TextWithSummaryItemTest::testCrudAndUpdate in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/text/src/Tests/TextWithSummaryItemTest.php \Drupal\text\Tests\TextWithSummaryItemTest::testCrudAndUpdate()

Tests processed properties.

File

core/modules/text/src/Tests/TextWithSummaryItemTest.php, line 59
Contains \Drupal\text\Tests\TextWithSummaryItemTest.

Class

TextWithSummaryItemTest
Tests using entity fields of the text summary field type.

Namespace

Drupal\text\Tests

Code

public function testCrudAndUpdate() {
  $entity_type = 'entity_test';
  $this
    ->createField($entity_type);

  // Create an entity with a summary and no text format.
  $entity = entity_create($entity_type);
  $entity->summary_field->value = $value = $this
    ->randomMachineName();
  $entity->summary_field->summary = $summary = $this
    ->randomMachineName();
  $entity->summary_field->format = NULL;
  $entity->name->value = $this
    ->randomMachineName();
  $entity
    ->save();
  $entity = entity_load($entity_type, $entity
    ->id());
  $this
    ->assertTrue($entity->summary_field instanceof FieldItemListInterface, 'Field implements interface.');
  $this
    ->assertTrue($entity->summary_field[0] instanceof FieldItemInterface, 'Field item implements interface.');
  $this
    ->assertEqual($entity->summary_field->value, $value);
  $this
    ->assertEqual($entity->summary_field->summary, $summary);
  $this
    ->assertNull($entity->summary_field->format);

  // Even if no format is given, if text processing is enabled, the default
  // format is used.
  $this
    ->assertEqual($entity->summary_field->processed, "<p>{$value}</p>\n");
  $this
    ->assertEqual($entity->summary_field->summary_processed, "<p>{$summary}</p>\n");

  // Change the format, this should update the processed properties.
  $entity->summary_field->format = 'no_filters';
  $this
    ->assertEqual($entity->summary_field->processed, $value);
  $this
    ->assertEqual($entity->summary_field->summary_processed, $summary);

  // Test the generateSampleValue() method.
  $entity = entity_create($entity_type);
  $entity->summary_field
    ->generateSampleItems();
  $this
    ->entityValidateAndSave($entity);
}