function UpdateFetcherTest::testUpdateFetcherHttpFallback
Same name in other branches
- 10 core/modules/update/tests/src/Unit/UpdateFetcherTest.php \Drupal\Tests\update\Unit\UpdateFetcherTest::testUpdateFetcherHttpFallback()
- 11.x core/modules/update/tests/src/Unit/UpdateFetcherTest.php \Drupal\Tests\update\Unit\UpdateFetcherTest::testUpdateFetcherHttpFallback()
@covers ::doRequest @covers ::fetchProjectData
File
-
core/
modules/ update/ tests/ src/ Unit/ UpdateFetcherTest.php, line 213
Class
- UpdateFetcherTest
- Tests update functionality unrelated to the database.
Namespace
Drupal\Tests\update\UnitCode
public function testUpdateFetcherHttpFallback() {
$settings = new Settings([
'update_fetch_with_http_fallback' => TRUE,
]);
$this->mockClient(new Response('500', [], 'HTTPS failed'), new Response('200', [], 'HTTP worked'));
$update_fetcher = new UpdateFetcher($this->mockConfigFactory, $this->mockHttpClient, $settings);
$data = $update_fetcher->fetchProjectData($this->testProject, '');
// There should be two request / response pairs.
$this->assertCount(2, $this->history);
// The first should have been HTTPS and should have failed.
$first_try = $this->history[0];
$this->assertNotEmpty($first_try);
$this->assertEquals('https', $first_try['request']->getUri()
->getScheme());
$this->assertEquals(500, $first_try['response']->getStatusCode());
// The second should have been the HTTP fallback and should have worked.
$second_try = $this->history[1];
$this->assertNotEmpty($second_try);
$this->assertEquals('http', $second_try['request']->getUri()
->getScheme());
$this->assertEquals(200, $second_try['response']->getStatusCode());
// Although this is a bogus mocked response, it's what fetchProjectData()
// should return in this case.
$this->assertEquals('HTTP worked', $data);
$this->assertSame([
"Server error: `GET https://www.example.com/update_test/current` resulted in a `500 Internal Server Error` response:\nHTTPS failed\n",
], $this->logMessages);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.