add a message how to start apache manually
[mkws-moved-to-github.git] / test / widgets / Makefile
1 # Copyright (c) 2013-2014 Index Data ApS. http://indexdata.com
2
3 PHANTOMJS_TIMEOUT=30
4 PHANTOMJS=      ../bin/bomb --timeout=${PHANTOMJS_TIMEOUT} ../node_modules/phantomjs/bin/phantomjs
5 IMAGES=         ./images
6 SCREENSHOT_WIDTH_HEIGHT=        1000 1200
7 PROG=   ../phantom/screenshot.js
8 MD5=    $(shell which md5 md5sum)
9 TESTS=  koha demos mike # koha.url
10 TIMEOUT=4
11 PREFIX= test
12 APACHE_PORT:= $(shell echo $${APACHE_PORT-4040})
13
14 PHANTOMJS_URL=  http://cph.koha.indexdata.com/cgi-bin/koha/opac-search.pl?q=sushi
15 PHANTOMJS_URL=  http://www.indexdata.com/
16
17 all: help
18
19 clean:
20         rm -f index-*.html
21         rm -f iframe-*.html
22         rm -f ${IMAGES}/*.png
23
24 distclean: clean
25         rm -f ${IMAGES}/*.png.tmp
26
27 test: check
28
29 screenshot:
30         file=${PREFIX}.$$(echo "${PHANTOMJS_URL}" | perl -npe 's,(\W),-,g; s/-$$//;'); \
31           ${PHANTOMJS} ${PROG} "${PHANTOMJS_URL}" ${IMAGES}/tmp.$$file.png ${SCREENSHOT_WIDTH_HEIGHT} ${TIMEOUT}; \
32           mv -f  ${IMAGES}/tmp.$$file.png  ${IMAGES}/$$file.png
33
34 screenshots: clean estimate-time iframe
35         set -e; \
36         for t in ${TESTS}; do \
37             for i in $$(cat url.$$t); do \
38                 ${MAKE} PHANTOMJS_URL="$$i" TIMEOUT=4 PREFIX=$$t screenshot & sleep 1; \
39             done; wait; \
40             ${MAKE} PREFIX=$$t index; \
41         done
42         ${MAKE} index-widgets tidy help-url
43
44 help-url:
45         @echo ""
46         @echo "Please check now: "
47         @echo "   http://localhost:${APACHE_PORT}/test/widgets/index.html"
48         @echo ""
49         @echo "You can start the web server with: make apache-start"
50
51 estimate-time:
52         @wc -l url.* | tail -n1 | awk '{print "Estimeate run time: " $$1 * (1 + '${TIMEOUT}') * 0.5, "seconds" }'
53         @echo ""
54
55 index:
56         ( cd ${IMAGES}; ls -tr ${PREFIX}.*.png | perl -ne 'chomp; print qq{<h2>$$_</h2><img src="'${IMAGES}/'$$_"/><br/><br/><p/>\n}' ) > index-${PREFIX}.html
57
58 index-widgets:
59         ls -t index-*html iframe-*.html | perl -ne 'chomp; print qq{<a href="$$_">$$_</a><br/>\n}' > index.html
60
61 iframe: index-iframe-demo
62 index-iframe-demo:
63         ( egrep example.indexdata.com url.demos | perl -ne 'chomp; print qq{<h2>$$_</h2><iframe width="900px" height="600px" src="$$_"></iframe>\n}' ) > iframe-demos-example.html
64         ( egrep -v example.indexdata.com url.demos | perl -ne 'chomp; print qq{<h2>$$_</h2><iframe width="900px" height="600px" src="$$_"></iframe>\n}' ) > iframe-demos-other.html
65
66 tidy:
67         for i in iframe-demos*.html index*.html; do \
68             tidy -i -m $$i >/dev/null 2>&1; \
69             perl -i -npe 's,(^\s*</head>),<link type="text/css" rel="stylesheet" href="screenshots.css" /> $$1,' $$i; \
70         done
71
72 help:
73         @echo "make [ all | clean | distclean ]"
74         @echo "     [ screenshots ]"
75         @echo "     [ screenshot | index | iframe | tidy ]"
76         @echo ""
77         @echo "Examples: "
78         @echo ""
79         @echo "make TESTS=mike screenshots"
80