# Makefile to drive test cases for difficult subsystems.
# Intended to make sure that not too much breakage can sneak past unnoticed.
.PHONY: all
SAFECSSMIN=script/safecssmin
all:: ../${SAFECSSMIN}
# Ensure that whitespace is stripped.
all:: test0
test0: ../${SAFECSSMIN}
@echo Checking that whitespace is stripped...
@cd ..; [ ".ad{width:100}" = "`echo .ad { width : 100 } | ${SAFECSSMIN}`" ]
@touch $@
# Ensure that fallback cupport for old browsers is not stripped.
# .fullw,.fullwcdisp,.fullwctbl{width:100%;width:100vw;position:relative;left:50%;right:50%;margin-left:-50%;margin-left:-50vw;margin-right:-50%;margin-right:-50vw}.fullwcdisp{clear:both;text-align:center}.fullwctbl{clear:both}
# Eg note "margin-left:-50%;margin-left:-50vw;"
all:: test1
test1: ../${SAFECSSMIN} ../img/css/fullw-20200805.min.css
@echo Checking that fallbacks for older browsers are not stripped...
@(cd ..; ${SAFECSSMIN} < img/css/fullw-20200805.min.css )> $@.tmp
@if [ "`cat ../img/css/fullw-20200805.min.css`" != "`cat $@.tmp`" ]; then echo "ERROR: should be:"; cat ../img/css/fullw-20200805.min.css; echo ""; echo "Is:"; cat $@.tmp; echo ""; exit 1; fi
@mv $@.tmp $@
# Ensure that repeated clauses for same selector can be merged.
# This is a common residue when stripping CSS with static analysis.
REPEATED=".respfloatr{float:right}.respfloatr{max-width:50}.respfloatr{border-radius:4px}"
all:: test2
test2: ../${SAFECSSMIN}
@echo Checking that adjacent same-selector rules are merged...
@(cd ..; echo "${REPEATED}" | ${SAFECSSMIN}) > $@.tmp
@[ ".respfloatr{float:right;max-width:50;border-radius:4px}" = "`cat $@.tmp`" ]
@mv $@.tmp $@
# Image converter/extracter.
GHII=script/get_hero_img_inline
# Default value for GALLERYCMSPATH.
GALLERYCMSPATH ?= /rw/galleryDB/photos/
# Ensure that correct images are selected for IMG tag for desktop, etc.
# test3a is a conventional static raster image under img/.
all:: test3a
TARGETIMGa=img/iButton/iButton-temperature-recording-devices-DS1921G.jpg
test3a: ../${GHII} ../${TARGETIMGa}
@test -s ../${TARGETIMGa}
@test "`wc -c < ../${TARGETIMGa}`" -eq 207537
@echo Checking correct body images auto-generated for static raster image a.
@cd ..; [ 'img/a/b/iButton-temperature-recording-devices-DS1921G.l207537.400x256.jpg' = "`${GHII} autogenImg $(TARGETIMGa) unit-test3a http://www.earth.org.uk/ false 400`" ]
@cd ..; [ 'img/a/b/iButton-temperature-recording-devices-DS1921G.l207537.320x205.jpg' = "`${GHII} autogenImg $(TARGETIMGa) unit-test3a http://www.earth.org.uk/ true 320`" ]
@cd ..; [ 'img/a/b/iButton-temperature-recording-devices-DS1921G.l207537.320x205.jpg' = "`${GHII} autogenImg $(TARGETIMGa) unit-test3a http://www.earth.org.uk/ amp 320`" ]
@echo Checking correct desktop image selected for image a.
@cd ..; [ '' = "`${GHII} floatImg $(TARGETIMGa) unit-test3a http://www.earth.org.uk/ false '' '' respfloatr`" ]
@echo Checking correct mobile image selected for image a.
@cd ..; [ '' = "`${GHII} floatImg $(TARGETIMGa) unit-test3a http://www.earth.org.uk/ true '' '' respfloatr`" ]
@echo Checking correct AMP image selected for image a.
@cd ..; [ '' = "`${GHII} floatImg $(TARGETIMGa) unit-test3a http://www.earth.org.uk/ amp '' '' respfloatr`" ]
# test3b is a static vector image under img/.
all:: test3b
TARGETIMGb=img/20180507-16WW-HeatingEfficiency-co-Pilio.svg
test3b: ../${GHII} ../${TARGETIMGb}
@test -s ../${TARGETIMGb}
@test "`wc -c < ../${TARGETIMGb}`" -eq 6597
@echo Checking correct desktop image selected for static vector image b.
@cd ..; [ '' = "`${GHII} floatImg $(TARGETIMGb) unit-test3b http://www.earth.org.uk/ false '' '' respF heating`" ]
# TODO: test3c is a dynamic image under out/.
#all:: test3c
# test3d is a large raster image from the Gallery.
all:: test3d
TARGETIMGdRAW=http://gallery.hd.org/_tn/std/energy-matters/_more2011/_more12/MHRV-mechanical-heat-recovery-ventilation-Vent-Axia-HR25H-with-humidistat-being-fitted-to-small-bathroom-33-DHD.jpg
ABSTARGETIMGd=$(GALLERYCMSPATH)energy-matters/_more2011/_more12/MHRV-mechanical-heat-recovery-ventilation-Vent-Axia-HR25H-with-humidistat-being-fitted-to-small-bathroom-33-DHD.jpg
test3d: ../${GHII} ${ABSTARGETIMGd}
@test -s ${ABSTARGETIMGd}
@test "`wc -c < ${ABSTARGETIMGd}`" -eq 4992530
@echo Checking correct desktop image selected for large gallery raster image d.
@cd ..; [ '' = "`${GHII} floatImg $(TARGETIMGdRAW) unit-test3d http://www.earth.org.uk/ false '' '' respfloatlsml external`" ]
# test3e is a small-enough-to-use-directly raster image from the Gallery.
all:: test3e
TARGETIMGeRAW=http://gallery.hd.org/_tn/std/energy-matters/_more2015/_more01/MHRV-mechanical-heat-recovery-ventilation-Vent-Axia-HR25H-seen-working-in-thermal-image-imaging-with-handheld-IR-infrared-camera-warm-outgoing-on-left-cool-incoming-on-right-1-DHD.jpg
ABSTARGETIMGe=$(GALLERYCMSPATH)energy-matters/_more2015/_more01/MHRV-mechanical-heat-recovery-ventilation-Vent-Axia-HR25H-seen-working-in-thermal-image-imaging-with-handheld-IR-infrared-camera-warm-outgoing-on-left-cool-incoming-on-right-1-DHD.jpg
test3e: ../${GHII} ${ABSTARGETIMGe}
@test -s ${ABSTARGETIMGe}
@test "`wc -c < ${ABSTARGETIMGe}`" -eq 32404
@echo Checking correct desktop image selected for small gallery raster image e.
@cd ..; [ '' = "`${GHII} floatImg $(TARGETIMGeRAW) unit-test3e http://www.earth.org.uk/ false '' '' respfloatlsml IR`" ]
@echo Checking correct mobile image selected for small gallery raster image e.
@cd ..; [ '' = "`${GHII} floatImg $(TARGETIMGeRAW) unit-test3e http://www.earth.org.uk/ true '' '' respfloatlsml IR`" ]
# Ensure that correct alt text is auto-extracted, incl for non-static cases.
all:: test4
test4: ../script/altTextFromFilename
@echo Checking correct alt text is auto-extracted for static img.
@cd ..; [ 'hob reflections' = "`script/altTextFromFilename img/SMAKLIG/hob-reflections-1-128w.jpg`" ]
@cd ..; [ 'solar PV grid tie roof mounted power system on slate roof on outbuilding shed garage 1 DHD' = "`script/altTextFromFilename http://gallery.hd.org/_tn/std/mechanoids/_more2010/_more06/solar-PV-grid-tie-roof-mounted-power-system-on-slate-roof-on-outbuilding-shed-garage-1-DHD.jpg`" ]
# Ensure that cross-page promotion can work.
all:: test5
PTP=.work/script/pickPageToPromote
test5: ../${PTP}
@echo Checking that cross-page promotion can work.
@cd ..; [ "" != "`${PTP} index.html`" -o "" != "`${PTP} about-16WW.html`" ]
# Tests of creation test-page output for desktop/mobile/AMP.
# Test for decription and title in suitable forms.
all::testDESC
testDESC:: ../test-page.html ../m/test-page.html ../amp/test-page.html
@echo "Testing for title, description, etc, in metadata."
@awk '{print;exit}' < ../test-page.html | fgrep -q '
Test Page'
@awk '{print;exit}' < ../test-page.html | fgrep -q 'content="Avert your eyes'
@awk '{print;exit}' < ../amp/test-page.html | fgrep -q 'Test Page'
@awk '{print;exit}' < ../amp/test-page.html | fgrep -q 'content="Avert your eyes'
@cat < ../m/test-page.html | fgrep -q 'Test Page'
@cat < ../m/test-page.html | fgrep -q 'content="Avert your eyes'
@echo "Testing for title, description, etc, in body."
@awk 'NR<=3{print}' < ../test-page.html | fgrep -q 'itemprop="headline name">Test Page'
@awk 'NR<=5{print}' < ../test-page.html | fgrep -q 'itemprop=description>Avert your eyes'
@awk 'NR<=3{print}' < ../amp/test-page.html | fgrep -q 'itemprop="headline name">Test Page'
@awk 'NR<=5{print}' < ../amp/test-page.html | fgrep -q 'itemprop=description>Avert your eyes'
@cat < ../m/test-page.html | fgrep -q 'itemprop="headline name">Test Page'
@cat < ../m/test-page.html | fgrep -q 'itemprop=description>Avert your eyes'
# Test for canonical and other key rel links.
all:: testREL
testREL: ../test-page.html ../m/test-page.html ../amp/test-page.html
@echo "Testing for correct header rel links."
@fgrep -q '' < ../m/test-page.html
@fgrep -q '' < ../amp/test-page.html
@fgrep -q '' < ../test-page.html
@fgrep -q '' < ../test-page.html
# Based on these source lines:
# Page type: desktop
# Page type: mobile (including AMP)
# Page type2: vanilla HTML5 (not AMP)
# Page type2: AMP
# The test-page.html files must already have been brought up to date.
all:: testPTBL
testPTBL: ../test-page.html ../m/test-page.html ../amp/test-page.html
@echo Testing for correct stripping of DESK/MOB/etc.
@echo Testing for correct stripping of DESK/MOB/etc on desktop.
@egrep -q '^PTBL: Desktop vs Mobile Page Type Line By Line
$$' ../test-page.html
@[ 'Page type: desktop' = "`egrep '^Page type:' < ../test-page.html`" ]
@[ 'Page type2: vanilla HTML5 (not AMP)' = "`egrep '^Page type2:' < ../test-page.html`" ]
@echo Testing for correct stripping of DESK/MOB/etc on AMP.
@egrep -q '^PTBL: Desktop vs Mobile Page Type Line By Line
$$' ../amp/test-page.html
@[ 'Page type: mobile (including AMP)' = "`egrep '^Page type:' < ../amp/test-page.html`" ]
@[ 'Page type2: AMP' = "`egrep '^Page type2:' < ../amp/test-page.html`" ]
@echo Testing for correct stripping of DESK/MOB/etc on vanilla mobile.
@egrep -q 'PTBL: Desktop vs Mobile Page Type Line By Line
' ../m/test-page.html
@[ '' != "`egrep 'Page type: mobile' < ../m/test-page.html`" ]
@[ '' != "`egrep 'Page type2: vanilla' < ../m/test-page.html`" ]