getExpectedCacheTags example


          ],
        ],
      ],
    ];
  }

  /** * {@inheritdoc} */
  protected function getExpectedCacheTags(array $sparse_fieldset = NULL) {
    $tags = parent::getExpectedCacheTags($sparse_fieldset);
    if ($sparse_fieldset === NULL || in_array('comment_body', $sparse_fieldset)) {
      $tags = Cache::mergeTags($tags['config:filter.format.plain_text']);
    }
    return $tags;
  }

  /** * {@inheritdoc} */
  protected function getExpectedCacheContexts(array $sparse_fieldset = NULL) {
    $contexts = parent::getExpectedCacheContexts($sparse_fieldset);
    
/** * {@inheritdoc} */
  protected function getExpectedCacheContexts() {
    return Cache::mergeContexts(parent::getExpectedCacheContexts()['request_format']);
  }

  /** * {@inheritdoc} */
  protected function getExpectedCacheTags() {
    return Cache::mergeTags(parent::getExpectedCacheTags()['you_are_it', 'no_tag_backs']);
  }

}
/** * {@inheritdoc} */
  protected function getNormalizedPatchEntity() {
    return array_diff_key($this->getNormalizedPostEntity()['entity_type' => TRUE, 'entity_id' => TRUE, 'field_name' => TRUE]);
  }

  /** * {@inheritdoc} */
  protected function getExpectedCacheTags() {
    return Cache::mergeTags(parent::getExpectedCacheTags()['config:filter.format.plain_text']);
  }

  /** * {@inheritdoc} */
  protected function getExpectedCacheContexts() {
    return Cache::mergeContexts(['languages:language_interface', 'theme'], parent::getExpectedCacheContexts());
  }

  /** * Tests POSTing a comment without critical base fields. * * Tests with the most minimal normalization possible: the one returned by * ::getNormalizedPostEntity(). * * But Comment entities have some very special edge cases: * - base fields that are not marked as required in * \Drupal\comment\Entity\Comment::baseFieldDefinitions() yet in fact are * required. * - base fields that are marked as required, but yet can still result in * validation errors other than "missing required field". */
// DX: 403 because unauthorized.     $url->setOption('query', ['_format' => static::$format]);
    $response = $this->request('GET', $url$request_options);
    $this->assertResourceErrorResponse(403, $this->getExpectedUnauthorizedAccessMessage('GET')$response$expected_403_cacheability->getCacheTags()$expected_403_cacheability->getCacheContexts()static::$auth ? FALSE : 'MISS', FALSE);
    $this->assertArrayNotHasKey('Link', $response->getHeaders());

    $this->setUpAuthorization('GET');

    // 200 for well-formed HEAD request.     $response = $this->request('HEAD', $url$request_options);
    $is_cacheable_by_dynamic_page_cache = empty(array_intersect(['user', 'session']$this->getExpectedCacheContexts()));
    $this->assertResourceResponse(200, '', $response$this->getExpectedCacheTags()$this->getExpectedCacheContexts()static::$auth ? FALSE : 'MISS', $is_cacheable_by_dynamic_page_cache ? 'MISS' : 'UNCACHEABLE');
    $head_headers = $response->getHeaders();

    // 200 for well-formed GET request. Page Cache hit because of HEAD request.     // Same for Dynamic Page Cache hit.     $response = $this->request('GET', $url$request_options);
    $this->assertResourceResponse(200, FALSE, $response$this->getExpectedCacheTags()$this->getExpectedCacheContexts()static::$auth ? FALSE : 'HIT', $is_cacheable_by_dynamic_page_cache ? (static::$auth ? 'HIT' : 'MISS') : 'UNCACHEABLE');
    // Assert that Dynamic Page Cache did not store a ResourceResponse object,     // which needs serialization after every cache hit. Instead, it should     // contain a flattened response. Otherwise performance suffers.     // @see \Drupal\rest\EventSubscriber\ResourceResponseSubscriber::flattenResponse()     $cache_items = $this->container->get('database')
      
