-
Notifications
You must be signed in to change notification settings - Fork 252
Expand file tree
/
Copy pathPaymentGatewayTest.php
More file actions
130 lines (116 loc) · 4.91 KB
/
PaymentGatewayTest.php
File metadata and controls
130 lines (116 loc) · 4.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
namespace Drupal\Tests\commerce_payment\Functional;
use Drupal\commerce_payment\Entity\PaymentGateway;
use Drupal\Tests\commerce\Functional\CommerceBrowserTestBase;
/**
* Tests the payment gateway UI.
*
* @group commerce
*/
class PaymentGatewayTest extends CommerceBrowserTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'commerce_payment_example',
];
/**
* {@inheritdoc}
*/
protected function getAdministratorPermissions() {
return array_merge([
'administer commerce_payment_gateway',
], parent::getAdministratorPermissions());
}
/**
* Tests creating a payment gateway.
*/
public function testPaymentGatewayCreation() {
$this->drupalGet('admin/commerce/config/payment-gateways');
$this->getSession()->getPage()->clickLink('Add payment gateway');
$this->assertSession()->addressEquals('admin/commerce/config/payment-gateways/add');
$details = [
'value' => 'Test details',
'format' => 'plain_text',
];
$values = [
'label' => 'Example',
'plugin' => 'example_offsite_redirect',
'configuration[example_offsite_redirect][redirect_method]' => 'post',
'configuration[example_offsite_redirect][mode]' => 'test',
'configuration[example_offsite_redirect][details][value]' => $details['value'],
'status' => '1',
// Setting the 'id' can fail if focus switches to another field.
// This is a bug in the machine name JS that can be reproduced manually.
'id' => 'example',
];
$this->submitForm($values, 'Save');
$this->assertSession()->addressEquals('admin/commerce/config/payment-gateways');
$this->assertSession()->responseContains('Example');
$this->assertSession()->responseContains('Test');
$payment_gateway = PaymentGateway::load('example');
$this->assertEquals('example', $payment_gateway->id());
$this->assertEquals('Example', $payment_gateway->label());
$this->assertEquals('example_offsite_redirect', $payment_gateway->getPluginId());
$this->assertEmpty($payment_gateway->getConditions());
$this->assertEquals('AND', $payment_gateway->getConditionOperator());
$this->assertEquals(TRUE, $payment_gateway->status());
$payment_gateway_plugin = $payment_gateway->getPlugin();
$this->assertEquals('test', $payment_gateway_plugin->getMode());
$this->assertEquals($details, $payment_gateway_plugin->getDetails());
$configuration = $payment_gateway_plugin->getConfiguration();
$this->assertEquals('post', $configuration['redirect_method']);
}
/**
* Tests editing a payment gateway.
*/
public function testPaymentGatewayEditing() {
$values = [
'id' => 'edit_example',
'label' => 'Edit example',
'plugin' => 'example_offsite_redirect',
'status' => 0,
];
$payment_gateway = $this->createEntity('commerce_payment_gateway', $values);
$this->drupalGet('admin/commerce/config/payment-gateways/manage/' . $payment_gateway->id());
$details = [
'value' => 'Test details',
'format' => 'plain_text',
];
$values += [
'configuration[example_offsite_redirect][redirect_method]' => 'get',
'configuration[example_offsite_redirect][mode]' => 'live',
'configuration[example_offsite_redirect][details][value]' => $details['value'],
'conditionOperator' => 'OR',
];
$this->submitForm($values, 'Save');
\Drupal::entityTypeManager()->getStorage('commerce_payment_gateway')->resetCache();
$payment_gateway = PaymentGateway::load('edit_example');
$this->assertEquals('edit_example', $payment_gateway->id());
$this->assertEquals('Edit example', $payment_gateway->label());
$this->assertEquals('example_offsite_redirect', $payment_gateway->getPluginId());
$this->assertEmpty($payment_gateway->getConditions());
$this->assertEquals('OR', $payment_gateway->getConditionOperator());
$this->assertEquals(FALSE, $payment_gateway->status());
$payment_gateway_plugin = $payment_gateway->getPlugin();
$this->assertEquals('live', $payment_gateway_plugin->getMode());
$this->assertEquals($details, $payment_gateway_plugin->getDetails());
$configuration = $payment_gateway_plugin->getConfiguration();
$this->assertEquals('get', $configuration['redirect_method']);
}
/**
* Tests deleting a payment gateway.
*/
public function testPaymentGatewayDeletion() {
$payment_gateway = $this->createEntity('commerce_payment_gateway', [
'id' => 'for_deletion',
'label' => 'For deletion',
'plugin' => 'example_offsite_redirect',
]);
$this->drupalGet('admin/commerce/config/payment-gateways/manage/' . $payment_gateway->id() . '/delete');
$this->submitForm([], 'Delete');
$this->assertSession()->addressEquals('admin/commerce/config/payment-gateways');
$payment_gateway_exists = (bool) PaymentGateway::load('for_deletion');
$this->assertEmpty($payment_gateway_exists, 'The payment gateway has been deleted from the database.');
}
}