Create::prepareForCreation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
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\_support\Page\price\certificate;
12
13
use hipanel\modules\finance\tests\_support\Page\price\Create as PriceCreate;
14
15
class Create extends PriceCreate
16
{
17
    public function fillRandomPrices(string $type): void
18
    {
19
        $I = $this->tester;
20
21
        $this->priceValues = $I->executeJS("
22
        var prices = [];
23
        $('.price-input').each(function(){
24
            var randomValue = Math.floor(Math.random() * 2147483647);
25
            $(this).val(randomValue);
26
            prices.push(randomValue);
27
        });
28
        return prices;
29
        ");
30
    }
31
32
    public function addPrices(string $templateName): void
33
    {
34
        $this->prepareForCreation($templateName);
35
        $this->fillRandomPrices('');
36
        $this->saveForm();
37
        $this->seeRandomPrices();
38
    }
39
40
    private function prepareForCreation(string $templateName): void
41
    {
42
        $this->loadPage();
43
        $this->openModal();
44
        $this->chooseTemplate($templateName);
45
        $this->proceedToCreation();
46
    }
47
48
    public function chooseTemplate(string $templateName): void
49
    {
50
        $this->select2->open('#template_plan_id');
0 ignored issues
show
Bug introduced by
The property select2 does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
51
        $this->select2->fillSearchField($templateName);
52
        $this->select2->chooseOption($templateName);
53
    }
54
55
    public function ensureThereNoSuggestions(string $templateName): void
56
    {
57
        $this->prepareForCreation($templateName);
58
        $this->seeNoSuggestions();
59
    }
60
61
    protected function seeNoSuggestions(): void
62
    {
63
        $I = $this->tester;
64
65
        $I->see('No price suggestions for this object');
66
        $I->see('We could not suggest any new prices of type "Certificate" for the selected object.');
67
        $I->see('Probably, they were already created earlier or this suggestion type is not compatible with this object type');
68
        $I->see('You can return back to plan');
69
    }
70
}
71