http://www.mediawiki.org/wiki/Special:Code/MediaWiki/100208
Revision: 100208 Author: jpostlethwaite Date: 2011-10-19 03:18:57 +0000 (Wed, 19 Oct 2011) Log Message: ----------- Implementing unit testing and code coverage with Bank Transfers. Modified Paths: -------------- branches/fundraising/extensions/DonationInterface/tests/Adapter/GlobalCollect/BankTransferTestCase.php branches/fundraising/extensions/DonationInterface/tests/TestHelper.php Added Paths: ----------- branches/fundraising/extensions/DonationInterface/tests/logs/ branches/fundraising/extensions/DonationInterface/tests/logs/coverage/ branches/fundraising/extensions/DonationInterface/tests/logs/coverage/clover/ branches/fundraising/extensions/DonationInterface/tests/logs/coverage/html/ branches/fundraising/extensions/DonationInterface/tests/macros/ branches/fundraising/extensions/DonationInterface/tests/macros/form.twostepamount.banktransfer.spain.htm branches/fundraising/extensions/DonationInterface/tests/phpunit.xml branches/fundraising/extensions/DonationInterface/tests/unittest.conf.dist branches/fundraising/extensions/DonationInterface/tests/unittest.sh Modified: branches/fundraising/extensions/DonationInterface/tests/Adapter/GlobalCollect/BankTransferTestCase.php =================================================================== --- branches/fundraising/extensions/DonationInterface/tests/Adapter/GlobalCollect/BankTransferTestCase.php 2011-10-19 03:11:09 UTC (rev 100207) +++ branches/fundraising/extensions/DonationInterface/tests/Adapter/GlobalCollect/BankTransferTestCase.php 2011-10-19 03:18:57 UTC (rev 100208) @@ -62,27 +62,97 @@ IBAN CountryDescription Notes - We do not need to have donor information stored on our side yet as long as it is sent to Global Collect + We do not need to have donor information stored on our side yet as long as it is sent to Global Collect */ /** - * Copied from Katie's test code + * testbuildRequestXML + * + * @todo + * - there are many cases to this that need to be developed. + * - Do not consider this a complete test! + * + * @covers GatewayAdapter::__construct + * @covers GatewayAdapter::do_transaction + * @covers GatewayAdapter::buildRequestXML + * @covers GatewayAdapter::getData */ public function testbuildRequestXML() { - $this->markTestIncomplete( TESTS_MESSAGE_NOT_IMPLEMENTED ); + global $wgGlobalCollectGatewayTest; + global $wgRequest; + + $wgGlobalCollectGatewayTest = true; - return; + $_SERVER = array(); - $gateway = new TestAdapter(); - $gateway->publicCurrentTransaction( 'Test1' ); - $built = $gateway->buildRequestXML(); - $expected = '<?xml version="1.0"?>' . "\n"; - $expected .= '<XML><REQUEST><ACTION>Donate</ACTION><ACCOUNT><MERCHANTID>128</MERCHANTID><PASSWORD>k4ftw</PASSWORD><VERSION>3.2</VERSION><RETURNURL>http://' . TESTS_HOSTNAME . '/index.php/Donate-thanks/en</RETURNURL></ACCOUNT><DONATION><DONOR>Tester Testington</DONOR><AMOUNT>35000</AMOUNT><CURRENCYCODE>USD</CURRENCYCODE><LANGUAGECODE>en</LANGUAGECODE><COUNTRYCODE>US</COUNTRYCODE></DONATION></REQUEST></XML>' . "\n"; - $this->assertEquals($built, $expected, "The constructed XML for transaction type Test1 does not match our expected."); + $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; + $_SERVER['HTTP_HOST'] = TESTS_HOSTNAME; + $_SERVER['SERVER_NAME'] = TESTS_HOSTNAME; + $_SERVER['REQUEST_URI'] = '/index.php/Special:GlobalCollectGateway?form_name=TwoStepAmount'; + + + $options = array(); + $options['test'] = true; + $transactionType = 'BANK_TRANSFER'; + + $amount = 350; + + $options['postDefaults'] = array( + 'returnTitle' => true, + 'returnTo' => 'http://' . TESTS_HOSTNAME . '/index.php/Special:GlobalCollectGatewayResult', + ); + + $options['testData'] = array( + 'amount' => $amount, + 'transaction_type' => $transactionType, + 'email' => TESTS_EMAIL, + 'fname' => 'Testy', + 'lname' => 'Testerton', + 'street' => '123 Happy Street', + 'city' => 'Barcelona', + 'state' => 'XX', + 'zip' => '', + 'country' => 'ES', + //'size' => 'small', + 'currency' => 'EUR', + 'payment_method' => '', + //'order_id' => '5038287830', + //'i_order_id' => '1234567890', + 'numAttempt' => 0, + 'referrer' => 'http://' . TESTS_HOSTNAME . '/index.php/Special:GlobalCollectGateway?form_name=TwoStepAmount', + 'utm_source' => '..gc_bt', + 'utm_medium' => null, + 'utm_campaign' => null, + 'language' => 'en', + 'comment-option' => '', + 'comment' => '', + 'email-opt' => 1, + 'test_string' => '', + 'token' => '', + 'contribution_tracking_id' => '', + 'data_hash' => '', + 'action' => '', + 'gateway' => 'globalcollect', + 'owa_session' => '', + 'owa_ref' => 'http://localhost/defaultTestData', + 'transaction_type' => '', // Used by GlobalCollect for payment types + ); + + $gateway = new GlobalCollectAdapter( $options ); + + $result = $gateway->do_transaction( $transactionType ); + + $request = trim( $gateway->buildRequestXML() ); + + $orderId = $gateway->getData( 'order_id' ); + + $expected = '<?xml version="1.0"?>' . "\n"; + $expected .= '<XML><REQUEST><ACTION>INSERT_ORDERWITHPAYMENT</ACTION><META><MERCHANTID>6570</MERCHANTID><VERSION>1.0</VERSION></META><PARAMS><ORDER><ORDERID>' . $orderId . '</ORDERID><AMOUNT>' . $amount * 100 . '</AMOUNT><CURRENCYCODE>EUR</CURRENCYCODE><LANGUAGECODE>en</LANGUAGECODE><COUNTRYCODE>ES</COUNTRYCODE><MERCHANTREFERENCE>' . $orderId . '</MERCHANTREFERENCE></ORDER><PAYMENT><PAYMENTPRODUCTID>11</PAYMENTPRODUCTID><AMOUNT>35000</AMOUNT><CURRENCYCODE>EUR</CURRENCYCODE><LANGUAGECODE>en</LANGUAGECODE><COUNTRYCODE>ES</COUNTRYCODE><HOSTEDINDICATOR>1</HOSTEDINDICATOR><RETURNURL>http://wikimedia-fundraising-1.17.localhost.wikimedia.org/index.php/Special:GlobalCollectGatewayResult?order_id=' . $orderId . '</RETURNURL><FIRSTNAME>Testy</FIRSTNAME><SURNAME>Testerton</SURNAME><STREET>123 Happy Street</STREET><CITY>Barcelona</CITY><STATE>XX</STATE><EMAIL>jpostlethwa...@wikimedia.org</EMAIL></PAYMENT></PARAMS></REQUEST></XML>'; + //$expected .= '<XML><REQUEST><ACTION>Donate</ACTION><ACCOUNT><MERCHANTID>128</MERCHANTID><PASSWORD>k4ftw</PASSWORD><VERSION>3.2</VERSION><RETURNURL>http://' . TESTS_HOSTNAME . '/index.php/Donate-thanks/en</RETURNURL></ACCOUNT><DONATION><DONOR>Tester Testington</DONOR><AMOUNT>35000</AMOUNT><CURRENCYCODE>USD</CURRENCYCODE><LANGUAGECODE>en</LANGUAGECODE><COUNTRYCODE>US</COUNTRYCODE></DONATION></REQUEST></XML>' . "\n"; + $this->assertEquals($request, $expected, 'The constructed XML for transaction type [' . $transactionType . '] does not match our expected.'); } - /** * testRequestHasRequiredFields @@ -110,8 +180,8 @@ public function testSendToGlobalCollect() { $this->markTestIncomplete( TESTS_MESSAGE_NOT_IMPLEMENTED ); - //global $wgContLang, $wgAuth, $wgMemc, $wgRequest, $wgUser, $wgServer; global $wgGlobalCollectGatewayTest; + global $wgRequest; $wgGlobalCollectGatewayTest = true; @@ -121,51 +191,35 @@ $_SERVER['HTTP_HOST'] = TESTS_HOSTNAME; $_SERVER['SERVER_NAME'] = TESTS_HOSTNAME; $_SERVER['REQUEST_URI'] = '/index.php/Special:GlobalCollectGateway?form_name=TwoStepAmount'; - - /** - * @see WebStart.php - */ - require_once TESTS_WEB_ROOT . '/includes/WebStart.php'; $options = array(); $options['test'] = true; - $options['transactionType'] = 'BANK_TRANSFER'; + $transactionType = 'BANK_TRANSFER'; $options['postDefaults'] = array( 'returnTitle' => true, 'returnTo' => 'http://' . TESTS_HOSTNAME . '/index.php/Special:GlobalCollectGatewayResult', ); + + $amount = 350; $options['testData'] = array( - 'amount' => "35", - 'amountOther' => '', - 'email' => 't...@example.com', - 'fname' => 'Tester', - 'mname' => 'T.', - 'lname' => 'Testington', - 'street' => '548 Market St.', - 'city' => 'San Francisco', - 'state' => 'CA', - 'zip' => '94104', - 'country' => 'US', - 'fname2' => 'Testy', - 'lname2' => 'Testerson', - 'street2' => '123 Telegraph Ave.', - 'city2' => 'Berkeley', - 'state2' => 'CA', - 'zip2' => '94703', - 'country2' => 'US', - 'size' => 'small', - 'premium_language' => 'es', - //'card_num' => TESTS_CREDIT_CARDS_AMEREICAN_EXPRESS_VALID_CARD, - //'card_type' => 'american', - //'expiration' => date( 'my', strtotime( '+1 year 1 month' ) ), - //'cvv' => '001', - 'currency' => 'USD', + 'amount' => $amount, + 'transaction_type' => $transactionType, + 'email' => TESTS_EMAIL, + 'fname' => 'Testy', + 'lname' => 'Testerton', + 'street' => '123 Happy Street', + 'city' => 'Barcelona', + 'state' => 'XX', + 'zip' => '', + 'country' => 'ES', + //'size' => 'small', + 'currency' => 'EUR', 'payment_method' => '', - 'order_id' => '1234567890', - 'i_order_id' => '1234567890', + //'order_id' => '5038287830', + //'i_order_id' => '1234567890', 'numAttempt' => 0, 'referrer' => 'http://' . TESTS_HOSTNAME . '/index.php/Special:GlobalCollectGateway?form_name=TwoStepAmount', 'utm_source' => '..gc_bt', @@ -187,7 +241,9 @@ ); $gateway = new GlobalCollectAdapter( $options ); - return $gateway->do_transaction( $options['transactionType'] ); + $result = $gateway->do_transaction( $transactionType ); + + $this->assertTrue( $result ); } } Modified: branches/fundraising/extensions/DonationInterface/tests/TestHelper.php =================================================================== --- branches/fundraising/extensions/DonationInterface/tests/TestHelper.php 2011-10-19 03:11:09 UTC (rev 100207) +++ branches/fundraising/extensions/DonationInterface/tests/TestHelper.php 2011-10-19 03:18:57 UTC (rev 100208) @@ -37,7 +37,22 @@ */ error_reporting( E_ALL | E_STRICT ); +/** + * TESTS_WEB_ROOT + * + * This is similar to $IP, the installation path in Mediawiki. + */ +define( 'TESTS_WEB_ROOT', dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) ); +$IP = TESTS_WEB_ROOT; + +/* + * Required files for unit testing. + */ +require_once( TESTS_WEB_ROOT . '/includes/SpecialPage.php' ); +require_once( TESTS_WEB_ROOT . '/includes/Title.php' ); +require_once( TESTS_WEB_ROOT . '/includes/Exception.php' ); + /** * @see DonationData */ @@ -49,6 +64,16 @@ require_once dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'gateway_common/gateway.adapter.php'; /** + * @see GatewayForm + */ +require_once dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'gateway_common/GatewayForm.php'; + +/** + * @see extras/extras.body.php + */ +require_once dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'extras/extras.body.php'; + +/** * @see GlobalCollectAdapter */ require_once dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'globalcollect_gateway/globalcollect.adapter.php'; @@ -58,19 +83,52 @@ */ require_once dirname( dirname( dirname( __FILE__ ) ) ) . DIRECTORY_SEPARATOR . 'ContributionTracking/ContributionTracking.processor.php'; + +if ( !defined( 'MEDIAWIKI' ) ) { + define( 'MEDIAWIKI', 1 ); +} + +/* + * Unit tests are run from the command line. + * + * It should be confirmed that this will not affect other tests such as Selenium. + */ +//$wgCommandLineMode = true; +//$wgCanonicalServer = true; + /** - * TESTS_WEB_ROOT + * Initializing the global $_SERVER for unit testing. This array does not exist + * on the CLI. * - * This is similar to $IP, the installation path in Mediawiki. + * You may customize this variable in TestConfiguration.php. + * + * @todo + * - make this default more general and customizable. + * + * @var array $_SERVER */ -define( 'TESTS_WEB_ROOT', dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) ); +$_SERVER = array ( 'HTTP_HOST' => 'localhost', 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:7.0.1) Gecko/20100101 Firefox/7.0.1', 'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5', 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate', 'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'HTTP_CONNECTION' => 'keep-alive', 'HTTP_COOKIE' => 'mediawiki_fundraising_117_session=f2rc8vv6av1o324qodvinqlpi1', 'HTTP_IF_MODIFIED_SINCE' => 'Fri, 14 Oct 2011 20:18:45 GMT', 'PATH' => '/usr/bin:/bin:/usr/sbin:/sbin', 'SERVER_SIGNATURE' => ' +Apache/2.2.19 (Unix) DAV/2 PHP/5.3.7 Server at localhost Port 80 +', 'SERVER_SOFTWARE' => 'Apache/2.2.19 (Unix) DAV/2 PHP/5.3.7', 'SERVER_NAME' => 'localhost', 'SERVER_ADDR' => '127.0.0.1', 'SERVER_PORT' => '80', 'REMOTE_ADDR' => '127.0.0.1', 'DOCUMENT_ROOT' => '/dev/null', 'SERVER_ADMIN' => 'no-re...@example.org', 'SCRIPT_FILENAME' => '/dev/null/index.php', 'REMOTE_PORT' => '62747', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'REQUEST_METHOD' => 'GET', 'QUERY_STRING' => '', 'REQUEST_URI' => '/', 'SCRIPT_NAME' => '/index.php', 'PHP_SELF' => '/index.php', 'REQUEST_TIME' => 1318890010, ); +// Initialize session for unit testing +$_SESSION = isset( $_SESSION ) ? $_SESSION : array(); + /* - * Unit tests are run from the command line. + * Required files for unit testing. * - * It should be confirmed that this will not affect other tests such as Selenium. + * These files need to be required after the above code. Do not move. */ -$wgCommandLineMode = true; +require_once( TESTS_WEB_ROOT . '/includes/Defines.php' ); +require_once( TESTS_WEB_ROOT . '/LocalSettings.php' ); +require_once( TESTS_WEB_ROOT . '/includes/WebRequest.php' ); +require_once( TESTS_WEB_ROOT . '/includes/GlobalFunctions.php' ); +require_once( TESTS_WEB_ROOT . '/includes/HttpFunctions.php' ); +require_once( TESTS_WEB_ROOT . '/includes/db/Database.php' ); +require_once( TESTS_WEB_ROOT . '/includes/db/DatabaseMysql.php' ); +require_once( TESTS_WEB_ROOT . '/includes/Profiler.php' ); +$request = $_SERVER; +$wgRequest = new FauxRequest( $request ); /* * Load the user-defined test configuration file, if it exists; otherwise, load @@ -82,3 +140,11 @@ require_once 'TestConfiguration.php.dist'; } +/* + * Customize the server variable options. + */ +$_SERVER['HTTP_HOST'] = TESTS_HOSTNAME; +$_SERVER['SERVER_NAME'] = TESTS_HOSTNAME; +$_SERVER['SERVER_NAME'] = TESTS_WEB_ROOT; +$_SERVER['SERVER_ADMIN'] = TESTS_EMAIL; + Property changes on: branches/fundraising/extensions/DonationInterface/tests/logs/coverage/clover ___________________________________________________________________ Added: svn:ignore + * Property changes on: branches/fundraising/extensions/DonationInterface/tests/logs/coverage/html ___________________________________________________________________ Added: svn:ignore + * Added: branches/fundraising/extensions/DonationInterface/tests/macros/form.twostepamount.banktransfer.spain.htm =================================================================== --- branches/fundraising/extensions/DonationInterface/tests/macros/form.twostepamount.banktransfer.spain.htm (rev 0) +++ branches/fundraising/extensions/DonationInterface/tests/macros/form.twostepamount.banktransfer.spain.htm 2011-10-19 03:18:57 UTC (rev 100208) @@ -0,0 +1,71 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head profile="http://selenium-ide.openqa.org/profiles/test-case"> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> +<link rel="selenium.base" href="http://wikimedia-fundraising-1.17.localhost.wikimedia.org/" /> +<title>form.twostepamount.banktransfer</title> +</head> +<body> +<table cellpadding="1" cellspacing="1" border="1"> +<thead> +<tr><td rowspan="1" colspan="3">form.twostepamount.banktransfer</td></tr> +</thead><tbody> +<tr> + <td>open</td> + <td>/index.php/Special:GlobalCollectGateway?form_name=TwoStepAmount</td> + <td></td> +</tr> +<tr> + <td>type</td> + <td>id=fname</td> + <td>Testy</td> +</tr> +<tr> + <td>type</td> + <td>id=lname</td> + <td>Testerton</td> +</tr> +<tr> + <td>select</td> + <td>id=country</td> + <td>label=Spain</td> +</tr> +<tr> + <td>type</td> + <td>id=street</td> + <td>123 Happy Street</td> +</tr> +<tr> + <td>type</td> + <td>id=city</td> + <td>Madrid</td> +</tr> +<tr> + <td>select</td> + <td>id=state</td> + <td>label=Outside the U.S.</td> +</tr> +<tr> + <td>type</td> + <td>id=emailAdd</td> + <td>jpostlethwa...@wikimedia.org</td> +</tr> +<tr> + <td>type</td> + <td>id=amount</td> + <td>100.00</td> +</tr> +<tr> + <td>select</td> + <td>id=input_currency_code</td> + <td>label=EUR: Euro</td> +</tr> +<tr> + <td>clickAndWait</td> + <td>css=input.button-plain</td> + <td></td> +</tr> +</tbody></table> +</body> +</html> Property changes on: branches/fundraising/extensions/DonationInterface/tests/macros/form.twostepamount.banktransfer.spain.htm ___________________________________________________________________ Added: svn:mime-type + text/html Added: svn:keywords + Author Date HeadURL Header Id Revision Added: svn:eol-style + native Added: branches/fundraising/extensions/DonationInterface/tests/phpunit.xml =================================================================== --- branches/fundraising/extensions/DonationInterface/tests/phpunit.xml (rev 0) +++ branches/fundraising/extensions/DonationInterface/tests/phpunit.xml 2011-10-19 03:18:57 UTC (rev 100208) @@ -0,0 +1,12 @@ +<phpunit> + <filter> + <whitelist addUncoveredFilesFromWhitelist="false"> + <directory suffix=".php">../</directory> + <exclude> + <directory suffix=".php">../extras</directory> + <directory suffix=".php">../tests</directory> + <directory suffix=".php">../../../includes</directory> + </exclude> + </whitelist> + </filter> +</phpunit> Property changes on: branches/fundraising/extensions/DonationInterface/tests/phpunit.xml ___________________________________________________________________ Added: svn:mime-type + text/xml Added: svn:keywords + Author Date HeadURL Header Id Revision Added: svn:eol-style + native Added: branches/fundraising/extensions/DonationInterface/tests/unittest.conf.dist =================================================================== --- branches/fundraising/extensions/DonationInterface/tests/unittest.conf.dist (rev 0) +++ branches/fundraising/extensions/DonationInterface/tests/unittest.conf.dist 2011-10-19 03:18:57 UTC (rev 100208) @@ -0,0 +1,90 @@ +#!/bin/sh +################################################################################ +# +# Wikimedia Foundation +# +# LICENSE +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# +# @category UnitTesting +# @package Fundraising_Miscellaneous +# @license http://www.gnu.org/copyleft/gpl.html GNU GENERAL PUBLIC LICENSE +# @since r462 +# @author Jeremy Postlethwaite <jpostlethwa...@wikimedia.org> +# +################################################################################ +# +# This is the distributed configuration file. If you need to make changes to +# these settings, copy this file to this directory and remove the ".dist" +# extension. +# +################################################################################ +# +# @var string $UNITTEST_HOSTNAME The hostname to the webserver. +# +: ${UNITTEST_HOSTNAME:="localhost"} +# +# @var string $UNITTEST_URL The url to the webserver. You need the trailing +# slash. +# +: ${UNITTEST_URL:="http://localhost/queue_handling/tests/"} +# +# @var string $PHPUNIT If phpunit.php is not within your shell $PATH, you may +# specify the full path here. +# +: ${PHPUNIT:="phpunit.php"} +# +# @var string $PHPUNIT_OPTS By default, all testing will be run in verbose mode. +# +: ${PHPUNIT_OPTS:="--verbose"} +# +# @var string $PHPUNIT_LIST_GROUPS Specify the relative path to the file in +# which you want to list groups designated by the doctag @group +# +: ${PHPUNIT_LIST_GROUPS:"=AllTests.php"} +# +# @var string $PHPUNIT_FILE Specify the relative path to the test in which you +# want to run. You need to omit the ".php" extension. +# +: ${PHPUNIT_FILE:="AllTests"} +# +# @var string $PHPUNIT_COVERAGE_HTML The relative path to the code coverage +# html directory +# +# This is where code coverage will be saved if the flag -ch is passed. If you wish to specify a full path, use: +# --coverage-html "/some/absolute/path" +# +# These directories will need to exist, they will not be created. +# +: ${PHPUNIT_COVERAGE_HTML:="logs/coverage/html"} +# +# @var string $PHPUNIT_COVERAGE_CLOVER The relative path to the code coverage +# clover directory +# +# This is where code coverage will be saved if the flag -ch is passed. If you wish to specify a full path, use: +# --coverage-clover "/some/absolute/path" +# +# These directories will need to exist, they will not be created. +# +: ${PHPUNIT_COVERAGE_CLOVER:="logs/coverage/clover/index.xml"} +# +# @var string $PHPUNIT_TESTDOX_HTML The relative path to the testdox output html +# directory. It is okay to put this the same directory as html coverage. +# +# This is where testdox will be saved if the flag -tdh is passed. If you wish to specify a full path, use: +# --testdox-html "/some/absolute/path" +# +# These directories will need to exist, they will not be created. +# +: ${PHPUNIT_TESTDOX_HTML:="logs/coverage/html/testdox.html"} + Added: branches/fundraising/extensions/DonationInterface/tests/unittest.sh =================================================================== --- branches/fundraising/extensions/DonationInterface/tests/unittest.sh (rev 0) +++ branches/fundraising/extensions/DonationInterface/tests/unittest.sh 2011-10-19 03:18:57 UTC (rev 100208) @@ -0,0 +1,289 @@ +#!/bin/sh +################################################################################ +# +# Wikimedia Foundation +# +# LICENSE +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# +# @category UnitTesting +# @package Fundraising_Miscellaneous +# @license http://www.gnu.org/copyleft/gpl.html GNU GENERAL PUBLIC LICENSE +# @since r462 +# @author Jeremy Postlethwaite <jpostlethwa...@wikimedia.org> +# +################################################################################ +# +# The script: +# +# unittest.sh - Launch PHPUnit for specific test group(s). +# +################################################################################ +# +# Debugging the script +# +# The set -x option causes sh to print each command to standard error before +# executing it. Since this can generate a lot of output, you may want to turn +# tracing on just before the section that you want to trace, and turn it off +# immediately afterward: +#set -x +# +################################################################################ +# +# help() +# +################################################################################ +help() +{ + cat <<HELP + +NAME + unittest.sh -- Run phpunit + +SYNOPSIS + $0 + [-h | --help] [help] + [-l | --list-groups] ["relative/path/to/file"] + + [-d | --debug ] + [-nc | --no-configuration ] + + [-cc | --coverage-clover ["/full/path/to/index.xml"] ] + [-ch | --coverage-html ["/full/path/to/folder"] ] + [-tdh | --testdox-html ["/full/path/to/testdox.html"] ] + +DESCRIPTION + The unittest.sh script is designed to facilitate running phpunit. + +EXAMPLES + + # List all groups available for testing + + $0 -l + + # List all groups available for testing in the file PostTestCase + + $0 -l GlobalCollect/AllTests.php + + # List all groups available for testing in the file PostTestCase + + $0 -l GlobalCollect/PostTestCase.php + + # Run unit testing with html code coverage report to default path + + $0 -ch + + # Run unit testing with html code coverage report + + $0 -ch GlobalCollect/AllTests + + # Run unit testing with clover code coverage report to default path + + $0 -cc + + # Run unit testing with clover code coverage report + + $0 -cc GlobalCollect/AllTests + + # Generate testdox report + + $0 -tdh + $0 --testdox-html + + # Turn on PHPUnit debugging + + $0 -d + $0 --debug + + # Ignore the local phpunit.xml file + + $0 -nc + $0 --no-configuration + +HELP + exit 0 +} +################################################################################ +# +# load_configuration() +# +# Load the configuration file +# +################################################################################ +load_configuration() +{ + CONFIGURATION_FILE="unittest.conf" + + # Load the custom configuration file if it exists + if [ -f "${CONFIGURATION_FILE}" ]; then + source ${CONFIGURATION_FILE}; + else + + # Load the default configuration file + CONFIGURATION_FILE="${CONFIGURATION_FILE}.dist" + + if [ -f "${CONFIGURATION_FILE}" ]; then + source ${CONFIGURATION_FILE}; + else + echo "The default configuration file (${CONFIGURATION_FILE}) is missing from: `pwd`" + exit 1; + fi + fi +} +################################################################################ +# +# Begin execution of script +# +################################################################################ +# Run help if needed. +[ -z "${1}" ] && help +[ "${1}" = "-h" ] && help +[ "${1}" = "help" ] && help + +# +# @var string $UNITTEST_DIRECTORY This is the relative path to the +# configuration file. +UNITTEST_DIRECTORY="`dirname $0`/" + +# Change to script directory to keep path variables consistent. +cd ${UNITTEST_DIRECTORY} + +load_configuration +################################################################################ +# +# @var string $PHPUNIT_COVERAGE_HTML_LINK The link to html code coverage +# +PHPUNIT_COVERAGE_HTML_LINK=${UNITTEST_URL} +# +# @var string $PHPUNIT_COVERAGE_CLOVER_LINK The link to clover code coverage +# +PHPUNIT_COVERAGE_CLOVER_LINK=${UNITTEST_URL} +# +# @var string $PHPUNIT_COVERAGE_TESTDOX_LINK The link to testdox code coverage +# +PHPUNIT_COVERAGE_TESTDOX_LINK=${UNITTEST_URL} +################################################################################ + +################################################################################ +# +# Loop through options to pass to phpunit.php +# +################################################################################ +while [ -n "$1" ] ; do + + case "$1" in + + # list-groups + -l|--list-groups) + PHPUNIT_LIST_GROUPS="--list-groups" + break ;; + + # coverage-html + -ch) + PHPUNIT_COVERAGE="${PHPUNIT_COVERAGE} --coverage-html ${PHPUNIT_COVERAGE_HTML}" + PHPUNIT_COVERAGE_HTML_LINK="${PHPUNIT_COVERAGE_HTML_LINK}${PHPUNIT_COVERAGE_HTML}" + shift 1 ;; + + --coverage-html) + PHPUNIT_COVERAGE="${PHPUNIT_COVERAGE} --coverage-html $2" + PHPUNIT_COVERAGE_HTML_LINK="${PHPUNIT_COVERAGE_HTML_LINK}$2" + shift ;; + + # coverage-clover + -cc) + PHPUNIT_COVERAGE="${PHPUNIT_COVERAGE} --coverage-clover ${PHPUNIT_COVERAGE_CLOVER}" + PHPUNIT_COVERAGE_CLOVER_LINK="${PHPUNIT_COVERAGE_CLOVER_LINK}${PHPUNIT_COVERAGE_CLOVER}" + shift 1 ;; + + --coverage-clover) + PHPUNIT_COVERAGE="${PHPUNIT_COVERAGE} --coverage-clover $2" + PHPUNIT_COVERAGE_CLOVER_LINK="${PHPUNIT_COVERAGE_CLOVER_LINK}$2" + shift 2 ;; + + # no-configuration + -nc|--no-configuration) + PHPUNIT_OPTS="${PHPUNIT_OPTS} --no-configuration" + shift ;; + + # testdox-html + -tdh) + PHPUNIT_COVERAGE="${PHPUNIT_COVERAGE} --testdox-html ${PHPUNIT_TESTDOX_HTML}" + PHPUNIT_COVERAGE_TESTDOX_LINK="${PHPUNIT_COVERAGE_TESTDOX_LINK}${PHPUNIT_TESTDOX_HTML}" + shift 1 ;; + + --testdox-html) + PHPUNIT_COVERAGE="${PHPUNIT_COVERAGE} --testdox-html $2" + PHPUNIT_COVERAGE_TESTDOX_LINK="${PHPUNIT_COVERAGE_TESTDOX_LINK}$2" + shift 2 ;; + + # debug + -d|--debug) + PHPUNIT_OPTS="${PHPUNIT_OPTS} --debug" + shift ;; + + # file + -f|--file) + PHPUNIT_FILE="$2" + shift 2 ;; + + # All groups + ALL|all|MAX|max) + PHPUNIT_GROUPS="" + break ;; + + *) + PHPUNIT_GROUPS="${PHPUNIT_GROUPS:+"$PHPUNIT_GROUPS,"}$1" + shift ;; + esac +done +################################################################################ +# +# Information statements +# +################################################################################ +echo "" + +echo "SCRIPT PATH:\n\n${PATH}" + +echo "" + +echo "PWD:\n\n`pwd`" + +echo "" + +COMMAND_OPTIONS="${PHPUNIT_OPTS} ${PHPUNIT_LIST_GROUPS} ${PHPUNIT_COVERAGE} ${PHPUNIT_GROUPS:+--group $PHPUNIT_GROUPS} ${PHPUNIT_FILE}" +echo "COMMAND:\n\n${PHPUNIT} ${COMMAND_OPTIONS}" + +echo "" + +echo "HTML code coverage link:\n\n${PHPUNIT_COVERAGE_HTML_LINK}" + +echo "" + +echo "Clover code coverage link:\n\n${PHPUNIT_COVERAGE_CLOVER_LINK}" + +echo "" + +echo "Testdox code coverage link:\n\n${PHPUNIT_COVERAGE_TESTDOX_LINK}" + +echo "" + +################################################################################ +# Debugging +# +# The set -n option causes sh to read the script but not execute any commands. +# This is useful for checking syntax. +#set -n +################################################################################ + +${PHPUNIT} ${PHPUNIT_OPTS} ${COMMAND_OPTIONS} Property changes on: branches/fundraising/extensions/DonationInterface/tests/unittest.sh ___________________________________________________________________ Added: svn:executable + * Added: svn:keywords + Author Date HeadURL Header Id Revision Added: svn:eol-style + native _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs