Completed
Push — master ( c8110c...3d2236 )
by Dmitry
19:54 queued 16:15
created

PaymentsCest::ensureICanCreateDetailedBill()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.568
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace hipanel\modules\finance\tests\acceptance\manager;
4
5
6
use hipanel\helpers\Url;
7
use hipanel\modules\finance\tests\_support\Page\bill\Create;
8
use hipanel\modules\finance\tests\_support\Page\bill\Update;
9
use hipanel\tests\_support\Step\Acceptance\Manager;
10
11
class PaymentsCest
12
{
13
    public $billId;
14
15
    public function ensureBillPageWorks(Manager $I): void
16
    {
17
        $I->login();
18
        $I->needPage(Url::to('@bill'));
19
    }
20
21
    /**
22
     * Tries to create a new simple bill without any data.
23
     *
24
     * Expects blank field errors.
25
     *
26
     * @param Manager $I
27
     * @throws \Exception
28
     */
29
    public function ensureICantCreateBillWithoutRequiredData(Manager $I): void
30
    {
31
        $page = new Create($I);
32
33
        $I->needPage(Url::to('@bill/create'));
34
35
        $page->save();
36
        $page->containsBlankFieldsError(['Client', 'Sum', 'Currency', 'Quantity']);
37
    }
38
39
    /**
40
     * Tries to create a new simple bill with all necessary data.
41
     *
42
     * Expects successful bill creation.
43
     *
44
     * @param Manager $I
45
     */
46
    public function ensureICanCreateSimpleBill(Manager $I): void
47
    {
48
        $page = new Create($I);
49
        $page->createBill($this->getBillData());
50
51
        $page->seeBillWasCreated();
52
    }
53
54
    /**
55
     * Tries to create a new detailed bill without charge data.
56
     *
57
     * Expects blank field errors.
58
     *
59
     * @param Manager $I
60
     * @throws \Exception
61
     */
62
    public function ensureICantCreateDetailedBillWithoutData(Manager $I): void
63
    {
64
        $page = new Create($I);
65
66
        $I->needPage(Url::to('@bill/create'));
67
68
        $page->fillMainBillFields($this->getBillData());
69
        $page->addCharge([]);
70
        $page->save();
71
        $page->containsBlankFieldsError(['Object', 'Sum', 'Quantity']);
72
    }
73
74
    /**
75
     * Tries to create a new detailed bill with all the necessary data.
76
     *
77
     * Expects successful bill creation.
78
     * Also checks Sum field mismatch error.
79
     *
80
     * @param Manager $I
81
     * @throws \Exception
82
     */
83
    public function ensureICanCreateDetailedBill(Manager $I): void
84
    {
85
        $I->needPage(Url::to('@bill/create'));
86
87
        $page = new Create($I);
88
        $page->deleteLastCharge();
89
90
        $page->addCharges([
91
            $this->getChargeData('TEST01'),
92
            $this->getChargeData('vCDN-soltest')
93
        ]);
94
        $page->containsCharges(2);
95
96
        $page->save();
97
        $page->containsSumMismatch();
98
99
        $chargesSum = $page->getChargesTotalSum();
100
101
        $page->setBillTotalSum(-$chargesSum);
102
        $page->save();
103
        $this->billId = $page->seeBillWasCreated();
104
    }
105
106
    /**
107
     * Tries to update early created bill.
108
     *
109
     * @param Manager $I
110
     */
111
    public function ensureICanUpdateBill(Manager $I): void
112
    {
113
        $page = new Update($I);
114
115
        $page->goToUpdatePage($this->billId);
116
        $page->containsCharges(2);
117
118
        $page->deleteLastCharge();
119
        $page->containsCharges(1);
120
121
        $chargesSum = $page->getChargesTotalSum();
122
        $page->setBillTotalSum(-$chargesSum);
123
124
        $page->save();
125
        $page->seeBillWasUpdated();
126
    }
127
128
    /**
129
     * Checks whether a bill was updated successfully.
130
     *
131
     * @param Manager $I
132
     * @throws \Exception
133
     */
134
    public function ensureBillWasSuccessfullyUpdated (Manager $I): void
135
    {
136
        $page = new Update($I);
137
138
        $page->goToUpdatePage($this->billId);
139
        $page->containsCharges(1);
140
141
        $I->waitForElement('span[title=vCDN-soltest]', 5);
142
        $I->see('Server', 'div.bill-charges:first-child');
143
        $I->see('Monthly fee', 'div.bill-charges:first-child');
144
    }
145
146
    /**
147
     * @return array
148
     */
149
    protected function getBillData(): array
150
    {
151
        return [
152
            'login'     => '[email protected]',
153
            'type'      => 'Monthly fee',
154
            'currency'  => '$',
155
            'sum'       =>  1000,
156
            'quantity'  =>  1
157
        ];
158
    }
159
160
    /**
161
     * @param string $objectId
162
     * @return array
163
     */
164
    protected function getChargeData(string $objectId): array
165
    {
166
        return [
167
            'class'     => 'Server',
168
            'objectId'  => $objectId,
169
            'type'      => 'Monthly fee',
170
            'sum'       => -250,
171
            'quantity'  => 1
172
        ];
173
    }
174
}
175