diff --git a/Makefile b/Makefile index 096ac60cb4966f103f179471119cbc28f2cb7640..7d4898d01058e2ec06437049489ded2b6390416e 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,6 @@ all: + @echo "Run 'make initcomposer' to install Composer and phpunit" + @echo "Run 'make phpunit' to execute phpunit tests" @echo "Run 'make imageoptim' to losslessly optimise all images" @echo "Run 'make minaccept' to run the quick pre-commit tests" @echo "Run 'make checksignoff' to check that your commits are all Signed-off-by" @@ -10,15 +12,45 @@ imageoptim: find . -iname '*.jpg' -exec jpegoptim -q -p --strip-all {} \; find . -iname '*.jpeg' -exec jpegoptim -q -p --strip-all {} \; +composer := $(shell ls external/composer.phar 2>/dev/null) + +initcomposer: +ifdef composer + @echo "Updating Composer..." + @php external/composer.phar --working-dir=external update +else + @echo "Installing Composer..." + @curl -sS https://getcomposer.org/installer | php -- --install-dir=external + @php external/composer.phar --working-dir=external install +endif + +vendorphpunit := $(shell external/vendor/bin/phpunit --version 2>/dev/null) + +phpunit: + @echo "Running phpunit tests..." +ifdef vendorphpunit + @external/vendor/bin/phpunit --log-junit logs/tests/phpunit-results.xml htdocs/ +else + @phpunit --log-junit logs/tests/phpunit-results.xml htdocs/ +endif + + +revision := $(shell git rev-parse --verify HEAD 2>/dev/null) +whitelist := $(shell grep / test/WHITELIST | xargs -I entry find entry -type f | xargs -I file echo '! -path ' file 2>/dev/null) + minaccept: @echo "Running minimum acceptance test..." - @find htdocs/ -type f -name "*.php" | xargs -n 1 -P 2 php -l > /dev/null && echo All good! +ifdef revision + @find htdocs -type f -name "*.php" -print0 | xargs -0 -n 1 -P 2 php -l > /dev/null && echo All good! @php test/versioncheck.php - @find htdocs/ -type f -name "install.xml" -path "*/db/install.xml" | xargs -n 1 -P 2 xmllint --schema htdocs/lib/xmldb/xmldb.xsd --noout - @if git rev-parse --verify HEAD 2>/dev/null; then git show HEAD ; fi | test/coding-standard-check.pl + @find htdocs -type f -name "install.xml" -path "*/db/install.xml" -print0 | xargs -0 -n 1 -P 2 xmllint --schema htdocs/lib/xmldb/xmldb.xsd --noout + @git diff-tree --diff-filter=ACMR --no-commit-id --name-only -r $(revision) | xargs -I {} find {} $(whitelist) | xargs -I list git show $(revision) list | test/coding-standard-check.pl +else + @echo "No revision found!" +endif jenkinsaccept: minaccept - @find ./ ! -path './.git/*' -type f | xargs clamscan > /dev/null && echo All good! + @find ./ ! -path './.git/*' -type f -print0 | xargs -0 clamscan > /dev/null && echo All good! sshargs := $(shell git config --get remote.gerrit.url | sed -re 's~^ssh://([^@]*)@([^:]*):([0-9]*)/mahara~-p \3 -l \1 \2~') mergebase := $(shell git fetch gerrit >/dev/null 2>&1 && git merge-base HEAD gerrit/master) diff --git a/external/composer.json b/external/composer.json index fdddbec5a0e9752a06fa147190e94a024d137580..c81df40783045ad1a18553b6a9ccad3e9b1f569a 100644 --- a/external/composer.json +++ b/external/composer.json @@ -12,6 +12,10 @@ "fabpot/goutte": "~1.0" }, + "require-dev": { + "phpunit/phpunit": "3.7.*" + }, + "minimum-stability": "dev" } diff --git a/htdocs/lib/errors.php b/htdocs/lib/errors.php index 6d084a2bf7cd80f62924357e8000f55b7be1f514..f71e0a661803c504560e400a0fd354a46475ed25 100644 --- a/htdocs/lib/errors.php +++ b/htdocs/lib/errors.php @@ -53,8 +53,10 @@ define('DEVMODE_UNPACKEDJS', 8); // later in init.php after we've loaded config.php $errorlevel = E_ALL & ~E_STRICT; error_reporting($errorlevel); -set_error_handler('error', $errorlevel); -set_exception_handler('exception'); +if (!defined('TESTSRUNNING')) { + set_error_handler('error', $errorlevel); + set_exception_handler('exception'); +} // Logging functions diff --git a/htdocs/lib/tests/phpunit/README b/htdocs/lib/tests/phpunit/README index 6facd73648b037c33dfa8bea8072ea32f797bdb0..1b90620ddd82a5f9e4631fda1055239f98baf84d 100644 --- a/htdocs/lib/tests/phpunit/README +++ b/htdocs/lib/tests/phpunit/README @@ -1,12 +1,9 @@ -This requires phpunit 3.3 or later. +This requires phpunit 3.7 or later which is installed by running: -It needs to be run like: +make initcomposer -php -c /etc/php5/apache2/php.ini /usr/bin/phpunit . - -Or if you've configured your cli php.ini properly, you can just do - -phpunit . +Unit tests can be run by: +make phpunit From the main directory of mahara (eg, outside htdocs) diff --git a/htdocs/lib/tests/phpunit/bootstrap.php b/htdocs/lib/tests/phpunit/bootstrap.php index 2b4e32c382e841c7fd01fee20ed8dcbdc02af78b..2327088b3ba07cebcae21839bbc2977551155714 100644 --- a/htdocs/lib/tests/phpunit/bootstrap.php +++ b/htdocs/lib/tests/phpunit/bootstrap.php @@ -16,13 +16,17 @@ define('PUBLIC', 1); // necessary since we're running in a limited scope global $CFG, $db, $SESSION, $USER, $THEME; -ob_start(); require(dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php'); -ob_end_clean(); require_once(get_config('libroot') . 'ddl.php'); require_once(get_config('libroot') . 'upgrade.php'); require_once(get_config('libroot') . 'phpunit.php'); +error_reporting(E_ALL & ~E_STRICT); +ini_set('display_errors', '1'); +ini_set('log_errors', '1'); +restore_error_handler(); +restore_exception_handler(); + $bootstrap = new UnitTestBootstrap(); $bootstrap->jimmy_config(); diff --git a/htdocs/webservice/test/tests/RunAllTests.php b/htdocs/webservice/test/tests/RunAllTests.php deleted file mode 100644 index a31f222f639649b9f6123882e5b1742bd0fa606b..0000000000000000000000000000000000000000 --- a/htdocs/webservice/test/tests/RunAllTests.php +++ /dev/null @@ -1,37 +0,0 @@ -addTestSuite($parts[0]); - } - return $suite; - } -} diff --git a/htdocs/webservice/test/tests/run_all_tests.sh b/htdocs/webservice/test/tests/run_all_tests.sh deleted file mode 100755 index 0c9dcad07e4f9b35bdad0aa8c5058b271e906102..0000000000000000000000000000000000000000 --- a/htdocs/webservice/test/tests/run_all_tests.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh - -# Test the different web service protocols. -# -# @package mahara -# @subpackage auth-webservice -# @author Catalyst IT Ltd -# @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later -# @copyright For copyright information on Mahara, please see the README file distributed with this software. -# - -# Example of running ALL the phpunit tests - -# protect against execution -if [ -n "$GATEWAY_INTERFACE" ]; then - echo "Content-type: text/html" - echo "" - echo "ERROR

