Moved API\Notification tests

This commit is contained in:
Philipp 2021-11-12 21:35:21 +01:00
parent f2ca21935e
commit 6725f05ab2
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
8 changed files with 161 additions and 86 deletions

View file

@ -35,6 +35,29 @@ class ApiResponse
$this->logger = $logger;
}
/**
* Sets header directly
* mainly used to override it for tests
*
* @param string $header
*/
protected function setHeader(string $header)
{
header($header);
}
/**
* Prints output directly to the caller
* mainly used to override it for tests
*
* @param string $output
*/
protected function printOutput(string $output)
{
echo $output;
exit;
}
/**
* Creates the XML from a JSON style array
*
@ -143,7 +166,7 @@ class ApiResponse
'request' => $this->args->getQueryString()
];
header(($_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.1') . ' ' . $code . ' ' . $description);
$this->setHeader(($_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.1') . ' ' . $code . ' ' . $description);
$this->exit('status', ['status' => $error], $format);
}
@ -165,10 +188,10 @@ class ApiResponse
switch ($format) {
case 'xml':
header('Content-Type: text/xml');
$this->setHeader('Content-Type: text/xml');
break;
case 'json':
header('Content-Type: application/json');
$this->setHeader('Content-Type: application/json');
if (!empty($return)) {
$json = json_encode(end($return));
if (!empty($_GET['callback'])) {
@ -178,17 +201,16 @@ class ApiResponse
}
break;
case 'rss':
header('Content-Type: application/rss+xml');
$this->setHeader('Content-Type: application/rss+xml');
$return = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . $return;
break;
case 'atom':
header('Content-Type: application/atom+xml');
$this->setHeader('Content-Type: application/atom+xml');
$return = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . $return;
break;
}
echo $return;
exit;
$this->printOutput($return);
}
/**