Completed
Push — master ( b66556...89216d )
by Dmitry
21:57
created

View::fillRandomPrices()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
rs 9.7666
cc 1
nc 1
nop 1
1
<?php
2
3
namespace hipanel\modules\finance\tests\_support\Page\price;
4
5
use hipanel\tests\_support\AcceptanceTester;
6
use hipanel\tests\_support\Page\Authenticated;
7
use hipanel\helpers\Url;
8
9
class View extends Authenticated
10
{
11
    /**
12
     * @var array
13
     */
14
    protected $priceValues = [];
15
16
    /**
17
     * @var int the target plan ID
18
     */
19
    private $id;
20
21
    public function __construct(AcceptanceTester $I, int $id)
22
    {
23
        parent::__construct($I);
24
25
        $this->id = $id;
26
        $this->loadPage();
27
    }
28
29
    protected function loadPage(): void
30
    {
31
        $I = $this->tester;
32
33
        $I->needPage(Url::to(['@plan/view', 'id' => $this->id]));
34
    }
35
36
    public function seeRandomPrices(): void
37
    {
38
        if (empty($this->priceValues)) {
39
            throw new \LogicException('Prices were not created yet');
40
        }
41
42
        $I = $this->tester;
43
44
        foreach ($this->priceValues as $value) {
45
            $I->seeInSource(number_format($value, 2));
46
        }
47
    }
48
49
    public function fillRandomPrices(string $type): void
50
    {
51
        $I = $this->tester;
52
53
        $this->priceValues = $I->executeJS("
54
        var prices = [];
55
        $('.price-item').each(function(){
56
            var number = $(this).find('input[id^={$type}][id$=price]');
57
            var randomValue = Math.floor(Math.random() * 2147483647);
58
            number.val(randomValue);
59
            prices.push(randomValue);
60
        });
61
        return prices;
62
        ");
63
    }
64
}
65