You are here

public function EntityTestTextItemNormalizerTest::testGetWithFormat in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/system/tests/modules/entity_test/tests/src/Functional/Rest/EntityTestTextItemNormalizerTest.php \Drupal\Tests\entity_test\Functional\Rest\EntityTestTextItemNormalizerTest::testGetWithFormat()
  2. 10 core/modules/system/tests/modules/entity_test/tests/src/Functional/Rest/EntityTestTextItemNormalizerTest.php \Drupal\Tests\entity_test\Functional\Rest\EntityTestTextItemNormalizerTest::testGetWithFormat()

Tests GETting an entity with the test text field set to a specific format.

@dataProvider providerTestGetWithFormat

File

core/modules/system/tests/modules/entity_test/tests/src/Functional/Rest/EntityTestTextItemNormalizerTest.php, line 155

Class

EntityTestTextItemNormalizerTest
@group rest

Namespace

Drupal\Tests\entity_test\Functional\Rest

Code

public function testGetWithFormat($text_format_id, array $expected_cache_tags) {
  FilterFormat::create([
    'name' => 'Pablo Picasso',
    'format' => 'pablo',
    'langcode' => 'es',
    'filters' => [],
  ])
    ->save();

  // Set TextItemBase field's value for testing, using the given text format.
  $value = [
    'value' => $this
      ->randomString(),
  ];
  if ($text_format_id !== FALSE) {
    $value['format'] = $text_format_id;
  }
  $this->entity
    ->set('field_test_text', $value)
    ->save();
  $this
    ->initAuthentication();
  $url = $this
    ->getEntityResourceUrl();
  $url
    ->setOption('query', [
    '_format' => static::$format,
  ]);
  $request_options = $this
    ->getAuthenticationRequestOptions('GET');
  $this
    ->provisionEntityResource();
  $this
    ->setUpAuthorization('GET');
  $response = $this
    ->request('GET', $url, $request_options);
  $expected_cache_tags = Cache::mergeTags($expected_cache_tags, parent::getExpectedCacheTags());
  $this
    ->assertEqualsCanonicalizing($expected_cache_tags, explode(' ', $response
    ->getHeader('X-Drupal-Cache-Tags')[0]));
}