Passed
Pull Request — master (#4)
by
unknown
02:54
created

PagantisOscommerceTest::findById()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Test;
4
5
use Facebook\WebDriver\Interactions\WebDriverActions;
6
use Facebook\WebDriver\Remote\DesiredCapabilities;
7
use Facebook\WebDriver\Remote\RemoteWebDriver;
8
use Facebook\WebDriver\WebDriverBy;
9
use Facebook\WebDriver\WebDriverElement;
10
use Facebook\WebDriver\WebDriverExpectedCondition;
11
use Facebook\WebDriver\Remote\RemoteWebElement;
12
use Faker\Factory;
13
use PHPUnit\Framework\TestCase;
14
15
/**
16
 * Class PagantisOscommerceTest
17
 * @package Test
18
 */
19
abstract class PagantisOscommerceTest extends TestCase
20
{
21
    const OSCURL = 'http://oscommerce-test.docker:8096';
22
23
    const BACKOFFICE_FOLDER = '/admin';
24
25
    /**
26
     * Const title
27
     */
28
    const TITLE = 'Oscommerce';
29
    /**
30
     * Const admin_title
31
     */
32
    const ADMIN_TITLE = 'osCommerce Online Merchant Administration Tool';
33
34
    /**
35
     * @var array
36
     */
37
    protected $configuration = array(
38
        'username'      => 'root',
39
        'password'      => 'root',
40
        'publicKey'     => 'tk_fd53cd467ba49022e4f8215e',
41
        'secretKey'     => '21e57baa97459f6a',
42
        'birthdate'     => '05/05/2005',
43
        'firstname'     => 'Jøhn',
44
        'lastname'      => 'Dōè',
45
        'email'         => '[email protected]',
46
        'company'       => 'Digital Origin SL',
47
        'zip'           => '08023',
48
        'city'          => 'Barcelona',
49
        'phone'         => '600123123',
50
        'dni'           => '09422447Z',
51
        'extra'         => 'Free Finance',
52
        'address'       => 'Av.Diagonal 579',
53
        'methodName'    => 'Pagantis',
54
        'checkoutTitle' => 'Instant Financing',
55
        'defaultMinIns' => 3,
56
        'defaultMaxIns' => 12,
57
        'defaultSimulatorOpt' => 6,
58
        'confirmationMsg'=>'Pedido recibido',
59
        'checkoutDescription'=> 'Pay up to 12 comfortable installments with Pagantis',
60
        'enter' => 'Haz clic aquí para acceder'
61
    );
62
63
64
    /**
65
     * WooCommerce constructor.
66
     *
67
     * @param null   $name
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $name is correct as it would always require null to be passed?
Loading history...
68
     * @param array  $data
69
     * @param string $dataName
70
     */
71
    public function __construct($name = null, array $data = array(), $dataName = '')
72
    {
73
        $faker = Factory::create();
74
        $this->configuration['dni'] = $this->getDNI();
75
        $this->configuration['birthdate'] =
76
            $faker->numberBetween(1, 28) . '/' .
77
            $faker->numberBetween(1, 12). '/1975'
78
        ;
79
        $this->configuration['firstname'] = $faker->firstName;
80
        $this->configuration['lastname'] = $faker->lastName . ' ' . $faker->lastName;
81
        $this->configuration['company'] = $faker->company;
82
        $this->configuration['zip'] = '28'.$faker->randomNumber(3, true);
83
        $this->configuration['street'] = $faker->streetAddress;
84
        $this->configuration['phone'] = '6' . $faker->randomNumber(8);
85
        $this->configuration['email'] = date('ymd') . '@pagamastarde.com';
86
        parent::__construct($name, $data, $dataName);
87
    }
88
    /**
89
     * @return string
90
     */
91
    protected function getDNI()
92
    {
93
        $dni = '0000' . rand(pow(10, 4-1), pow(10, 4)-1);
94
        $value = (int) ($dni / 23);
95
        $value *= 23;
96
        $value= $dni - $value;
97
        $letter= "TRWAGMYFPDXBNJZSQVHLCKEO";
98
        $dniLetter= substr($letter, $value, 1);
99
        return $dni.$dniLetter;
100
    }
101
102
    /**
103
     * @var RemoteWebDriver
104
     */
105
    protected $webDriver;
106
107
    /**
108
     * Configure selenium
109
     */
110
    protected function setUp()
111
    {
112
        $this->webDriver = PagantisWebDriver::create(
113
            'http://localhost:4444/wd/hub',
114
            DesiredCapabilities::chrome(),
115
            90000,
116
            90000
117
        );
118
    }
119
120
    /**
121
     * @param $name
122
     *
123
     * @return RemoteWebElement
124
     */
125
    public function findByName($name)
126
    {
127
        return $this->webDriver->findElement(WebDriverBy::name($name));
128
    }
129
130
    /**
131
     * @param $id
132
     *
133
     * @return RemoteWebElement
134
     */
135
    public function findById($id)
136
    {
137
        return $this->webDriver->findElement(WebDriverBy::id($id));
138
    }
139
140
    /**
141
     * @param $className
142
     *
143
     * @return RemoteWebElement
144
     */
145
    public function findByClass($className)
146
    {
147
        return $this->webDriver->findElement(WebDriverBy::className($className));
148
    }
149
150
    /**
151
     * @param $css
152
     *
153
     * @return RemoteWebElement
154
     */
155
    public function findByCss($css)
156
    {
157
        return $this->webDriver->findElement(WebDriverBy::cssSelector($css));
158
    }
159
160
    /**
161
     * @param $xpath
162
     *
163
     * @return RemoteWebElement
164
     */
165
    public function findByXpath($xpath)
166
    {
167
        return $this->webDriver->findElement(WebDriverBy::xpath($xpath));
168
    }
169
170
    /**
171
     * @param $link
172
     *
173
     * @return RemoteWebElement
174
     */
175
    public function findByLinkText($link)
176
    {
177
        return $this->webDriver->findElement(WebDriverBy::partialLinkText($link));
178
    }
179
180
    /**
181
     * @param WebDriverExpectedCondition $condition
182
     * @return mixed
183
     * @throws \Facebook\WebDriver\Exception\NoSuchElementException
184
     * @throws \Facebook\WebDriver\Exception\TimeOutException
185
     */
186
    public function waitUntil(WebDriverExpectedCondition $condition)
187
    {
188
        return $this->webDriver->wait()->until($condition);
189
    }
190
191
    /**
192
     * @param WebDriverElement $element
193
     *
194
     * @return WebDriverElement
195
     */
196
    public function moveToElementAndClick(WebDriverElement $element)
197
    {
198
        $action = new WebDriverActions($this->webDriver);
199
        $action->moveToElement($element);
200
        $action->click($element);
201
        $action->perform();
202
203
        return $element;
204
    }
205
206
    /**
207
     * @param WebDriverElement $element
208
     *
209
     * @return WebDriverElement
210
     */
211
    public function getParent(WebDriverElement $element)
212
    {
213
        return $element->findElement(WebDriverBy::xpath(".."));
214
    }
215
216
    /**
217
     * Quit browser
218
     */
219
    protected function quit()
220
    {
221
        $this->webDriver->quit();
222
    }
223
}