PaymentsCest::getChargeData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * Finance module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-finance
6
 * @package   hipanel-module-finance
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\tests\acceptance\manager;
12
13
use hipanel\helpers\Url;
14
use hipanel\modules\finance\tests\_support\Page\bill\Create;
15
use hipanel\modules\finance\tests\_support\Page\bill\Update;
16
use hipanel\tests\_support\Page\IndexPage;
17
use hipanel\tests\_support\Step\Acceptance\Seller;
18
19
class PaymentsCest
20
{
21
    public $billId;
22
23
    public function ensureBillPageWorks(Seller $I): void
24
    {
25
        $I->login();
26
        $I->needPage(Url::to('@bill'));
27
    }
28
29
    /**
30
     * Tries to create a new simple bill without any data.
31
     *
32
     * Expects blank field errors.
33
     *
34
     * @param Seller $I
35
     * @throws \Exception
36
     */
37
    public function ensureICantCreateBillWithoutRequiredData(Seller $I): void
38
    {
39
        $page = new Create($I);
40
41
        $I->needPage(Url::to('@bill/create'));
42
43
        $I->pressButton('Save');
44
        $page->containsBlankFieldsError(['Sum', 'Currency', 'Quantity']);
45
    }
46
47
    /**
48
     * Tries to create a new simple bill with all necessary data.
49
     *
50
     * Expects successful bill creation.
51
     *
52
     * @param Seller $I
53
     * @throws \Exception
54
     */
55
    public function ensureICanCreateSimpleBill(Seller $I): void
56
    {
57
        $page = new Create($I);
58
59
        $I->needPage(Url::to('@bill/create'));
60
61
        $page->fillMainBillFields($this->getBillData());
62
        $I->pressButton('Save');
63
64
        $page->seeActionSuccess();
65
    }
66
67
    /**
68
     * Tries to create a new detailed bill without charge data.
69
     *
70
     * Expects blank field errors.
71
     *
72
     * @param Seller $I
73
     * @throws \Exception
74
     */
75
    public function ensureICantCreateDetailedBillWithoutData(Seller $I): void
76
    {
77
        $page = new Create($I);
78
79
        $I->needPage(Url::to('@bill/create'));
80
81
        $page->fillMainBillFields($this->getBillData());
82
        $page->addCharge([]);
83
        $I->pressButton('Save');
84
        $page->containsBlankFieldsError(['Sum', 'Quantity']);
85
        $page->deleteLastCharge();
86
    }
87
88
    /**
89
     * Tries to create a new detailed bill with all the necessary data.
90
     *
91
     * Expects successful bill creation.
92
     * Also checks Sum field mismatch error.
93
     *
94
     * @param Seller $I
95
     * @throws \Exception
96
     */
97
    public function ensureICanCreateDetailedBill(Seller $I): void
98
    {
99
        $page = new Create($I);
100
101
        $I->needPage(Url::to('@bill/create'));
102
103
        $page->fillMainBillFields($this->getBillData());
104
        $page->addCharges([
105
            $this->getChargeData('TEST-DS-01'),
106
            $this->getChargeData('TEST-DS-02'),
107
        ]);
108
        $page->containsCharges(2);
109
110
        $I->pressButton('Save');
111
112
        $page->containsSumMismatch();
113
114
        $chargesSum = $page->getChargesTotalSum();
115
116
        $page->setBillTotalSum(-$chargesSum);
117
        $I->pressButton('Save');
118
        $this->billId = $page->seeActionSuccess();
119
    }
120
121
    /**
122
     * Tries to update early created bill.
123
     *
124
     * @param Seller $I
125
     * @throws \Codeception\Exception\ModuleException
126
     */
127
    public function ensureICanUpdateBill(Seller $I): void
128
    {
129
        $indexPage  = new IndexPage($I);
130
        $updatePage = new Update($I);
131
132
        $I->needPage(Url::to('@bill/index'));
133
134
        $indexPage->sortBy('Time');
135
        $indexPage->sortBy('Time');
136
137
        $indexPage->openRowMenuById($this->billId);
138
        $indexPage->chooseRowMenuOption('Update');
139
140
        $updatePage->containsCharges(2);
141
142
        $updatePage->deleteChargeByName('TEST-DS-01');
143
        $updatePage->containsCharges(1);
144
145
        $chargesSum = $updatePage->getChargesTotalSum();
146
        $updatePage->setBillTotalSum(-$chargesSum);
147
148
        $I->pressButton('Save');
149
        $updatePage->seeActionSuccess();
150
    }
151
152
    /**
153
     * Checks whether a bill was updated successfully.
154
     *
155
     * @param Seller $I
156
     * @throws \Exception
157
     */
158
    public function ensureBillWasSuccessfullyUpdated(Seller $I): void
159
    {
160
        $indexPage  = new IndexPage($I);
161
        $updatePage = new Update($I);
162
163
        $I->needPage(Url::to('@bill/index'));
164
165
        $indexPage->openRowMenuById($this->billId);
166
        $indexPage->chooseRowMenuOption('Update');
167
168
        $updatePage->containsCharges(1);
169
170
        $chargeSelector = 'div.bill-charges:first-child';
171
        $I->see('TEST-DS-02', $chargeSelector);
172
        $I->see('Server', $chargeSelector);
173
        $I->see('Monthly fee', $chargeSelector);
174
    }
175
176
    /**
177
     * @return array
178
     */
179
    protected function getBillData(): array
180
    {
181
        return [
182
            'login'     => 'hipanel_test_user',
183
            'type'      => 'Monthly fee',
184
            'currency'  => '$',
185
            'sum'       =>  1000,
186
            'quantity'  =>  1,
187
        ];
188
    }
189
190
    /**
191
     * @param string $objectId
192
     * @return array
193
     */
194
    protected function getChargeData(string $objectId): array
195
    {
196
        return [
197
            'class'     => 'Server',
198
            'objectId'  => $objectId,
199
            'type'      => 'Monthly fee',
200
            'sum'       => -250,
201
            'quantity'  => 1,
202
        ];
203
    }
204
}
205