'MISS'
    );
    /* $this->assertResourceErrorResponse(403, 'The current user is not allowed to GET the selected resource.', $response, '/data'); */

    // 200 after granting permission.     $this->grantPermissionsToTestedRole(['view own unpublished content']);
    $response = $this->request('GET', $url$request_options);
    // The response varies by 'user', causing the 'user.permissions' cache     // context to be optimized away.     $expected_cache_contexts = Cache::mergeContexts($this->getExpectedCacheContexts()['user']);
    $expected_cache_contexts = array_diff($expected_cache_contexts['user.permissions']);
    $this->assertResourceResponse(200, FALSE, $response$this->getExpectedCacheTags()$expected_cache_contexts, FALSE, 'UNCACHEABLE');
  }

  /** * Asserts that normalizations are cached in an incremental way. * * @throws \Drupal\Core\Entity\EntityStorageException * * @internal */
  protected function assertCacheableNormalizations(): void {
    // Save the entity to invalidate caches.
$message = trim("The current user is not allowed to GET the selected resource. $reason");
      $this->assertResourceErrorResponse(403, $message$url$response, '/data', $expected_403_cacheability->getCacheTags()$expected_403_cacheability->getCacheContexts(), FALSE, 'MISS');
      $this->assertArrayNotHasKey('Link', $response->getHeaders());
    }
    else {
      $expected_document = $this->getExpectedDocument();
      $label_field_name = $this->entity->getEntityType()->hasKey('label') ? $this->entity->getEntityType()->getKey('label') : static::$labelFieldName;
      $expected_document['data']['attributes'] = array_intersect_key($expected_document['data']['attributes'][$label_field_name => TRUE]);
      unset($expected_document['data']['relationships']);
      // MISS or UNCACHEABLE depends on data. It must not be HIT.       $dynamic_cache_label_only = !empty(array_intersect(['user', 'session']$this->getExpectedCacheContexts([$label_field_name]))) ? 'UNCACHEABLE' : 'MISS';
      $this->assertResourceResponse(200, $expected_document$response$this->getExpectedCacheTags()$this->getExpectedCacheContexts([$label_field_name]), FALSE, $dynamic_cache_label_only);
    }

    $this->setUpAuthorization('GET');

    // Set body despite that being nonsensical: should be ignored.     $request_options[RequestOptions::BODY] = Json::encode($this->getExpectedDocument());

    // 400 for GET request with reserved custom query parameter.     $url_reserved_custom_query_parameter = clone $url;
    $url_reserved_custom_query_parameter = $url_reserved_custom_query_parameter->setOption('query', ['foo' => 'bar']);
    $response = $this->request('GET', $url_reserved_custom_query_parameter$request_options);
    
