You are here

public function SecurityAdvisoriesFetcherTest::testNoHttpFallback in Drupal 10

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Kernel/SecurityAdvisories/SecurityAdvisoriesFetcherTest.php \Drupal\Tests\system\Kernel\SecurityAdvisories\SecurityAdvisoriesFetcherTest::testNoHttpFallback()

@covers ::doRequest @covers ::getSecurityAdvisories

File

core/modules/system/tests/src/Kernel/SecurityAdvisories/SecurityAdvisoriesFetcherTest.php, line 667

Class

SecurityAdvisoriesFetcherTest
@coversDefaultClass \Drupal\system\SecurityAdvisories\SecurityAdvisoriesFetcher

Namespace

Drupal\Tests\system\Kernel\SecurityAdvisories

Code

public function testNoHttpFallback() : void {
  $this
    ->setTestFeedResponses([
    new Response('500', [], 'HTTPS failed'),
  ]);
  $exception_thrown = FALSE;
  try {
    $this
      ->getAdvisories();
  } catch (TransferException $exception) {
    $this
      ->assertSame("Server error: `GET https://updates.drupal.org/psa.json` resulted in a `500 Internal Server Error` response:\nHTTPS failed\n", $exception
      ->getMessage());
    $exception_thrown = TRUE;
  }
  $this
    ->assertTrue($exception_thrown);

  // There should only be one request / response pair.
  $this
    ->assertCount(1, $this->history);
  $request = $this->history[0]['request'];
  $this
    ->assertNotEmpty($request);

  // It should have only been an HTTPS request.
  $this
    ->assertEquals('https', $request
    ->getUri()
    ->getScheme());

  // And it should have failed.
  $response = $this->history[0]['response'];
  $this
    ->assertEquals(500, $response
    ->getStatusCode());
}