Passed
Pull Request — master (#37)
by
unknown
04:18
created

PagantisMagentoTest   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 265
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 87
c 2
b 0
f 0
dl 0
loc 265
rs 10
wmc 16
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
     * @var String
137
     */
138
    protected $environment;
139
140
    /**
141
     * Magento version testing url port based on magento version
142
     *
143
     * @var array
144
     */
145
    protected $versionsPort = array(
146
        '22' => array('test'=>'8085', 'dev' =>'8086'),
147
        '23' => array('test'=>'8084', 'dev' =>'8087')
148
    );
149
150
    /**
151
     * pagantisMagentoTest constructor.
152
     */
153
    public function __construct()
154
    {
155
        $faker = Factory::create();
156
        $this->configuration['dni'] = $this->getDNI();
157
        $this->configuration['birthdate'] =
158
            $faker->numberBetween(1, 28) . '/' .
159
            $faker->numberBetween(1, 12). '/1975'
160
        ;
161
        $this->configuration['firstname'] = $faker->firstName;
162
        $this->configuration['lastname'] = $faker->lastName . ' ' . $faker->lastName;
163
        $this->configuration['company'] = $faker->company;
164
        $this->configuration['zip'] = '28'.$faker->randomNumber(3, true);
165
        $this->configuration['street'] = $faker->streetAddress;
166
        $this->configuration['phone'] = '6' . $faker->randomNumber(8);
167
        $this->configuration['email'] = date('ymd') . '@pagantis.com';
168
169
        if (!isset($_SERVER['argv']) ||
170
            !isset($_SERVER['argv'][4]) ||
171
            $_SERVER['argv'][4] != 'magentoVersion' ||
172
            !isset($_SERVER['argv'][6]) ||
173
            !isset($this->versionsPort[$_SERVER['argv'][6]])
174
        ) {
175
            throw new \Exception("No magentoVersion param provided or not valid for phpunit testing");
176
        }
177
178
        $this->version = $_SERVER['argv'][6];
179
        $this->environment = isset($_SERVER['argv'][8]) ? ($_SERVER['argv'][8]) : 'test';
180
        $this->configuration['magentoUrl'] = 'http://magento'.$this->version.'-'.$this->environment.'.docker:'.
181
            $this->versionsPort[$this->version][$this->environment].'/index.php';
182
        $this->configuration['email'] = "john.doe+".microtime(true)."@pagantis.com";
183
184
        return parent::__construct();
185
    }
186
187
    /**
188
     * @return string
189
     */
190
    protected function getDNI()
191
    {
192
        $dni = '0000' . rand(pow(10, 4-1), pow(10, 4)-1);
193
        $value = (int) ($dni / 23);
194
        $value *= 23;
195
        $value= $dni - $value;
196
        $letter= "TRWAGMYFPDXBNJZSQVHLCKEO";
197
        $dniLetter= substr($letter, $value, 1);
198
        return $dni.$dniLetter;
199
    }
200
201
    /**
202
     * Configure selenium
203
     */
204
    protected function setUp()
205
    {
206
        $this->webDriver = PagantisWebDriver::create(
207
            'http://localhost:4444/wd/hub',
208
            DesiredCapabilities::chrome(),
209
            180000,
210
            180000
211
        );
212
    }
213
214
    /**
215
     * @param $name
216
     *
217
     * @return \Facebook\WebDriver\Remote\RemoteWebElement
218
     */
219
    public function findByName($name)
220
    {
221
        return $this->webDriver->findElement(WebDriverBy::name($name));
222
    }
223
224
    /**
225
     * @param $id
226
     *
227
     * @return \Facebook\WebDriver\Remote\RemoteWebElement
228
     */
229
    public function findById($id)
230
    {
231
        return $this->webDriver->findElement(WebDriverBy::id($id));
232
    }
233
234
    /**
235
     * @param $className
236
     *
237
     * @return \Facebook\WebDriver\Remote\RemoteWebElement
238
     */
239
    public function findByClass($className)
240
    {
241
        return $this->webDriver->findElement(WebDriverBy::className($className));
242
    }
243
244
    /**
245
     * @param $css
246
     *
247
     * @return \Facebook\WebDriver\Remote\RemoteWebElement
248
     */
249
    public function findByCss($css)
250
    {
251
        return $this->webDriver->findElement(WebDriverBy::cssSelector($css));
252
    }
253
254
    /**
255
     * @param $link
256
     *
257
     * @return \Facebook\WebDriver\Remote\RemoteWebElement
258
     */
259
    public function findByLinkText($link)
260
    {
261
        return $this->webDriver->findElement(WebDriverBy::linkText($link));
262
    }
263
264
    /**
265
     * @param $link
266
     *
267
     * @return \Facebook\WebDriver\Remote\RemoteWebElement
268
     */
269
    public function findByPartialLinkText($link)
270
    {
271
        return $this->webDriver->findElement(WebDriverBy::partialLinkText($link));
272
    }
273
274
    /**
275
     * Quit browser
276
     */
277
    protected function quit()
278
    {
279
        $this->webDriver->quit();
280
    }
281
}
282