Add module integration tests

This commit is contained in:
cytopia
2019-11-18 16:52:35 +01:00
parent 2c6e013fad
commit db7c4e6334
7 changed files with 359 additions and 0 deletions

29
tests/mods/01-test-modules.sh Executable file
View File

@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
IMAGE="${1}"
VERSION="${2}"
FLAVOUR="${3}"
# shellcheck disable=SC1090
. "${CWD}/../.lib.sh"
# -------------------------------------------------------------------------------------------------
# Testing
# -------------------------------------------------------------------------------------------------
ERROR=0
for dir in $( ls -1 "${CWD}/modules/" ); do
if ! "${CWD}/modules.sh" "${IMAGE}" "${VERSION}" "${FLAVOUR}" "${dir}"; then
ERROR="$(( ERROR + 1 ))"
fi
done
exit "${ERROR}"

80
tests/mods/modules.sh Executable file
View File

@@ -0,0 +1,80 @@
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
if [ "${#}" != "4" ]; then
>&2 echo "Error, requires 4 arguments: <IMAGE> <VERSION> <FLAVOUR> <MODULE>"
exit 1
fi
IMAGE="${1}"
VERSION="${2}"
FLAVOUR="${3}"
MODULE="${4}"
# shellcheck disable=SC1090
. "${CWD}/../.lib.sh"
SKIP_GD=("")
echo
echo "# ------------------------------------------------------------"
echo "# Testing: ${MODULE}"
echo "# ------------------------------------------------------------"
echo
# -------------------------------------------------------------------------------------------------
# Check skipping
# -------------------------------------------------------------------------------------------------
if [[ ${SKIP_GD[*]} =~ ${VERSION} ]]; then
echo "Skipping '${MODULE}' checks for PHP ${VERSION}"
exit 0
fi
# -------------------------------------------------------------------------------------------------
# Testing
# -------------------------------------------------------------------------------------------------
WORKDIR="/tmp/${MODULE}"
docker run \
--rm \
-e DEBUG_ENTRYPOINT=0 \
-e NEW_UID="$(id -u)" \
-e NEW_GID="$(id -g)" \
-v "${CWD}/modules/${MODULE}:${WORKDIR}" \
--entrypoint=sh \
--workdir="${WORKDIR}" \
"${IMAGE}:${VERSION}-${FLAVOUR}" \
-c 'find . -name "*.php" -type f -print0 | xargs -0 -n1 sh -c "
set -e
set -u
if [ -f \"\${1:-}\" ]; then
fail=0
printf \"[TEST] %s\" \"\${1}\"
if script -e -c \"php \${1}\" /dev/null 2>&1 | grep -Ei \"core|segmentation|fatal|except|err|warn|notice\" 2>&1 >/dev/null; then
fail=1
fi
if ! php \"\${1}\" 2>&1 | grep -E \"^OK$\" 2>&1 >/dev/null; then
fail=1
fi
if [ \"\${fail}\" != \"0\" ]; then
printf \"\\r[FAIL] %s\\n\" \"\${1}\"
php \"\${1}\" || true
exit 1
else
printf \"\\r[OK] %s\\n\" \"\${1}\"
fi
fi
" --'

View File

@@ -0,0 +1,26 @@
<?php
/**
* This page should print 'OK' if everything works,
* 'FAIL' or nothing if an error occured.
*/
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
$a = '1.234';
$b = '5';
$num1 = bcadd($a, $b); // 6
$num2 = bcadd($a, $b, 4); // 6.2340
if ($num1 != 6) {
echo 'FAIL: ' . $num1;
exit(1);
}
if ($num2 != 6.2340) {
echo 'FAIL: ' . $num2;
exit(1);
}
echo 'OK';

View File

@@ -0,0 +1,67 @@
<?php
/**
* This page should print 'OK' if everything works,
* 'FAIL' or nothing if an error occured.
*/
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
// Create a blank image and add some text
if ( ($im = imagecreatetruecolor(640, 480)) === FALSE ) {
echo 'FAIL: imagecreatetruecolor()';
exit(1);
}
// First we create our stamp image manually from GD
if ( ($stamp = imagecreatetruecolor(100, 70)) === FALSE ) {
echo 'FAIL: imagecreatetruecolor()';
exit(1);
}
if (!imagefilledrectangle($stamp, 0, 0, 99, 69, 0x0000FF)) {
echo 'FAIL: imagefilledrectangle()';
exit(1);
}
if (!imagefilledrectangle($stamp, 9, 9, 90, 60, 0xFFFFFF)) {
echo 'FAIL: imagefilledrectangle()';
exit(1);
}
if (!imagestring($stamp, 5, 20, 20, 'libGD', 0x0000FF)) {
echo 'FAIL: imagestring()';
exit(1);
}
if (!imagestring($stamp, 3, 20, 40, '(c) 2007-9', 0x0000FF)) {
echo 'FAIL: imagestring()';
exit(1);
}
// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// Merge the stamp onto our photo with an opacity of 50%
if (!imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50)) {
echo 'FAIL: imagecopymerge()';
exit(1);
}
// Save the image to file and free memory
if (!imagejpeg($im, 'image.jpg')) {
echo 'FAIL: imagejpeg()';
exit(1);
}
if (!imagedestroy($im)) {
echo 'FAIL: imagedestroy()';
unlink('image.jpg');
exit(1);
}
// Remove image after test
unlink('image.jpg');
echo 'OK';

View File

@@ -0,0 +1,67 @@
<?php
/**
* This page should print 'OK' if everything works,
* 'FAIL' or nothing if an error occured.
*/
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
// Create a blank image and add some text
if ( ($im = imagecreatetruecolor(640, 480)) === FALSE ) {
echo 'FAIL: imagecreatetruecolor()';
exit(1);
}
// First we create our stamp image manually from GD
if ( ($stamp = imagecreatetruecolor(100, 70)) === FALSE ) {
echo 'FAIL: imagecreatetruecolor()';
exit(1);
}
if (!imagefilledrectangle($stamp, 0, 0, 99, 69, 0x0000FF)) {
echo 'FAIL: imagefilledrectangle()';
exit(1);
}
if (!imagefilledrectangle($stamp, 9, 9, 90, 60, 0xFFFFFF)) {
echo 'FAIL: imagefilledrectangle()';
exit(1);
}
if (!imagestring($stamp, 5, 20, 20, 'libGD', 0x0000FF)) {
echo 'FAIL: imagestring()';
exit(1);
}
if (!imagestring($stamp, 3, 20, 40, '(c) 2007-9', 0x0000FF)) {
echo 'FAIL: imagestring()';
exit(1);
}
// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// Merge the stamp onto our photo with an opacity of 50%
if (!imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50)) {
echo 'FAIL: imagecopymerge()';
exit(1);
}
// Save the image to file and free memory
if (!imagepng($im, 'image.png')) {
echo 'FAIL: imagepng()';
exit(1);
}
if (!imagedestroy($im)) {
echo 'FAIL: imagedestroy()';
unlink('image.png');
exit(1);
}
// Remove image after test
unlink('image.png');
echo 'OK';

