test_functions.php
Table of Contents
Functions
- resource_random_jpg() : bool
- Generates a random JPEG image for a given resource with random background color and text.
- create_random_image() : array<string|int, mixed>
- Generate a random image which can be used during testing (e.g to upload, or create previews for)
- create_random_video() : array<string|int, mixed>
- Generate a random video which can be used during testing (e.g to upload, or create previews for)
- test_log() : void
- Debug logs for ResourceSpace automated tests
- test_get_file_id() : int
- Get the test files' ID (from its file name)
Functions
resource_random_jpg()
Generates a random JPEG image for a given resource with random background color and text.
resource_random_jpg(int $resource, int $width, int $height) : bool
This function creates an image of specified dimensions with a random background color and text indicating the resource reference. The image is then saved to the resource's designated path and also triggers the creation of previews for the resource.
Parameters
- $resource : int
-
The reference ID of the resource for which the image is being created.
- $width : int
-
The width of the generated image in pixels.
- $height : int
-
The height of the generated image in pixels.
Return values
bool —Returns true on success, indicating that the image was created and saved successfully.
create_random_image()
Generate a random image which can be used during testing (e.g to upload, or create previews for)
create_random_image(array<string|int, mixed> $info) : array<string|int, mixed>
Parameters
- $info : array<string|int, mixed>
-
Set image parameters:
- text -> Image content text
- filename (default: random)
- width (default: 150)
- height (default: 50)
- bg[red|green|blue] -> Background colour (RGB), e.g $info['bg']['red'] = 234;
Return values
array<string|int, mixed> —Returns an "error" key if something went wrong, otherwise provides some useful info (e.g path)
create_random_video()
Generate a random video which can be used during testing (e.g to upload, or create previews for)
create_random_video(array<string|int, mixed> $info) : array<string|int, mixed>
Parameters
- $info : array<string|int, mixed>
-
Set video parameters:
- duration (default: 5 seconds)
- width (default: 300)
- height (default: 300)
- filename (default: random)
- extension (default: mp4)
- text -> Video content text (optional)
Return values
array<string|int, mixed> —Returns an "error" key if something went wrong, otherwise provides some useful info (e.g path)
test_log()
Debug logs for ResourceSpace automated tests
test_log(string $msg) : void
Parameters
- $msg : string
Tags
test_get_file_id()
Get the test files' ID (from its file name)
test_get_file_id(string $file) : int
Parameters
- $file : string