MediaWiki fundraising/REL1_35
DonationInterface.class.php
Go to the documentation of this file.
1<?php
2
3use PHPUnit\Framework\TestCase;
4use SmashPig\Core\Context;
5use SmashPig\Core\GlobalConfiguration;
6use SmashPig\Core\ProviderConfiguration;
7
12 public static function registerExtension() {
13 global $wgDonationInterfaceTest,
14 $wgDonationInterfaceTemplate,
15 $wgDonationInterfaceErrorTemplate,
16 $wgDonationInterfaceMessageSourceType,
17 $IP;
18
19 // Test mode (not for production!)
20 // Set it if not defined
21 if ( !isset( $wgDonationInterfaceTest ) || $wgDonationInterfaceTest !== true ) {
22 $wgDonationInterfaceTest = false;
23 }
24
28 $wgDonationInterfaceTemplate = __DIR__ . '/gateway_forms/mustache/index.html.mustache';
29
33 $wgDonationInterfaceErrorTemplate = __DIR__ . '/gateway_forms/mustache/error_form.html.mustache';
34
35 // Include composer's autoload if the vendor directory exists. If we have been
36 // included via Composer, our dependencies should already be autoloaded at the
37 // top level.
38 $vendorAutoload = __DIR__ . '/vendor/autoload.php';
39 if ( file_exists( $vendorAutoload ) ) {
40 require_once $vendorAutoload;
41 } else {
42 require_once __DIR__ . '/gateway_common/WmfFramework.php';
43 }
44 if ( defined( 'MEDIAWIKI' ) ) {
45 // If we're the top-level application, initialize the SmashPig context
46 $spConfig = GlobalConfiguration::create();
47 Context::init( $spConfig );
48 $context = Context::get();
49 $context->setSourceName( 'DonationInterface' );
50 $context->setSourceType( $wgDonationInterfaceMessageSourceType );
51 $context->setVersionFromFile( "$IP/.version-stamp" );
52 }
53 }
54
55 public static function onDonationInterfaceUnitTests( &$files ) {
56 global $wgAutoloadClasses;
57
58 $testDir = __DIR__ . '/tests/phpunit/';
59
60 // Set up globaltown
61 if ( file_exists( $testDir . 'TestConfiguration.php' ) ) {
62 require_once $testDir . 'TestConfiguration.php';
63 } else {
64 return true;
65 }
66
67 $wgAutoloadClasses['DonationInterfaceTestCase'] = $testDir . 'DonationInterfaceTestCase.php';
68 $wgAutoloadClasses['DonationInterfaceApiTestCase'] = $testDir . 'DonationInterfaceApiTestCase.php';
69 $wgAutoloadClasses['BaseAdyenCheckoutTestCase'] = $testDir . 'BaseAdyenCheckoutTestCase.php';
70 $wgAutoloadClasses['BaseIngenicoTestCase'] = $testDir . 'BaseIngenicoTestCase.php';
71 $wgAutoloadClasses['TestingAstroPayAdapter'] = $testDir . 'includes/test_gateway/TestingAstroPayAdapter.php';
72 $wgAutoloadClasses['TestingDonationLogger'] = $testDir . 'includes/TestingDonationLogger.php';
73 $wgAutoloadClasses['TestingGatewayPage'] = $testDir . 'includes/TestingGatewayPage.php';
74 $wgAutoloadClasses['TestingGenericAdapter'] = $testDir . 'includes/test_gateway/TestingGenericAdapter.php';
75 $wgAutoloadClasses['TestingGlobalCollectAdapter'] = $testDir . 'includes/test_gateway/TestingGlobalCollectAdapter.php';
76 $wgAutoloadClasses['TestingPaypalExpressAdapter'] = $testDir . 'includes/test_gateway/TestingPaypalExpressAdapter.php';
77
78 $wgAutoloadClasses['TestingRequest'] = $testDir . 'includes/test_request/test.request.php';
79 $wgAutoloadClasses['TTestingAdapter'] = $testDir . 'includes/test_gateway/test.adapter.php';
80
81 return true;
82 }
83
89 public static function onMediaWikiPHPUnitTeststartTest( TestCase $test ) {
90 // In some cases, running a non-DonationInterface test may invoke DonationInterface
91 // code. For those cases, ensure a testing SmashPig config is used. This previously
92 // caused errors in SpecialPageFatalTest::testSpecialPageDoesNotFatal. See T287599.
93 if ( !in_array( "DonationInterface", $test->getGroups() ) ) {
94 DonationInterfaceTestCase::setUpSmashPigContext();
95 }
96 }
97
98 public static function getAdapterClassForGateway( $gateway ) {
99 global $wgDonationInterfaceGatewayAdapters;
100 if ( !array_key_exists( $gateway, $wgDonationInterfaceGatewayAdapters ) ) {
101 throw new OutOfRangeException( "No adapter configured for $gateway" );
102 }
103 return $wgDonationInterfaceGatewayAdapters[$gateway];
104 }
105
112 public static function setSmashPigProvider( $provider ) {
113 $ctx = Context::get();
114 $spConfig = ProviderConfiguration::createForProvider(
115 $provider,
116 $ctx->getGlobalConfiguration()
117 );
118 // FIXME: should set a logger prefix here, but we've got a chicken
119 // and egg problem with the Gateway constructor
120 $ctx->setProviderConfiguration( $spConfig );
121 return $spConfig;
122 }
123
132 public static function onGetMessagesFileName( $code, &$file ) {
133 if ( $code === 'es-419' ) {
134 $file = __DIR__ . DIRECTORY_SEPARATOR . 'gateway_common' . DIRECTORY_SEPARATOR .
135 'messages' . DIRECTORY_SEPARATOR . 'MessagesEs_419.php';
136 }
137 }
138}
$wgAutoloadClasses
Array mapping class names to filenames, for autoloading.
static setSmashPigProvider( $provider)
Initialize SmashPig context and return configuration object.
static onGetMessagesFileName( $code, &$file)
Register es-419 as a language supported by this extension but not by MediaWiki core.
static registerExtension()
Executed after processing extension.json.
static getAdapterClassForGateway( $gateway)
static onMediaWikiPHPUnitTeststartTest(TestCase $test)
Implements MediaWikiPHPUnitTest::startTest hook.
static onDonationInterfaceUnitTests(&$files)
$IP
Definition rebuild.php:19
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42