ERROR

" - exit 0 -fi - -sudo -u www-data phpunit "RunAllTests" - diff --git a/htdocs/webservice/test/README b/htdocs/webservice/tests/README similarity index 56% rename from htdocs/webservice/test/README rename to htdocs/webservice/tests/README index 8f8cbaca9d21d30a695a196c459ee3a1a24f4399..bd64925a6fbe1dceaead9aa9c8bb67fecbf2624f 100644 --- a/htdocs/webservice/test/README +++ b/htdocs/webservice/tests/README @@ -1,23 +1,6 @@ -PHPUnit Tests, and example clients for Mahara Web Services +Example clients for Mahara Web Services ========================================================== -Tests -===== - -The test directory contains PHP Unit tests for Web Services. - -To run all of these you need to change the the tests/ directory, - switch to the web server user and run: - -phpunit RunAllTests - -An easy way to do this with Linux is: - -sudo -u www-data phpunit "RunAllTests" - -Example Clients -=============== - The example clients are a to demonstrate the usage of the User, Group, and Institution APIs. diff --git a/htdocs/webservice/test/exampleclients/example_group_api.php b/htdocs/webservice/tests/exampleclients/example_group_api.php similarity index 100% rename from htdocs/webservice/test/exampleclients/example_group_api.php rename to htdocs/webservice/tests/exampleclients/example_group_api.php diff --git a/htdocs/webservice/test/exampleclients/example_institution_api.php b/htdocs/webservice/tests/exampleclients/example_institution_api.php similarity index 100% rename from htdocs/webservice/test/exampleclients/example_institution_api.php rename to htdocs/webservice/tests/exampleclients/example_institution_api.php diff --git a/htdocs/webservice/test/exampleclients/example_user_api.php b/htdocs/webservice/tests/exampleclients/example_user_api.php similarity index 100% rename from htdocs/webservice/test/exampleclients/example_user_api.php rename to htdocs/webservice/tests/exampleclients/example_user_api.php diff --git a/htdocs/webservice/test/exampleclients/lib/example_api_base.php b/htdocs/webservice/tests/exampleclients/lib/example_api_base.php similarity index 99% rename from htdocs/webservice/test/exampleclients/lib/example_api_base.php rename to htdocs/webservice/tests/exampleclients/lib/example_api_base.php index 1b5f34e69d8671e105aadc84cac67aa2df2db6e8..c0e578673666f603e2a4032ca5ec326510193a67 100644 --- a/htdocs/webservice/test/exampleclients/lib/example_api_base.php +++ b/htdocs/webservice/tests/exampleclients/lib/example_api_base.php @@ -195,7 +195,8 @@ while (1) { try { $result = $client->call($function, $functions[$function]); print "Results are: " . var_export($result, true) . "\n"; - } catch (Exception $e) { + } + catch (Exception $e) { print "exception: " . var_export($e, true) . "\n"; } } diff --git a/htdocs/webservice/test/exampleclients/lib/example_test_data_group.php b/htdocs/webservice/tests/exampleclients/lib/example_test_data_group.php similarity index 100% rename from htdocs/webservice/test/exampleclients/lib/example_test_data_group.php rename to htdocs/webservice/tests/exampleclients/lib/example_test_data_group.php diff --git a/htdocs/webservice/test/exampleclients/lib/example_test_data_institution.php b/htdocs/webservice/tests/exampleclients/lib/example_test_data_institution.php similarity index 100% rename from htdocs/webservice/test/exampleclients/lib/example_test_data_institution.php rename to htdocs/webservice/tests/exampleclients/lib/example_test_data_institution.php diff --git a/htdocs/webservice/test/exampleclients/lib/example_test_data_user.php b/htdocs/webservice/tests/exampleclients/lib/example_test_data_user.php similarity index 100% rename from htdocs/webservice/test/exampleclients/lib/example_test_data_user.php rename to htdocs/webservice/tests/exampleclients/lib/example_test_data_user.php diff --git a/htdocs/webservice/test/exampleclients/lib/wsse_soap_client.php b/htdocs/webservice/tests/exampleclients/lib/wsse_soap_client.php similarity index 100% rename from htdocs/webservice/test/exampleclients/lib/wsse_soap_client.php rename to htdocs/webservice/tests/exampleclients/lib/wsse_soap_client.php diff --git a/htdocs/webservice/test/exampleclients/run_examples.sh b/htdocs/webservice/tests/exampleclients/run_examples.sh similarity index 100% rename from htdocs/webservice/test/exampleclients/run_examples.sh rename to htdocs/webservice/tests/exampleclients/run_examples.sh diff --git a/htdocs/webservice/test/tests/WebServiceGroupTest.php b/htdocs/webservice/tests/phpunit/WebServiceGroupTest.php similarity index 99% rename from htdocs/webservice/test/tests/WebServiceGroupTest.php rename to htdocs/webservice/tests/phpunit/WebServiceGroupTest.php index 98dd20b4fb0c532b9e888337a0968fce7849a775..fc218fdb73506a42aa4f5e5b0a18631431b52003 100644 --- a/htdocs/webservice/test/tests/WebServiceGroupTest.php +++ b/htdocs/webservice/tests/phpunit/WebServiceGroupTest.php @@ -11,12 +11,12 @@ * */ -require_once 'TestBase.class.php'; +require_once('WebServiceTestBase.class.php'); /** * functional tests for Groups */ -class WebServiceGroupTest extends TestBase { +class WebServiceGroupTest extends WebServiceTestBase { /** * local setup - outline the test functions in the framework diff --git a/htdocs/webservice/test/tests/WebServiceInstitutionTest.php b/htdocs/webservice/tests/phpunit/WebServiceInstitutionTest.php similarity index 98% rename from htdocs/webservice/test/tests/WebServiceInstitutionTest.php rename to htdocs/webservice/tests/phpunit/WebServiceInstitutionTest.php index 22c4a2d09520bf652efdbefaa4111fdaf7615df6..e06ae4c6cf100172f8c43f6a2868a81f7a6d9ff8 100644 --- a/htdocs/webservice/test/tests/WebServiceInstitutionTest.php +++ b/htdocs/webservice/tests/phpunit/WebServiceInstitutionTest.php @@ -11,12 +11,12 @@ * */ -require_once 'TestBase.class.php'; +require_once('WebServiceTestBase.class.php'); /** * functional tests for institutions */ -class WebServiceInstitutionTest extends TestBase { +class WebServiceInstitutionTest extends WebServiceTestBase { /** * local setup - outline the test functions in the framework diff --git a/htdocs/webservice/test/tests/TestBase.class.php b/htdocs/webservice/tests/phpunit/WebServiceTestBase.class.php similarity index 97% rename from htdocs/webservice/test/tests/TestBase.class.php rename to htdocs/webservice/tests/phpunit/WebServiceTestBase.class.php index 2a5ca0b645ef39bd361676fb08ebe5615039f8ce..60e1de8051b8bc046e7503100e4dfb239a854b26 100644 --- a/htdocs/webservice/test/tests/TestBase.class.php +++ b/htdocs/webservice/tests/phpunit/WebServiceTestBase.class.php @@ -10,27 +10,12 @@ * */ -// disable the WSDL cache -ini_set("soap.wsdl_cache_enabled", "0"); - -// must be run from the command line -if (isset($_SERVER['REMOTE_ADDR']) || isset($_SERVER['GATEWAY_INTERFACE'])) { - die('Direct access to this script is forbidden.'); -} // disable the WSDL cache ini_set("soap.wsdl_cache_enabled", "0"); -define('TESTSRUNNING', 1); -define('INTERNAL', 1); -define('PUBLIC', 1); - -// necessary since we're running in a limited scope -global $CFG, $db, $SESSION, $USER, $THEME; -require(dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php'); require_once(get_config('libroot') . 'ddl.php'); require_once(get_config('libroot') . 'upgrade.php'); -require_once(get_config('libroot') . 'phpunit.php'); $path = get_config('docroot') . 'lib/zend'; set_include_path($path . PATH_SEPARATOR . get_include_path()); @@ -66,7 +51,7 @@ require_once('group.php'); * Also, the testRun framework that runs the list of tests in each specific class * against all the protocols and auth methods */ -class TestBase extends PHPUnit_Framework_TestCase { +class WebServiceTestBase extends MaharaUnitTest { public $testtoken; public $testrest; diff --git a/htdocs/webservice/test/tests/WebServiceUserTest.php b/htdocs/webservice/tests/phpunit/WebServiceUserTest.php similarity index 99% rename from htdocs/webservice/test/tests/WebServiceUserTest.php rename to htdocs/webservice/tests/phpunit/WebServiceUserTest.php index e31ba16313b296fdba288fc4c3c9e834a8b37890..ba2cea04a8bd90354d1955010ce28657c71dc07f 100644 --- a/htdocs/webservice/test/tests/WebServiceUserTest.php +++ b/htdocs/webservice/tests/phpunit/WebServiceUserTest.php @@ -11,12 +11,12 @@ * */ -require_once 'TestBase.class.php'; +require_once('WebServiceTestBase.class.php'); /** * funcitonal tests for user API */ -class WebServiceUserTest extends TestBase { +class WebServiceUserTest extends WebServiceTestBase { /** * local setup - outline the test functions in the framework diff --git a/phpunit.xml b/phpunit.xml index 697deeff97a59c89633e7818e6fa84644fa2cffc..c3489ef01bf5b3339d79d5269d45a747c4991769 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,9 +1,14 @@ - + htdocs diff --git a/test/WHITELIST b/test/WHITELIST new file mode 100644 index 0000000000000000000000000000000000000000..a81f005a06302d5f5c943aba58a9c5f60a479a28 --- /dev/null +++ b/test/WHITELIST @@ -0,0 +1,3 @@ +htdocs/lib/mobile_detect/Mobile_Detect.php +htdocs/lib/pear +htdocs/lib/dwoo/dwoo \ No newline at end of file