getIncludePermissions example

    $dynamic_cache = $expected_cacheability->getCacheMaxAge() === 0 || !empty(array_intersect(['user', 'session']$expected_cacheability->getCacheContexts())) ? 'UNCACHEABLE' : 'MISS';
    $this->assertResourceResponse(200, $expected_document$response$expected_cacheability->getCacheTags()$expected_cacheability->getCacheContexts(), FALSE, $dynamic_cache);

    // If the response should vary by a user's authorizations, grant permissions     // for the included resources and execute another request.     $permission_related_cache_contexts = [
      'user',
      'user.permissions',
      'user.roles',
    ];
    if (!empty($relationship_field_names) && !empty(array_intersect($expected_cacheability->getCacheContexts()$permission_related_cache_contexts))) {
      $applicable_permissions = array_intersect_key(static::getIncludePermissions()array_flip($relationship_field_names));
      $flattened_permissions = array_unique(array_reduce($applicable_permissions, 'array_merge', []));
      $this->grantPermissionsToTestedRole($flattened_permissions);
      $expected_response = $this->getExpectedCollectionResponse($filtered_entity_collection$filtered_collection_include_url->toString()$request_options$relationship_field_names, TRUE);
      $expected_cacheability = $expected_response->getCacheableMetadata();
      $expected_document = $expected_response->getResponseData();
      $response = $this->request('GET', $filtered_collection_include_url$request_options);
      $requires_include_only_permissions = !empty($flattened_permissions);
      $uncacheable = $expected_cacheability->getCacheMaxAge() === 0 || !empty(array_intersect(['user', 'session']$expected_cacheability->getCacheContexts()));
      $dynamic_cache = !$uncacheable ? $requires_include_only_permissions ? 'MISS' : 'HIT' : 'UNCACHEABLE';
      $this->assertResourceResponse(200, $expected_document$response$expected_cacheability->getCacheTags()$expected_cacheability->getCacheContexts(), FALSE, $dynamic_cache);
    }

    
Home | Imprint | This part of the site doesn't use cookies.