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

View   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 56
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A loadPage() 0 6 1
A seeRandomPrices() 0 12 3
A fillRandomPrices() 0 15 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