GridFieldPaymentActionsTest::testButtons()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 9.1127
c 0
b 0
f 0
cc 1
nc 1
nop 0
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);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \SilverStripe\ORM\Da...y\Model\Payment::class) of type object<SilverStripe\ORM\DataList> is incompatible with the declared type object<SilverStripe\ORM\ArrayList> of property $list.

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..

Loading history...
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