Limit the images that previews keep.
A preview that fails the captcha or the form token keeps no image. A session keeps one image, the directory has a size limit, and abandoned images go at the next upload.
This commit is contained in:
@@ -161,13 +161,24 @@ abstract class PageTestCase extends \PHPUnit\Framework\TestCase {
|
||||
* name => list of values, 'body' => ...). Cookies go and come back as a
|
||||
* browser sends them, without regard to domain or the secure flag.
|
||||
*/
|
||||
protected function request(string $method, string $path, array $post = array(), array $headers = array()): array {
|
||||
protected function request(string $method, string $path, array $post = array(), array $headers = array(), array $files = array()): array {
|
||||
if ($this->cookies) {
|
||||
$headers['Cookie'] = implode('; ', array_map(function ($name, $value) { return "$name=" . rawurlencode($value); },
|
||||
array_keys($this->cookies), $this->cookies));
|
||||
}
|
||||
$options = array('method' => $method, 'follow_location' => 0, 'ignore_errors' => TRUE, 'timeout' => 30);
|
||||
if ($method === 'POST') {
|
||||
if ($method === 'POST' && $files) {
|
||||
// A multipart form; $files holds field => array(file name, content)
|
||||
$boundary = 'xxx-' . bin2hex(random_bytes(8));
|
||||
$body = '';
|
||||
foreach ($post as $name => $value)
|
||||
$body .= "--$boundary\r\nContent-Disposition: form-data; name=\"$name\"\r\n\r\n$value\r\n";
|
||||
foreach ($files as $name => list($filename, $content))
|
||||
$body .= "--$boundary\r\nContent-Disposition: form-data; name=\"$name\"; filename=\"$filename\"\r\n"
|
||||
. "Content-Type: application/octet-stream\r\n\r\n$content\r\n";
|
||||
$options['content'] = $body . "--$boundary--\r\n";
|
||||
$headers['Content-Type'] = "multipart/form-data; boundary=$boundary";
|
||||
} else if ($method === 'POST') {
|
||||
$options['content'] = http_build_query($post);
|
||||
$headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
||||
}
|
||||
@@ -207,6 +218,16 @@ abstract class PageTestCase extends \PHPUnit\Framework\TestCase {
|
||||
return $this->request('POST', $path, $post, $headers);
|
||||
}
|
||||
|
||||
// A POST with files: $files holds field => array(file name, content)
|
||||
protected function postFiles(string $path, array $post, array $files): array {
|
||||
return $this->request('POST', $path, $post, array(), $files);
|
||||
}
|
||||
|
||||
// The files in the upload directory of the server
|
||||
protected function uploads(): array {
|
||||
return glob(self::$state . '/tmp/uploads/*') ?: array();
|
||||
}
|
||||
|
||||
protected function header(array $response, string $name): ?string {
|
||||
return $response['headers'][strtolower($name)][0] ?? NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user