|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bummzack\SsOmnipayUI\Tests\GridField; |
|
4
|
|
|
|
|
5
|
|
|
use Bummzack\SsOmnipayUI\GridField\GridFieldCaptureAction; |
|
6
|
|
|
use Bummzack\SsOmnipayUI\GridField\GridFieldRefundAction; |
|
7
|
|
|
use Bummzack\SsOmnipayUI\GridField\GridFieldVoidAction; |
|
8
|
|
|
use SilverStripe\Control\Controller; |
|
9
|
|
|
use SilverStripe\Core\Config\Config; |
|
10
|
|
|
use SilverStripe\Dev\CSSContentParser; |
|
11
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
12
|
|
|
use SilverStripe\Forms\FieldList; |
|
13
|
|
|
use SilverStripe\Forms\Form; |
|
14
|
|
|
use SilverStripe\Forms\GridField\GridField; |
|
15
|
|
|
use SilverStripe\Forms\GridField\GridFieldConfig; |
|
16
|
|
|
use SilverStripe\Omnipay\GatewayInfo; |
|
17
|
|
|
use SilverStripe\Omnipay\Model\Payment; |
|
18
|
|
|
use SilverStripe\ORM\ArrayList; |
|
19
|
|
|
use SilverStripe\ORM\DataList; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Test payment actions in GridFields |
|
23
|
|
|
*/ |
|
24
|
|
|
class GridFieldPaymentActionsTest extends SapphireTest |
|
25
|
|
|
{ |
|
26
|
|
|
|
|
27
|
|
|
/** @var ArrayList */ |
|
28
|
|
|
protected $list; |
|
29
|
|
|
|
|
30
|
|
|
/** @var GridField */ |
|
31
|
|
|
protected $gridField; |
|
32
|
|
|
|
|
33
|
|
|
/** @var Form */ |
|
34
|
|
|
protected $form; |
|
35
|
|
|
|
|
36
|
|
|
/** @var string */ |
|
37
|
|
|
protected static $fixture_file = 'GridFieldTestPayments.yml'; |
|
38
|
|
|
|
|
39
|
|
|
public function setUp() |
|
40
|
|
|
{ |
|
41
|
|
|
parent::setUp(); |
|
42
|
|
|
$this->list = new DataList(Payment::class); |
|
|
|
|
|
|
43
|
|
|
$config = GridFieldConfig::create() |
|
44
|
|
|
->addComponent(new GridFieldCaptureAction()) |
|
45
|
|
|
->addComponent(new GridFieldRefundAction()) |
|
46
|
|
|
->addComponent(new GridFieldVoidAction()); |
|
47
|
|
|
$this->gridField = new GridField('testfield', 'testfield', $this->list, $config); |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
$ctrl = new Controller(); |
|
51
|
|
|
$ctrl::config()->set('url_segment', 'mock'); |
|
52
|
|
|
$this->form = new Form( |
|
53
|
|
|
$ctrl, |
|
54
|
|
|
'mockform', |
|
55
|
|
|
new FieldList(array($this->gridField)), |
|
56
|
|
|
new FieldList() |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testButtons() |
|
61
|
|
|
{ |
|
62
|
|
|
$content = new CSSContentParser($this->gridField->FieldHolder()); |
|
63
|
|
|
|
|
64
|
|
|
// There should be a total of 5 items in the GridField (see fixture file) |
|
65
|
|
|
$this->assertEquals(5, count($content->getBySelector('tr.ss-gridfield-item'))); |
|
66
|
|
|
|
|
67
|
|
|
// Two of the payments should have capture buttons |
|
68
|
|
|
$this->assertEquals(2, count($content->getBySelector('.gridfield-button-capture'))); |
|
69
|
|
|
|
|
70
|
|
|
// Two payments should have a refund button |
|
71
|
|
|
$this->assertEquals(2, count($content->getBySelector('.gridfield-button-refund'))); |
|
72
|
|
|
|
|
73
|
|
|
// Two payments should have a void button |
|
74
|
|
|
$this->assertEquals(2, count($content->getBySelector('.gridfield-button-void'))); |
|
75
|
|
|
|
|
76
|
|
|
// Disallow actions for Manual Gateway |
|
77
|
|
|
Config::modify()->merge(GatewayInfo::class, 'Manual', array( |
|
78
|
|
|
'can_capture' => false, |
|
79
|
|
|
'can_refund' => false, |
|
80
|
|
|
'can_void' => false |
|
81
|
|
|
)); |
|
82
|
|
|
|
|
83
|
|
|
$content = new CSSContentParser($this->gridField->FieldHolder()); |
|
84
|
|
|
|
|
85
|
|
|
// Now only one payment should have a capture button |
|
86
|
|
|
$this->assertEquals(1, count($content->getBySelector('.gridfield-button-capture'))); |
|
87
|
|
|
|
|
88
|
|
|
// Now only one payment should have a refund button |
|
89
|
|
|
$this->assertEquals(1, count($content->getBySelector('.gridfield-button-refund'))); |
|
90
|
|
|
|
|
91
|
|
|
// Now only one payment should have a void button |
|
92
|
|
|
$this->assertEquals(1, count($content->getBySelector('.gridfield-button-void'))); |
|
93
|
|
|
|
|
94
|
|
|
// Update the authorized PaymentExpress_PxPay payment to Void |
|
95
|
|
|
$payment = $this->objFromFixture(Payment::class, 'payment3'); |
|
96
|
|
|
$payment->Status = 'Void'; |
|
97
|
|
|
$payment->write(); |
|
98
|
|
|
|
|
99
|
|
|
$content = new CSSContentParser($this->gridField->FieldHolder()); |
|
100
|
|
|
// Now no payment should have a capture button |
|
101
|
|
|
$this->assertEquals(0, count($content->getBySelector('.gridfield-button-capture'))); |
|
102
|
|
|
|
|
103
|
|
|
// One payment should still have a refund button |
|
104
|
|
|
$this->assertEquals(1, count($content->getBySelector('.gridfield-button-refund'))); |
|
105
|
|
|
|
|
106
|
|
|
// Now no payment should have a void button |
|
107
|
|
|
$this->assertEquals(0, count($content->getBySelector('.gridfield-button-void'))); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..