1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pagantis\Pagantis\Test; |
4
|
|
|
|
5
|
|
|
use Facebook\WebDriver\Remote\DesiredCapabilities; |
6
|
|
|
use Facebook\WebDriver\Remote\RemoteWebDriver; |
7
|
|
|
use Facebook\WebDriver\WebDriverBy; |
8
|
|
|
use Faker\Factory; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class pagantisMagentoTest |
13
|
|
|
* @package Pagantis\Test |
14
|
|
|
*/ |
15
|
|
|
abstract class PagantisMagentoTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Magento Backoffice URL |
19
|
|
|
*/ |
20
|
|
|
const BACKOFFICE_FOLDER = '/admin'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Magento Logout URL |
24
|
|
|
*/ |
25
|
|
|
const LOGOUT_FOLDER = '/customer/account/logout/'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Magento Checkout URL |
29
|
|
|
*/ |
30
|
|
|
const CHECKOUT_FOLDER = '/checkout/'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Product name |
34
|
|
|
*/ |
35
|
|
|
const PRODUCT_NAME = 'Fusion Backpack'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Product quantity after |
39
|
|
|
*/ |
40
|
|
|
const PRODUCT_QTY_AFTER = 3; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Magento checkout Title |
44
|
|
|
*/ |
45
|
|
|
const CHECKOUT_TITLE = 'Checkout'; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Magento cart Title |
49
|
|
|
*/ |
50
|
|
|
const CART_TITLE = 'Cart'; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Magento success title |
54
|
|
|
*/ |
55
|
|
|
const SUCCESS_TITLE = 'Success Page'; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Magento order confirmation title |
59
|
|
|
*/ |
60
|
|
|
const ORDER_TITLE = 'Order #'; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Pagantis Order Title |
64
|
|
|
*/ |
65
|
|
|
const PAGANTIS_TITLE = 'Paga+Tarde'; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Already processed |
69
|
|
|
*/ |
70
|
|
|
const NOTFOUND_TITLE = 'Merchant order not found'; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Wrong order |
74
|
|
|
*/ |
75
|
|
|
const NOORDER_TITLE = 'We can not get the Pagantis identification in database'; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Magento Logout URL |
79
|
|
|
*/ |
80
|
|
|
const NOTIFICATION_FOLDER = '/pagantis/notify/'; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Magento Logout URL |
84
|
|
|
*/ |
85
|
|
|
const NOTIFICATION_PARAMETER = 'quoteId'; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Magento Log URL |
89
|
|
|
*/ |
90
|
|
|
const LOG_FOLDER = '/pagantis/Payment/Log'; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Magento Config URL |
94
|
|
|
*/ |
95
|
|
|
const CONFIG_FOLDER = '/pagantis/Payment/Config'; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @var array |
99
|
|
|
*/ |
100
|
|
|
protected $configuration = array( |
101
|
|
|
'backofficeUsername' => 'admin', |
102
|
|
|
'backofficePassword' => 'password123', |
103
|
|
|
'publicKey' => 'tk_fd53cd467ba49022e4f8215e', |
104
|
|
|
'secretKey' => '21e57baa97459f6a', |
105
|
|
|
'methodName' => 'Pagantis', |
106
|
|
|
'methodTitle' => 'Financiación instantánea', |
107
|
|
|
'defaultSimulatorOpt'=> 6, |
108
|
|
|
'defaultMinIns' => 3, |
109
|
|
|
'defaultMaxIns' => 12, |
110
|
|
|
'minAmount' => 70, |
111
|
|
|
'username' => '[email protected]', |
112
|
|
|
'password' => 'Prestashop_demo', |
113
|
|
|
'firstname' => 'John', |
114
|
|
|
'lastname' => 'Döe Martinez', |
115
|
|
|
'email' => null, |
116
|
|
|
'zip' => '08023', |
117
|
|
|
'city' => 'Barcelona', |
118
|
|
|
'street' => 'Av Diagonal 585, planta 7', |
119
|
|
|
'phone' => '600123123', |
120
|
|
|
'checkoutDescription'=> 'Paga hasta en 12' |
121
|
|
|
); |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @var RemoteWebDriver |
125
|
|
|
*/ |
126
|
|
|
protected $webDriver; |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Magento version provided for tests in commandline as an argument. |
130
|
|
|
* |
131
|
|
|
* @var String |
132
|
|
|
*/ |
133
|
|
|
protected $version; |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Magento version testing url port based on magento version |
137
|
|
|
* |
138
|
|
|
* @var array |
139
|
|
|
*/ |
140
|
|
|
protected $versionsPort = array( |
141
|
|
|
'22' => '8085', |
142
|
|
|
'23' => '8084', |
143
|
|
|
); |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* pagantisMagentoTest constructor. |
147
|
|
|
*/ |
148
|
|
|
public function __construct() |
149
|
|
|
{ |
150
|
|
|
$faker = Factory::create(); |
151
|
|
|
$this->configuration['dni'] = $this->getDNI(); |
152
|
|
|
$this->configuration['birthdate'] = |
153
|
|
|
$faker->numberBetween(1, 28) . '/' . |
154
|
|
|
$faker->numberBetween(1, 12). '/1975' |
155
|
|
|
; |
156
|
|
|
$this->configuration['firstname'] = $faker->firstName; |
157
|
|
|
$this->configuration['lastname'] = $faker->lastName . ' ' . $faker->lastName; |
158
|
|
|
$this->configuration['company'] = $faker->company; |
159
|
|
|
$this->configuration['zip'] = '28'.$faker->randomNumber(3, true); |
160
|
|
|
$this->configuration['street'] = $faker->streetAddress; |
161
|
|
|
$this->configuration['phone'] = '6' . $faker->randomNumber(8); |
162
|
|
|
$this->configuration['email'] = date('ymd') . '@pagantis.com'; |
163
|
|
|
|
164
|
|
|
if (!isset($_SERVER['argv']) || |
165
|
|
|
!isset($_SERVER['argv'][4]) || |
166
|
|
|
$_SERVER['argv'][4] != 'magentoVersion' || |
167
|
|
|
!isset($_SERVER['argv'][6]) || |
168
|
|
|
!isset($this->versionsPort[$_SERVER['argv'][6]]) |
169
|
|
|
) { |
170
|
|
|
throw new \Exception("No magentoVersion param provided or not valid for phpunit testing"); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
$this->version = $_SERVER['argv'][6]; |
174
|
|
|
$this->configuration['magentoUrl'] = 'http://magento'.$this->version.'-test.docker:'. |
175
|
|
|
$this->versionsPort[$this->version].'/index.php'; |
176
|
|
|
$this->configuration['email'] = "john.doe+".microtime(true)."@pagantis.com"; |
177
|
|
|
|
178
|
|
|
return parent::__construct(); |
|
|
|
|
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @return string |
183
|
|
|
*/ |
184
|
|
|
protected function getDNI() |
185
|
|
|
{ |
186
|
|
|
$dni = '0000' . rand(pow(10, 4-1), pow(10, 4)-1); |
187
|
|
|
$value = (int) ($dni / 23); |
188
|
|
|
$value *= 23; |
189
|
|
|
$value= $dni - $value; |
190
|
|
|
$letter= "TRWAGMYFPDXBNJZSQVHLCKEO"; |
191
|
|
|
$dniLetter= substr($letter, $value, 1); |
192
|
|
|
return $dni.$dniLetter; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Configure selenium |
197
|
|
|
*/ |
198
|
|
|
protected function setUp() |
199
|
|
|
{ |
200
|
|
|
$this->webDriver = PagantisWebDriver::create( |
201
|
|
|
'http://localhost:4444/wd/hub', |
202
|
|
|
DesiredCapabilities::chrome(), |
203
|
|
|
180000, |
204
|
|
|
180000 |
205
|
|
|
); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @param $name |
210
|
|
|
* |
211
|
|
|
* @return \Facebook\WebDriver\Remote\RemoteWebElement |
212
|
|
|
*/ |
213
|
|
|
public function findByName($name) |
214
|
|
|
{ |
215
|
|
|
return $this->webDriver->findElement(WebDriverBy::name($name)); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @param $id |
220
|
|
|
* |
221
|
|
|
* @return \Facebook\WebDriver\Remote\RemoteWebElement |
222
|
|
|
*/ |
223
|
|
|
public function findById($id) |
224
|
|
|
{ |
225
|
|
|
return $this->webDriver->findElement(WebDriverBy::id($id)); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* @param $className |
230
|
|
|
* |
231
|
|
|
* @return \Facebook\WebDriver\Remote\RemoteWebElement |
232
|
|
|
*/ |
233
|
|
|
public function findByClass($className) |
234
|
|
|
{ |
235
|
|
|
return $this->webDriver->findElement(WebDriverBy::className($className)); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @param $css |
240
|
|
|
* |
241
|
|
|
* @return \Facebook\WebDriver\Remote\RemoteWebElement |
242
|
|
|
*/ |
243
|
|
|
public function findByCss($css) |
244
|
|
|
{ |
245
|
|
|
return $this->webDriver->findElement(WebDriverBy::cssSelector($css)); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* @param $link |
250
|
|
|
* |
251
|
|
|
* @return \Facebook\WebDriver\Remote\RemoteWebElement |
252
|
|
|
*/ |
253
|
|
|
public function findByLinkText($link) |
254
|
|
|
{ |
255
|
|
|
return $this->webDriver->findElement(WebDriverBy::linkText($link)); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @param $link |
260
|
|
|
* |
261
|
|
|
* @return \Facebook\WebDriver\Remote\RemoteWebElement |
262
|
|
|
*/ |
263
|
|
|
public function findByPartialLinkText($link) |
264
|
|
|
{ |
265
|
|
|
return $this->webDriver->findElement(WebDriverBy::partialLinkText($link)); |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* Quit browser |
270
|
|
|
*/ |
271
|
|
|
protected function quit() |
272
|
|
|
{ |
273
|
|
|
$this->webDriver->quit(); |
274
|
|
|
} |
275
|
|
|
} |
276
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.