view core/modules/rest/tests/src/Functional/BasicAuthResourceWithInterfaceTranslationTestTrait.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents
children
line wrap: on
line source
<?php

namespace Drupal\Tests\rest\Functional;

use Psr\Http\Message\ResponseInterface;

/**
 * Trait for ResourceTestBase subclasses testing $auth=basic_auth + 'language'.
 *
 * @see \Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait
 */
trait BasicAuthResourceWithInterfaceTranslationTestTrait {

  use BasicAuthResourceTestTrait;

  /**
   * {@inheritdoc}
   */
  protected function assertResponseWhenMissingAuthentication($method, ResponseInterface $response) {
    // Because BasicAuth::challengeException() relies on the 'system.site'
    // configuration, and this test installs the 'language' module, all config
    // may be translated and therefore gets the 'languages:language_interface'
    // cache context.
    $expected_page_cache_header_value = $method === 'GET' ? 'MISS' : FALSE;
    $this->assertResourceErrorResponse(401, 'No authentication credentials provided.', $response, ['4xx-response', 'config:system.site', 'config:user.role.anonymous', 'http_response'], ['languages:language_interface', 'user.roles:anonymous'], $expected_page_cache_header_value, $expected_page_cache_header_value);
  }

}