autotest.cmd 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. ::
  2. :: ownCloud
  3. ::
  4. :: @author Thomas Müller
  5. :: @author Tobias Ramforth (translated into Windows batch file)
  6. ::
  7. :: @copyright 2012, 2013 Thomas Müller thomas.mueller@tmit.eu
  8. ::
  9. @echo off
  10. set BASEDIR=%~dp0
  11. set DATADIR=%BASEDIR%data-autotest
  12. :: create autoconfig for sqlite, mysql, postgresql and mssql
  13. echo ^<?php > .\tests\autoconfig-sqlite.php
  14. echo $AUTOCONFIG ^= array ^( >> .\tests\autoconfig-sqlite.php
  15. echo 'installed' ^=^> false^, >> .\tests\autoconfig-sqlite.php
  16. echo 'dbtype' ^=^> 'sqlite'^, >> .\tests\autoconfig-sqlite.php
  17. echo 'dbtableprefix' ^=^> 'oc_'^, >> .\tests\autoconfig-sqlite.php
  18. echo 'adminlogin' ^=^> 'admin'^, >> .\tests\autoconfig-sqlite.php
  19. echo 'adminpass' ^=^> 'admin'^, >> .\tests\autoconfig-sqlite.php
  20. echo 'directory' ^=^> '%DATADIR%'^, >> .\tests\autoconfig-sqlite.php
  21. echo ^)^; >> .\tests\autoconfig-sqlite.php
  22. echo ^<?php > .\tests\autoconfig-mysql.php
  23. echo $AUTOCONFIG ^= array ^( >> .\tests\autoconfig-mysql.php
  24. echo 'installed' ^=^> false^, >> .\tests\autoconfig-mysql.php
  25. echo 'dbtype' ^=^> 'mysql'^, >> .\tests\autoconfig-mysql.php
  26. echo 'dbtableprefix' ^=^> 'oc_'^, >> .\tests\autoconfig-mysql.php
  27. echo 'adminlogin' ^=^> 'admin'^, >> .\tests\autoconfig-mysql.php
  28. echo 'adminpass' ^=^> 'admin'^, >> .\tests\autoconfig-mysql.php
  29. echo 'directory' ^=^> '%DATADIR%'^, >> .\tests\autoconfig-mysql.php
  30. echo 'dbuser' ^=^> 'oc_autotest'^, >> .\tests\autoconfig-mysql.php
  31. echo 'dbname' ^=^> 'oc_autotest'^, >> .\tests\autoconfig-mysql.php
  32. echo 'dbhost' ^=^> 'localhost'^, >> .\tests\autoconfig-mysql.php
  33. echo 'dbpass' ^=^> 'owncloud'^, >> .\tests\autoconfig-mysql.php
  34. echo ^)^; >> .\tests\autoconfig-mysql.php
  35. echo ^<?php > .\tests\autoconfig-pgsql.php
  36. echo $AUTOCONFIG ^= array ^( >> .\tests\autoconfig-pgsql.php
  37. echo 'installed' ^=^> false^, >> .\tests\autoconfig-pgsql.php
  38. echo 'dbtype' ^=^> 'pgsql'^, >> .\tests\autoconfig-pgsql.php
  39. echo 'dbtableprefix' ^=^> 'oc_'^, >> .\tests\autoconfig-pgsql.php
  40. echo 'adminlogin' ^=^> 'admin'^, >> .\tests\autoconfig-pgsql.php
  41. echo 'adminpass' ^=^> 'admin'^, >> .\tests\autoconfig-pgsql.php
  42. echo 'directory' ^=^> '%DATADIR%'^, >> .\tests\autoconfig-pgsql.php
  43. echo 'dbuser' ^=^> 'oc_autotest'^, >> .\tests\autoconfig-pgsql.php
  44. echo 'dbname' ^=^> 'oc_autotest'^, >> .\tests\autoconfig-pgsql.php
  45. echo 'dbhost' ^=^> 'localhost'^, >> .\tests\autoconfig-pgsql.php
  46. echo 'dbpass' ^=^> 'owncloud'^, >> .\tests\autoconfig-pgsql.php
  47. echo ^)^; >> .\tests\autoconfig-pgsql.php
  48. echo ^<?php > .\tests\autoconfig-mssql.php
  49. echo $AUTOCONFIG ^= array ^( >> .\tests\autoconfig-mssql.php
  50. echo 'installed' ^=^> false^, >> .\tests\autoconfig-mssql.php
  51. echo 'dbtype' ^=^> 'mssql'^, >> .\tests\autoconfig-mssql.php
  52. echo 'dbtableprefix' ^=^> 'oc_'^, >> .\tests\autoconfig-mssql.php
  53. echo 'adminlogin' ^=^> 'admin'^, >> .\tests\autoconfig-mssql.php
  54. echo 'adminpass' ^=^> 'admin'^, >> .\tests\autoconfig-mssql.php
  55. echo 'directory' ^=^> '%DATADIR%'^, >> .\tests\autoconfig-mssql.php
  56. echo 'dbuser' ^=^> 'oc_autotest'^, >> .\tests\autoconfig-mssql.php
  57. echo 'dbname' ^=^> 'oc_autotest'^, >> .\tests\autoconfig-mssql.php
  58. echo 'dbhost' ^=^> 'localhost\sqlexpress'^, >> .\tests\autoconfig-mssql.php
  59. echo 'dbpass' ^=^> 'owncloud'^, >> .\tests\autoconfig-mssql.php
  60. echo ^)^; >> .\tests\autoconfig-mssql.php
  61. echo localhost:5432:*:oc_autotest:owncloud > %APPDATA%\postgresql\pgpass.conf
  62. @echo on
  63. :: Back up existing (dev) config if one exists
  64. if exist config\config.php (
  65. copy /y config\config.php config\config-autotest-backup.php
  66. )
  67. ::
  68. :: start test execution
  69. ::
  70. if [%1] == [] (
  71. @echo "Running on all database backends"
  72. call:execute_tests "sqlite" "%2"
  73. call:execute_tests "mysql" "%2"
  74. call:execute_tests "mssql" "%2"
  75. ::call:execute_tests "ora" "%2"
  76. call:execute_tests "pgsql" "%2"
  77. ) else (
  78. call:execute_tests "%1" "%2"
  79. )
  80. goto:restore_config
  81. goto:eof
  82. :restore_config
  83. :: Restore existing config
  84. if exist config\config-autotest-backup.php (
  85. copy /y config\config-autotest-backup.php config\config.php
  86. )
  87. goto:eof
  88. :execute_tests
  89. @echo "Setup environment for %~1 testing ..."
  90. :: back to root folder
  91. cd %BASEDIR%
  92. :: revert changes to tests\data
  93. git checkout tests\data\*
  94. :: reset data directory
  95. rmdir /s /q %DATADIR%
  96. md %DATADIR%
  97. :: remove the old config file
  98. :: del /q /f config\config.php
  99. copy /y tests\preseed-config.php config\config.php
  100. :: drop database
  101. if "%~1" == "mysql" mysql -u oc_autotest -powncloud -e "DROP DATABASE oc_autotest"
  102. if "%~1" == "pgsql" dropdb -h localhost -p 5432 -U oc_autotest -w oc_autotest
  103. :: we assume a sqlexpress installation
  104. if "%~1" == "mssql" sqlcmd -S localhost\sqlexpress -U oc_autotest -P owncloud -Q "IF EXISTS (SELECT name FROM sys.databases WHERE name=N'oc_autotest') DROP DATABASE [oc_autotest]"
  105. :: copy autoconfig
  106. copy /y %BASEDIR%\tests\autoconfig-%~1.php %BASEDIR%\config\autoconfig.php
  107. :: trigger installation
  108. @echo INDEX
  109. call php -f index.php
  110. @echo END INDEX
  111. ::test execution
  112. @echo "Testing with %~1 ..."
  113. cd tests
  114. rmdir /s /q coverage-html-%~1
  115. md coverage-html-%~1
  116. php -f enable_all.php
  117. :: no external files on windows for now
  118. cd ..
  119. php occ app:disable files_external
  120. cd tests
  121. call phpunit --bootstrap bootstrap.php --configuration phpunit-autotest.xml --log-junit autotest-results-%~1.xml --coverage-clover autotest-clover-%~1.xml --coverage-html coverage-html-%~1 %~2
  122. @echo "Done with testing %~1 ..."
  123. cd %BASEDIR%
  124. goto:eof
  125. ::
  126. :: NOTES on mysql:
  127. :: - CREATE USER 'oc_autotest'@'localhost' IDENTIFIED BY 'owncloud';
  128. :: - grant access permissions: grant all on oc_autotest.* to 'oc_autotest'@'localhost';
  129. ::
  130. :: NOTES on pgsql:
  131. :: - su - postgres
  132. :: - createuser -P (enter username and password and enable superuser)
  133. :: - 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):
  134. :: local all all trust
  135. ::
  136. :: NOTES on mssql:
  137. :: we assume the usage of a local installed sqlexpress
  138. :: create a user 'oc_autotest' with password 'owncloud' and assign the server role 'dbcreator'
  139. :: make sure the sqlserver is configured to allow sql authentication
  140. ::