Skip to content

Commit dde5eb8

Browse files
authored
Make gatewayinfo respect false settings on is_offsite. (silverstripe#191)
* Make gatewayinfo respect `false` settings on `is_offsite`. * Fix unit-tests for changes that happened in the Dummy gateway. * Install from source in travis.
1 parent d252d6b commit dde5eb8

File tree

4 files changed

+45
-27
lines changed

4 files changed

+45
-27
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ before_script:
3333
- export PATH=~/.composer/vendor/bin:$PATH
3434
- composer validate
3535
- if [[ $DB == PGSQL ]]; then composer require silverstripe/postgresql:^2.0 --no-update; fi
36-
- composer update
36+
- composer install --prefer-source --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile
3737
- if [[ $PHPCS_TEST ]]; then composer global require squizlabs/php_codesniffer:^3 --prefer-dist --no-interaction --no-progress --no-suggest -o; fi
3838

3939
script:

src/GatewayInfo.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,10 @@ public static function isSupported($gateway)
148148
*/
149149
public static function isOffsite($gateway)
150150
{
151-
if (self::getConfigSetting($gateway, 'is_offsite')) {
152-
return true;
151+
$configValue = self::getConfigSetting($gateway, 'is_offsite');
152+
// If the value from config is set, return it
153+
if (is_bool($configValue)) {
154+
return $configValue;
153155
}
154156

155157
$factory = new GatewayFactory();

tests/CreateCardServiceTest.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,32 @@ protected function buildDummyGatewayMock($successValue)
112112
//--------------------------------------------------------------------------------------------------------------
113113
// Payment request and response
114114

115-
$mockPaymentResponse = $this->getMockBuilder('Omnipay\Dummy\Message\Response')
116-
->disableOriginalConstructor()->getMock();
115+
$mockPaymentResponse = $this
116+
->getMockBuilder('Omnipay\Dummy\Message\Response')
117+
->disableOriginalConstructor()
118+
->setMethods(['isSuccessful'])
119+
->getMock();
117120

118-
$mockPaymentResponse->expects($this->any())
119-
->method('isSuccessful')->will($this->returnValue($successValue));
121+
$mockPaymentResponse
122+
->expects($this->any())
123+
->method('isSuccessful')
124+
->will($this->returnValue($successValue));
120125

121-
$mockPaymentRequest = $this->getMockBuilder('Omnipay\Dummy\Message\AuthorizeRequest')
122-
->disableOriginalConstructor()->getMock();
126+
$mockPaymentRequest = $this
127+
->getMockBuilder('Omnipay\Dummy\Message\AbstractRequest')
128+
->setMethods(['send'])
129+
->getMock();
123130

124-
$mockPaymentRequest->expects($this->any())->method('send')->will($this->returnValue($mockPaymentResponse));
131+
$mockPaymentRequest
132+
->expects($this->any())
133+
->method('send')
134+
->will($this->returnValue($mockPaymentResponse));
125135

126136
//--------------------------------------------------------------------------------------------------------------
127137
// Build the gateway
128138

129-
$stubGateway = $this->getMockBuilder('Omnipay\Common\AbstractGateway')
139+
$stubGateway = $this
140+
->getMockBuilder('Omnipay\Common\AbstractGateway')
130141
->setMethods(array('createCard', 'getName'))
131142
->getMock();
132143

tests/GatewayFieldsFactoryTest.php

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -174,37 +174,38 @@ public function testCardTypes()
174174

175175
public function testRequiredFields()
176176
{
177-
Config::modify()->merge(GatewayInfo::class, 'Dummy', array(
178-
'required_fields' => array(
177+
Config::modify()->merge(GatewayInfo::class, 'Dummy', [
178+
'required_fields' => [
179179
'billingAddress1',
180180
'city',
181181
'country',
182182
'email',
183183
'company'
184-
)
185-
));
184+
],
185+
'is_offsite' => false
186+
]);
186187

187-
Config::modify()->merge(GatewayInfo::class, 'PayPal_Express', array(
188-
'required_fields' => array(
188+
Config::modify()->merge(GatewayInfo::class, 'PayPal_Express', [
189+
'required_fields' => [
189190
'billingAddress1',
190191
'city',
191192
'country',
192193
'email',
193194
'company'
194-
)
195-
));
195+
]
196+
]);
196197

197-
$factory = new GatewayFieldsFactory('Dummy', array(
198+
$factory = new GatewayFieldsFactory('Dummy', [
198199
'Card',
199200
'Billing',
200201
'Shipping',
201202
'Company',
202203
'Email'
203-
));
204+
]);
204205

205206
$fields = $factory->getFields();
206207

207-
$defaults = array(
208+
$defaults = [
208209
// default required CC fields for gateways that aren't manual and aren't offsite
209210
'name',
210211
'number',
@@ -219,37 +220,41 @@ public function testRequiredFields()
219220
'shippingCountry',
220221
'company',
221222
'email'
222-
);
223+
];
223224

224225
$this->assertEquals($this->factory->getFieldName($defaults), array_keys($fields->dataFields()));
225226

226227
// Same procedure with offsite gateway should not return the CC fields
227228

228-
$factory = new GatewayFieldsFactory('PayPal_Express', array(
229+
$factory = new GatewayFieldsFactory('PayPal_Express', [
229230
'Card',
230231
'Billing',
231232
'Shipping',
232233
'Company',
233234
'Email'
234-
));
235+
]);
235236

236237
$fields = $factory->getFields();
237238

238-
$pxDefaults = array(
239+
$pxDefaults = [
239240
'billingAddress1',
240241
'billingCity',
241242
'billingCountry',
242243
'shippingCity',
243244
'shippingCountry',
244245
'company',
245246
'email'
246-
);
247+
];
247248

248249
$this->assertEquals($this->factory->getFieldName($pxDefaults), array_keys($fields->dataFields()));
249250
}
250251

251252
public function testRenamedFields()
252253
{
254+
Config::modify()->merge(GatewayInfo::class, 'Dummy', [
255+
'is_offsite' => false
256+
]);
257+
253258
Config::modify()->merge('SilverStripe\Omnipay\GatewayFieldsFactory', 'rename', array(
254259
'prefix' => 'prefix_',
255260
'name' => 'testName',

0 commit comments

Comments
 (0)