protected function TestSubContext::uploadScreenshot in Panopoly 8.2
Same name and namespace in other branches
- 7 modules/panopoly/panopoly_test/behat/steps/panopoly_test.behat.inc \TestSubContext::uploadScreenshot()
Uploads a screenshot to imgur.
Parameters
string $image: The image data.
string $title: The image title.
string $imgur_client_id: The Client ID for your application registered with imgur.
See also
1 call to TestSubContext::uploadScreenshot()
- TestSubContext::takeScreenshot in modules/
panopoly/ panopoly_test/ behat/ steps/ panopoly_test.behat.inc - Explicitly take a screenshot.
File
- modules/
panopoly/ panopoly_test/ behat/ steps/ panopoly_test.behat.inc, line 400 - Provide Behat step-definitions for generic Panopoly tests.
Class
- TestSubContext
- Behat sub-context for Panopoly.
Code
protected function uploadScreenshot($image, $title, $imgur_client_id) {
// @todo This should use Guzzle rather than curl directly
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.imgur.com/3/image",
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "image=" . urlencode(base64_encode($image)) . "&title={$title}",
CURLOPT_HTTPHEADER => [
"authorization: Client-ID {$imgur_client_id}",
"cache-control: no-cache",
"content-type: application/x-www-form-urlencoded",
],
]);
$response = curl_exec($curl);
$error = curl_error($curl);
curl_close($curl);
$payload = json_decode($response);
if ($error || property_exists($payload, 'error')) {
return;
}
return $payload->data->link;
}