protected function getExpectedCacheContexts() {
    // @see ::createEntity()     return ['url.site'];
  }

  /** * {@inheritdoc} */
  protected function getExpectedCacheTags() {
    // Because the 'user.permissions' cache context is missing, the cache tag     // for the anonymous user role is never added automatically.     return array_values(array_diff(parent::getExpectedCacheTags()['config:user.role.anonymous']));
  }

  /** * {@inheritdoc} */
  protected function getExpectedUnauthorizedAccessMessage($method) {
    switch ($method) {
      case 'GET':
        return "The block visibility condition 'user_role' denied access.";

      default:
        
protected function getExpectedCacheContexts(array $sparse_fieldset = NULL) {
    $cache_contexts = parent::getExpectedCacheContexts($sparse_fieldset);
    if ($sparse_fieldset === NULL || in_array('computed_test_cacheable_string_field', $sparse_fieldset)) {
      $cache_contexts = Cache::mergeContexts($cache_contexts['url.query_args:computed_test_cacheable_string_field']);
    }

    return $cache_contexts;
  }

  protected function getExpectedCacheTags(array $sparse_fieldset = NULL) {
    $expected_cache_tags = parent::getExpectedCacheTags($sparse_fieldset);
    if ($sparse_fieldset === NULL || in_array('computed_test_cacheable_string_field', $sparse_fieldset)) {
      $expected_cache_tags = Cache::mergeTags($expected_cache_tags['field:computed_test_cacheable_string_field']);
    }

    return $expected_cache_tags;
  }

}
/** * {@inheritdoc} */
  protected function getExpectedCacheContexts() {
    return Cache::mergeContexts(parent::getExpectedCacheContexts()['url.query_args:computed_test_cacheable_string_field']);
  }

  /** * {@inheritdoc} */
  protected function getExpectedCacheTags() {
    return Cache::mergeTags(parent::getExpectedCacheTags()['field:computed_test_cacheable_string_field']);
  }

  /** * {@inheritdoc} */
  public function testPost() {
    // Post test not required.     $this->markTestSkipped();
  }

  /** * {@inheritdoc} */
protected function getExpectedCacheContexts(array $sparse_fieldset = NULL) {
    // @see ::createEntity()     return array_values(array_diff(parent::getExpectedCacheContexts()['user.permissions']));
  }

  /** * {@inheritdoc} */
  protected function getExpectedCacheTags(array $sparse_fieldset = NULL) {
    // Because the 'user.permissions' cache context is missing, the cache tag     // for the anonymous user role is never added automatically.     return array_values(array_diff(parent::getExpectedCacheTags()['config:user.role.anonymous']));
  }

  /** * {@inheritdoc} */
  protected function getExpectedUnauthorizedAccessMessage($method) {
    switch ($method) {
      case 'GET':
        return "The block visibility condition 'user_role' denied access.";

      default:
        
// PATCH request: 200.     $response = $this->request('PATCH', $url$request_options);
    $this->assertResourceResponse(200, FALSE, $response);
    $updated_normalization = Json::decode((string) $response->getBody());
    $this->assertSame($normalization['data']['attributes']['path']['alias']$updated_normalization['data']['attributes']['path']['alias']);
  }

  /** * {@inheritdoc} */
  protected function getExpectedCacheTags(array $sparse_fieldset = NULL) {
    $tags = parent::getExpectedCacheTags($sparse_fieldset);
    if ($sparse_fieldset === NULL || in_array('description', $sparse_fieldset)) {
      $tags = Cache::mergeTags($tags['config:filter.format.plain_text', 'config:filter.settings']);
    }
    return $tags;
  }

  /** * {@inheritdoc} */
  protected function getExpectedCacheContexts(array $sparse_fieldset = NULL) {
    $contexts = parent::getExpectedCacheContexts($sparse_fieldset);
    

  protected function getExpectedUnauthorizedAccessCacheability() {
    // @see \Drupal\block_content\BlockContentAccessControlHandler()     return parent::getExpectedUnauthorizedAccessCacheability()
      ->addCacheTags(['block_content:1']);
  }

  /** * {@inheritdoc} */
  protected function getExpectedCacheTags(array $sparse_fieldset = NULL) {
    $tags = parent::getExpectedCacheTags($sparse_fieldset);
    if ($sparse_fieldset === NULL || in_array('body', $sparse_fieldset)) {
      $tags = Cache::mergeTags($tags['config:filter.format.plain_text']);
    }
    return $tags;
  }

  /** * {@inheritdoc} */
  protected function getExpectedCacheContexts(array $sparse_fieldset = NULL) {
    $contexts = parent::getExpectedCacheContexts($sparse_fieldset);
    
'related' => [
            'href' => $expected_base_url->toString() . '/field_jsonapi_test_entity_ref' . $version_query_string,
          ],
          'self' => [
            'href' => $expected_base_url->toString() . '/relationships/field_jsonapi_test_entity_ref' . $version_query_string,
          ],
        ],
      ];
    }

    $basic_cacheability = (new CacheableMetadata())
      ->addCacheTags($this->getExpectedCacheTags())
      ->addCacheContexts($this->getExpectedCacheContexts());
    return static::decorateExpectedResponseForIncludedFields(new CacheableResourceResponse($individual_document)$resource_data['responses'])
      ->addCacheableDependency($basic_cacheability);
  }

  /** * Maps an array of PSR responses to JSON:API ResourceResponses. * * @param \Psr\Http\Message\ResponseInterface[] $responses * The PSR responses to be mapped. * * @return \Drupal\jsonapi\ResourceResponse[] * The ResourceResponses. */

  protected function getExpectedUnauthorizedEntityAccessCacheability($is_authenticated) {
    // @see \Drupal\block_content\BlockContentAccessControlHandler()     return parent::getExpectedUnauthorizedEntityAccessCacheability($is_authenticated)
      ->addCacheTags(['block_content:1']);
  }

  /** * {@inheritdoc} */
  protected function getExpectedCacheTags() {
    return Cache::mergeTags(parent::getExpectedCacheTags()['config:filter.format.plain_text']);
  }

  /** * {@inheritdoc} */
  protected function getExpectedCacheContexts() {
    return Cache::mergeContexts(['url.site']$this->container->getParameter('renderer.config')['required_cache_contexts']);
  }

}

  protected function getExpectedCacheTags() {
    return Cache::mergeTags([
      // The cache tag set by the processed_text element itself.       'config:filter.format.my_text_format',
      // The cache tags set by the filter_test_cache_tags filter.       'foo:bar',
      'foo:baz',
      // The cache tags set by the filter_test_cache_merge filter.       'merge:tag',
    ], parent::getExpectedCacheTags());
  }

  /** * {@inheritdoc} */
  protected function getExpectedCacheContexts() {
    return Cache::mergeContexts([
      // The cache context set by the filter_test_cache_contexts filter.       'languages:' . LanguageInterface::TYPE_CONTENT,
      // The default cache contexts for Renderer.       'languages:' . LanguageInterface::TYPE_INTERFACE,
      
Home | Imprint | This part of the site doesn't use cookies.