autotest.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #!/bin/bash
  2. #
  3. # ownCloud
  4. #
  5. # @author Thomas Müller
  6. # @copyright 2012, 2013 Thomas Müller thomas.mueller@tmit.eu
  7. #
  8. #$EXECUTOR_NUMBER is set by Jenkins and allows us to run autotest in parallel
  9. DATABASENAME=oc_autotest$EXECUTOR_NUMBER
  10. DATABASEUSER=oc_autotest$EXECUTOR_NUMBER
  11. ADMINLOGIN=admin$EXECUTOR_NUMBER
  12. DATADIR=data-autotest
  13. BASEDIR=$PWD
  14. echo "Using database $DATABASENAME"
  15. # create autoconfig for sqlite, mysql and postgresql
  16. cat > ./tests/autoconfig-sqlite.php <<DELIM
  17. <?php
  18. \$AUTOCONFIG = array (
  19. 'installed' => false,
  20. 'dbtype' => 'sqlite',
  21. 'dbtableprefix' => 'oc_',
  22. 'adminlogin' => '$ADMINLOGIN',
  23. 'adminpass' => 'admin',
  24. 'directory' => '$BASEDIR/$DATADIR',
  25. );
  26. DELIM
  27. cat > ./tests/autoconfig-mysql.php <<DELIM
  28. <?php
  29. \$AUTOCONFIG = array (
  30. 'installed' => false,
  31. 'dbtype' => 'mysql',
  32. 'dbtableprefix' => 'oc_',
  33. 'adminlogin' => '$ADMINLOGIN',
  34. 'adminpass' => 'admin',
  35. 'directory' => '$BASEDIR/$DATADIR',
  36. 'dbuser' => '$DATABASEUSER',
  37. 'dbname' => '$DATABASENAME',
  38. 'dbhost' => 'localhost',
  39. 'dbpass' => 'owncloud',
  40. );
  41. DELIM
  42. cat > ./tests/autoconfig-pgsql.php <<DELIM
  43. <?php
  44. \$AUTOCONFIG = array (
  45. 'installed' => false,
  46. 'dbtype' => 'pgsql',
  47. 'dbtableprefix' => 'oc_',
  48. 'adminlogin' => '$ADMINLOGIN',
  49. 'adminpass' => 'admin',
  50. 'directory' => '$BASEDIR/$DATADIR',
  51. 'dbuser' => '$DATABASEUSER',
  52. 'dbname' => '$DATABASENAME',
  53. 'dbhost' => 'localhost',
  54. 'dbpass' => 'owncloud',
  55. );
  56. DELIM
  57. cat > ./tests/autoconfig-oci.php <<DELIM
  58. <?php
  59. \$AUTOCONFIG = array (
  60. 'installed' => false,
  61. 'dbtype' => 'oci',
  62. 'dbtableprefix' => 'oc_',
  63. 'adminlogin' => '$ADMINLOGIN',
  64. 'adminpass' => 'admin',
  65. 'directory' => '$BASEDIR/$DATADIR',
  66. 'dbuser' => '$DATABASENAME',
  67. 'dbname' => 'XE',
  68. 'dbhost' => 'localhost',
  69. 'dbpass' => 'owncloud',
  70. );
  71. DELIM
  72. function execute_tests {
  73. echo "Setup environment for $1 testing ..."
  74. # back to root folder
  75. cd $BASEDIR
  76. # revert changes to tests/data
  77. git checkout tests/data/*
  78. # reset data directory
  79. rm -rf $DATADIR
  80. mkdir $DATADIR
  81. # remove the old config file
  82. #rm -rf config/config.php
  83. cp tests/preseed-config.php config/config.php
  84. # drop database
  85. if [ "$1" == "mysql" ] ; then
  86. mysql -u $DATABASEUSER -powncloud -e "DROP DATABASE $DATABASENAME"
  87. fi
  88. if [ "$1" == "pgsql" ] ; then
  89. dropdb -U $DATABASEUSER $DATABASENAME
  90. fi
  91. if [ "$1" == "oci" ] ; then
  92. echo "drop the database"
  93. sqlplus -s -l / as sysdba <<EOF
  94. drop user $DATABASENAME cascade;
  95. EOF
  96. echo "create the database"
  97. sqlplus -s -l / as sysdba <<EOF
  98. create user $DATABASENAME identified by owncloud;
  99. alter user $DATABASENAME default tablespace users
  100. temporary tablespace temp
  101. quota unlimited on users;
  102. grant create session
  103. , create table
  104. , create procedure
  105. , create sequence
  106. , create trigger
  107. , create view
  108. , create synonym
  109. , alter session
  110. to $DATABASENAME;
  111. exit;
  112. EOF
  113. fi
  114. # copy autoconfig
  115. cp $BASEDIR/tests/autoconfig-$1.php $BASEDIR/config/autoconfig.php
  116. # trigger installation
  117. php -f index.php
  118. #test execution
  119. echo "Testing with $1 ..."
  120. cd tests
  121. rm -rf coverage-html-$1
  122. mkdir coverage-html-$1
  123. php -f enable_all.php
  124. if [ "$1" == "sqlite" ] ; then
  125. # coverage only with sqlite - causes segfault on ci.tmit.eu - reason unknown
  126. phpunit --configuration phpunit-autotest.xml --log-junit autotest-results-$1.xml --coverage-clover autotest-clover-$1.xml --coverage-html coverage-html-$1 $2 $3
  127. else
  128. phpunit --configuration phpunit-autotest.xml --log-junit autotest-results-$1.xml $2 $3
  129. fi
  130. }
  131. #
  132. # start test execution
  133. #
  134. if [ -z "$1" ]
  135. then
  136. execute_tests 'sqlite'
  137. execute_tests 'mysql'
  138. execute_tests 'pgsql'
  139. execute_tests 'oci'
  140. else
  141. execute_tests $1 $2 $3
  142. fi
  143. #
  144. # NOTES on mysql:
  145. # - CREATE DATABASE oc_autotest;
  146. # - CREATE USER 'oc_autotest'@'localhost' IDENTIFIED BY 'owncloud';
  147. # - grant all on oc_autotest.* to 'oc_autotest'@'localhost';
  148. #
  149. # - for parallel executor support with EXECUTOR_NUMBER=0:
  150. # - CREATE DATABASE oc_autotest0;
  151. # - CREATE USER 'oc_autotest0'@'localhost' IDENTIFIED BY 'owncloud';
  152. # - grant all on oc_autotest0.* to 'oc_autotest0'@'localhost';
  153. #
  154. # NOTES on pgsql:
  155. # - su - postgres
  156. # - createuser -P oc_autotest (enter password and enable superuser)
  157. # - to enable dropdb I decided to add following line to pg_hba.conf (this is not the safest way but I don't care for the testing machine):
  158. # local all all trust
  159. #
  160. # - for parallel executor support with EXECUTOR_NUMBER=0:
  161. # - createuser -P oc_autotest0 (enter password and enable superuser)
  162. #
  163. # NOTES on oci:
  164. # - it's a pure nightmare to install Oracle on a Linux-System
  165. # - DON'T TRY THIS AT HOME!
  166. # - if you really need it: we feel sorry for you
  167. #