View File

@@ -0,0 +1,50 @@
<?php
/**
* This page should print 'OK' if everything works,
* 'FAIL' or nothing if an error occured.
*/
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
// Only available since 5.4.0
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
echo 'OK';
exit(0);
}
// Create a blank image and add some text
if ( ($im = imagecreatetruecolor(120, 20)) === FALSE ) {
echo 'FAIL: imagecreatetruecolor()';
exit(1);
}
if ( ($text_color = imagecolorallocate($im, 233, 14, 91)) === FALSE ) {
echo 'FAIL: imagecolorallocate()';
exit(1);
}
if (!imagestring($im, 1, 5, 5, 'WebP with PHP', $text_color)) {
echo 'FAIL: imagestring()';
exit(1);
}
// Save the image
if (!imagewebp($im, 'image.webp')) {
echo 'FAIL: imagewebp()';
exit(1);
}
// Free up memory
if (!imagedestroy($im)) {
echo 'FAIL: imagedestroy()';
unlink('image.webp');
exit(1);
}
// Remove image after test
unlink('image.webp');
echo 'OK';

View File

@@ -0,0 +1,40 @@
<?php
/**
* This page should print 'OK' if everything works,
* 'FAIL' or nothing if an error occured.
*/
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
/* Set width and height in proportion of genuine PHP logo */
$width = 400;
$height = 210;
/* Create an Imagick object with transparent canvas */
$img = new Imagick();
if ($img->newImage($width, $height, new ImagickPixel('transparent')) !== TRUE) {
echo 'FAIL: imagecreatetruecolor()';
exit(1);
}
/* New ImagickDraw instance for ellipse draw */
$draw = new ImagickDraw();
/* Set purple fill color for ellipse */
$draw->setFillColor('#777bb4');
/* Set ellipse dimensions */
$draw->ellipse($width / 2, $height / 2, $width / 2, $height / 2, 0, 360);
/* Draw ellipse onto the canvas */
$img->drawImage($draw);
/* Reset fill color from purple to black for text (note: we are reusing ImagickDraw object) */
$draw->setFillColor('black');
if ($img->setImageFormat('png') !== TRUE) {
echo 'FAIL: imagecreatetruecolor()';
exit(1);
}
echo 'OK';