function TextWithSummaryItemTest::testCrudAndUpdate

Same name and namespace in other branches
  1. 9 core/modules/text/tests/src/Kernel/TextWithSummaryItemTest.php \Drupal\Tests\text\Kernel\TextWithSummaryItemTest::testCrudAndUpdate()
  2. 10 core/modules/text/tests/src/Kernel/TextWithSummaryItemTest.php \Drupal\Tests\text\Kernel\TextWithSummaryItemTest::testCrudAndUpdate()
  3. 11.x core/modules/text/tests/src/Kernel/TextWithSummaryItemTest.php \Drupal\Tests\text\Kernel\TextWithSummaryItemTest::testCrudAndUpdate()

Tests processed properties.

File

core/modules/text/tests/src/Kernel/TextWithSummaryItemTest.php, line 56

Class

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

Namespace

Drupal\Tests\text\Kernel

Code

public function testCrudAndUpdate() {
    $entity_type = 'entity_test';
    $this->createField($entity_type);
    // Create an entity with a summary and no text format.
    $storage = $this->container
        ->get('entity_type.manager')
        ->getStorage($entity_type);
    $entity = $storage->create();
    $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 = $storage->load($entity->id());
    $this->assertInstanceOf(FieldItemListInterface::class, $entity->summary_field);
    $this->assertInstanceOf(FieldItemInterface::class, $entity->summary_field[0]);
    $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 = $this->container
        ->get('entity_type.manager')
        ->getStorage($entity_type)
        ->create();
    $entity->summary_field
        ->generateSampleItems();
    $this->entityValidateAndSave($entity);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.