2 # Install and start Selenium in background, pass configuration, and
3 # run PHPUnit functional testsuite
5 # Copyright (C) 2011 Olivier Berger - Institut Telecom
6 # Copyright (C) 2014, 2015 Inria (Sylvain Beucler)
7 # Copyright 2020, 2021, Franck Villaume - TrivialDev
9 # This file is part of FusionForge. FusionForge is free software;
10 # you can redistribute it and/or modify it under the terms of the
11 # GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the Licence, or (at your option)
15 # FusionForge is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along
21 # with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 export DEBIAN_FRONTEND=noninteractive
34 echo " $0 src/opensuse"
35 echo " $0 rpm/opensuse"
39 export INSTALL_METHOD=${1%/*}
40 export INSTALL_OS=${1#*/}
43 case $INSTALL_METHOD in
45 *) echo "Unknown install method"
50 debian*|centos*|opensuse*) ;;
51 *) echo "Unknown install OS"
56 if grep SUSE /etc/os-release >/dev/null 2>&1; then
57 grep -q "granted" /etc/apache2/httpd.conf || sed -i -e "s/denied/granted/" /etc/apache2/httpd.conf
58 grep -q "Allow from" /etc/apache2/httpd.conf || sed -i -e "s/Deny from/Allow from/g" /etc/apache2/httpd.conf
59 grep -q "^APACHE_SERVER_FLAGS" /etc/sysconfig/apache2 | grep -q "SSL" || sed -i -e "s/^APACHE_SERVER_FLAGS=.*$/APACHE_SERVER_FLAGS=\"SSL\"/" /etc/sysconfig/apache2
60 service apache2 restart
67 os_version=$(rpm -q --qf "%{VERSION}" $(rpm -q --whatprovides redhat-release))
68 if [[ "$os_version" == "7" && `rpm -qi httpd-itk | grep Release | awk '{print $3}'` != '1.el7' ]]; then
69 echo 'WARNING: WORKAROUND for docker/lxc. Downgrade httpd-itk.'
70 echo 'TODO: check for newer version. Debian not impacted.'
71 curl https://kojipkgs.fedoraproject.org//packages/httpd-itk/2.4.7.04/1.el7/x86_64/httpd-itk-2.4.7.04-1.el7.x86_64.rpm -o /tmp/httpd-itk-2.4.7.04-1.el7.x86_64.rpm
72 yum downgrade -y /tmp/httpd-itk-2.4.7.04-1.el7.x86_64.rpm
73 rm -f /tmp/httpd-itk-2.4.7.04-1.el7.x86_64.rpm
74 service httpd restart || true
81 # Selenium dependencies and test dependencies
82 # psmisc for db_reload.sh:killall
83 # rsyslog to get e.g. sshd error log
84 if [ -e /etc/debian_version ]; then
85 apt-get -y install wget firefox-esr net-tools
86 if grep -q ^8 /etc/debian_version; then
87 apt-get -y install rsyslog patch composer
88 apt-get -y install -t jessie-backports openjdk-8-jdk
90 apt-get -y install php-curl unzip composer psmisc rsyslog default-jre patch
92 elif [ -e /etc/centos-release ]; then
93 yum -y install wget firefox
94 os_version=$(rpm -q --qf "%{VERSION}" $(rpm -q --whatprovides redhat-release))
97 yum -y install java-1.8.0-openjdk
100 yum -y install php-json php-xml java-11-openjdk
103 yum --enablerepo=epel install -y psmisc net-tools patch php-cli php-zip unzip
105 php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
106 php composer-setup.php --install-dir=/usr/local/bin --filename=composer
109 zypper --non-interactive install MozillaFirefox wget php-composer patch unzip psmisc net-tools-deprecated
111 mkdir -p /usr/local/share/php
112 pushd /usr/local/share/php
113 if grep "[[:space:]]8" /etc/centos-release >/dev/null 2>&1; then
114 composer --no-plugins --no-scripts require phpunit/phpunit:8.5
116 composer --no-plugins --no-scripts require phpunit/phpunit
118 if grep -q ^9 /etc/debian_version >/dev/null 2>&1 || [ -e /etc/centos-release ]; then
119 composer --no-plugins --no-scripts require phpunit/phpunit-selenium
121 composer --no-plugins --no-scripts require phpunit/phpunit-selenium:dev-master
125 # Install selenium (no packaged version available)
129 SELENIUMURL=http://selenium-release.storage.googleapis.com/$SELENIUMMAJOR.$SELENIUMMINOR/selenium-server-standalone-$SELENIUMMAJOR.$SELENIUMMINOR.$SELENIUMMICRO.jar
130 mkdir -p /usr/share/selenium/
131 http_proxy=$PROXY wget -v -c $SELENIUMURL \
132 -O /usr/share/selenium/selenium-server.jar
134 # Install GeckoDriver
138 GECKODRIVERURL=https://github.com/mozilla/geckodriver/releases/download/v$GECKODRIVERMAJOR.$GECKODRIVERMINOR.$GECKODRIVERMICRO/geckodriver-v$GECKODRIVERMAJOR.$GECKODRIVERMINOR.$GECKODRIVERMICRO-linux64.tar.gz
139 mkdir -p /usr/share/geckodriver/
140 rm -f /usr/share/geckodriver/geckodriver
141 http_proxy=$PROXY wget -c $GECKODRIVERURL \
142 -O /usr/share/geckodriver/geckodriver.tar.gz
144 tar -zxf /usr/share/geckodriver/geckodriver.tar.gz -C /usr/share/geckodriver/
145 chmod +x /usr/share/geckodriver/geckodriver
147 # Add alias to /etc/hosts
148 if ! grep -q ^$(hostname -i) /etc/hosts ; then
149 echo $(hostname -i) $(hostname -f) $(hostname)>> /etc/hosts
151 grep -q "^$(hostname -i).*$(forge_get_config scm_host)" /etc/hosts || sed -i -e "s/^$(hostname -i).*/& $(forge_get_config scm_host)/" /etc/hosts
152 grep -q "^$(hostname -i).*$(forge_get_config lists_host)" /etc/hosts || sed -i -e "s/^$(hostname -i).*/& $(forge_get_config lists_host)/" /etc/hosts
154 #fix https://github.com/giorgiosironi/phpunit-selenium/issues/427
155 for i in /usr/share/*/PHPUnit/Extensions/Selenium2TestCase/Element.php /usr/local/share/php/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase/Element.php ; do
156 if [ -e "$i" ] ; then
157 patch -N "$i" <<'EOF' || true
158 --- Element.php.dist 2014-11-02 09:23:27.000000000 +0000
159 +++ Element.php 2019-01-15 15:00:44.034513685 +0000
161 PHPUnit\Extensions\Selenium2TestCase_URL $parentFolder,
162 PHPUnit\Extensions\Selenium2TestCase_Driver $driver)
165 if (!isset($value['ELEMENT'])) {
166 - throw new InvalidArgumentException('Element not found.');
167 + foreach ($value as $lKey => $val) {
168 + if (substr($lKey,0,7) === "element") {
174 + throw new InvalidArgumentException('Element not found.');
179 - $url = $parentFolder->descend($value['ELEMENT']);
180 + $url = $parentFolder->descend($value[$key]);
181 return new self($driver, $url);
189 # Mitigate testsuite timeouts, cf.
190 # http://lists.fusionforge.org/pipermail/fusionforge-general/2015-November/002955.html
195 if ! grep -q '^export PGPASSFILE' /etc/apache2/envvars; then
196 echo 'export PGPASSFILE=' >> /etc/apache2/envvars
200 if ! grep -q '^PGPASSFILE' /etc/sysconfig/httpd; then
201 echo 'PGPASSFILE=' >> /etc/sysconfig/httpd
215 service cron stop || true
217 # Reset the database and repos to post-install/pristine state
218 $(dirname $0)/func/fixtures.sh --reset
219 $(dirname $0)/func/fixtures.sh --backup
223 FORGE_HOME=$(cd $(dirname $0)/..; pwd)
225 SELENIUM_RC_DIR=/var/log
226 SELENIUM_RC_HOST=$HOST
227 # URL for screenshots - cf. http://buildbot.fusionforge.org/env-vars.html
228 SELENIUM_RC_URL=${JOB_URL}ws/reports
229 # config.php will be loaded inside the functionnal test suite with
230 # require_once, in SeleniumForge.php
231 export SELENIUM_RC_DIR SELENIUM_RC_URL SELENIUM_RC_HOST HOST
233 # Add definitions for the PHP functionnal test suite
234 cat <<-EOF >$(dirname $0)/func/config.php
236 // Host where selenium-rc is running
237 define ('SELENIUM_RC_HOST', getenv('SELENIUM_RC_HOST'));
238 define ('SELENIUM_RC_DIR', getenv('SELENIUM_RC_DIR'));
240 // The forge's hostname
241 define ('HOST', getenv('HOST'));
243 // Base URL where FusionForge is installed
246 define('INSTALL_METHOD', getenv('INSTALL_METHOD'));
247 define('INSTALL_OS', getenv('INSTALL_OS'));
250 // DON'T MODIFY BELOW THIS LINE UNLESS YOU KNOW WHAT YOU DO
253 // These are deduced from the previous definitions.
255 // URL to access the application
256 define ('URL', 'https://'.HOST.'/');
258 // WSDL of the forges SOAP API
259 // define ('WSDL_URL', URL.'soap/index.php?wsdl');
260 define ('WSDL_URL', 'http://'.HOST.'/soap/index.php?wsdl');
263 echo "Starting Selenium"
264 killall -9 java || true
266 export PATH=/usr/share/geckodriver:/usr/lib/iceweasel:/usr/lib/firefox-esr:/usr/lib64/firefox:$PATH
268 java -Dwebdriver.gecko.driver=/usr/share/geckodriver/geckodriver -jar /usr/share/selenium/selenium-server.jar &
271 while [ $i -lt $timeout ] && ! netstat -tnl 2>/dev/null | grep -q :4444 && kill -0 $pid 2>/dev/null; do
272 echo "Waiting for Selenium..."
276 if [ $i = $timeout ]; then
277 echo "Selenium failed to start listener… lacking entropy? Trying again."
278 find / > /dev/null 2> /dev/null &
280 while [ $i -lt $timeout ] && ! netstat -tnl 2>/dev/null | grep -q :4444 && kill -0 $pid 2>/dev/null; do
281 echo "Waiting for Selenium..."
286 if [ $i = $timeout ] || ! kill -0 $pid 2>/dev/null; then
287 echo "Selenium failed to start!"
293 echo "Running PHPunit tests"
297 # Override test through parameter, useful when launching tests through buildbot/*.sh (e.g. SSH)
298 # Use the TESTGLOB environment variable otherwise
299 testname="func_tests.php"
300 if [ -n "$1" ] ; then
304 if [ -x /usr/local/share/php/vendor/bin/phpunit ] ; then
305 phpunit=/usr/local/share/php/vendor/bin/phpunit
310 # For some reason PHPunit thinks all methods are tests
311 # …hence the --filter ::test to enforce that
312 # otherwise shared methods such as login() and logout() are run like tests and fail
313 timeout 2h $phpunit --filter ::test --verbose --debug --stop-on-failure --log-junit $SELENIUM_RC_DIR/phpunit-selenium.xml $testname || retcode=$?
316 echo "phpunit returned with code $retcode"
320 killall -9 firefox-bin # debian
321 killall -9 firefox # centos
322 killall -9 java # kill java stuffs