public function testPrefill()
{
$this->setRequest(Request::create('/bolt/prefill'));
$response = $this->controller()->prefill($this->getRequest());
$context = $response->getContext();
$this->assertEquals(4, count($context['context']['contenttypes']));
$this->assertInstanceOf('Symfony\\Component\\Form\\FormView', $context['context']['form']);
// Test the post
$this->setRequest(Request::create('/bolt/prefill', 'POST', ['contenttypes' => 'pages']));
$response = $this->controller()->prefill($this->getRequest());
$this->assertEquals('/bolt/prefill', $response->getTargetUrl());
// Test for the Exception if connection fails to the prefill service
$store = $this->getMockBuilder(Storage::class)->setMethods(['preFill'])->setConstructorArgs([$this->getApp()])->getMock();
$guzzleRequest = new \GuzzleHttp\Psr7\Request('GET', '');
$store->expects($this->any())->method('preFill')->will($this->returnCallback(function () use($guzzleRequest) {
throw new \GuzzleHttp\Exception\RequestException('', $guzzleRequest);
}));
$this->setService('storage', $store);
$logger = $this->getMockMonolog();
$logger->expects($this->once())->method('error')->with("Timeout attempting connection to the 'Lorem Ipsum' generator. Unable to add dummy content.");
$this->setService('logger.system', $logger);
$this->setRequest(Request::create('/bolt/prefill', 'POST', ['contenttypes' => 'pages']));
$this->controller()->prefill($this->getRequest());
}