function EntityTestTextItemNormalizerTest::testGetWithFormat

Same name in other branches
  1. 9 core/modules/system/tests/modules/entity_test/tests/src/Functional/Rest/EntityTestTextItemNormalizerTest.php \Drupal\Tests\entity_test\Functional\Rest\EntityTestTextItemNormalizerTest::testGetWithFormat()
  2. 8.9.x core/modules/system/tests/modules/entity_test/tests/src/Functional/Rest/EntityTestTextItemNormalizerTest.php \Drupal\Tests\entity_test\Functional\Rest\EntityTestTextItemNormalizerTest::testGetWithFormat()
  3. 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 160

Class

EntityTestTextItemNormalizerTest
@group rest @group #slow

Namespace

Drupal\Tests\entity_test\Functional\Rest

Code

public function testGetWithFormat($text_format_id, array $expected_cache_tags) : void {
    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]));
}

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