1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Test\Buy; |
4
|
|
|
|
5
|
|
|
use Facebook\WebDriver\WebDriverBy; |
6
|
|
|
use Facebook\WebDriver\WebDriverExpectedCondition; |
7
|
|
|
use Pagantis\ModuleUtils\Exception\AlreadyProcessedException; |
8
|
|
|
use Pagantis\ModuleUtils\Exception\NoIdentificationException; |
9
|
|
|
use Pagantis\ModuleUtils\Exception\QuoteNotFoundException; |
10
|
|
|
use Pagantis\SeleniumFormUtils\SeleniumHelper; |
11
|
|
|
use Httpful\Request; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class BuyRegisteredTest |
15
|
|
|
* @package Test\Buy |
16
|
|
|
* |
17
|
|
|
* @group oscommerce-buy-promoted |
18
|
|
|
*/ |
19
|
|
|
class BuyPromotedProductTest extends AbstractBuy |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var String $orderUrl |
23
|
|
|
*/ |
24
|
|
|
public $orderUrl; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Test Buy Registered |
28
|
|
|
*/ |
29
|
|
|
public function testBuyRegistered() |
30
|
|
|
{ |
31
|
|
|
$this->prepareProductAndCheckout(); |
32
|
|
|
$this->login(); |
33
|
|
|
$this->fillShippingMethod(); |
34
|
|
|
$this->fillPaymentMethod(); |
35
|
|
|
|
36
|
|
|
// get cart total price |
37
|
|
|
$button = WebDriverBy::xpath("//td[@class='main']/strong[1]"); |
38
|
|
|
$condition = WebDriverExpectedCondition::visibilityOfElementLocated($button); |
39
|
|
|
$this->waitUntil($condition); |
40
|
|
|
$cartPrice = $this->findByXpath("//td[@class='main']/strong[1]")->getText(); |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
// -------------------- |
44
|
|
|
$this->goToPagantis(); |
45
|
|
|
$this->verifyPagantis(); |
46
|
|
|
$this->commitPurchase(); |
47
|
|
|
$this->checkPurchaseReturn(self::CORRECT_PURCHASE_MESSAGE); |
48
|
|
|
$this->checkLastPurchaseStatus('Processing'); |
49
|
|
|
|
50
|
|
|
// get registered purchase amount |
51
|
|
|
$checkoutPrice = WebDriverBy::cssSelector( |
52
|
|
|
'.box-account.box-recent .data-table.orders .first .total .price' |
53
|
|
|
); |
54
|
|
|
$this->webDriver->wait()->until( |
55
|
|
|
WebDriverExpectedCondition::presenceOfElementLocated( |
56
|
|
|
$checkoutPrice |
57
|
|
|
) |
58
|
|
|
); |
59
|
|
|
$checkoutPrice = $this->webDriver->findElement($checkoutPrice)->getText(); |
60
|
|
|
//---------------------- |
61
|
|
|
|
62
|
|
|
$this->assertTrue(($cartPrice == $checkoutPrice)); |
63
|
|
|
$this->makeValidation(); |
64
|
|
|
$this->quit(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Login |
69
|
|
|
*/ |
70
|
|
|
public function login() |
71
|
|
|
{ |
72
|
|
|
$this->findByName('email_address')->clear()->sendKeys($this->configuration['customeremail']); |
73
|
|
|
$this->findByName('password')->clear()->sendKeys($this->configuration['customerpwd']); |
74
|
|
|
|
75
|
|
|
$buttonSearch = WebDriverBy::id('tdb1'); |
76
|
|
|
$condition = WebDriverExpectedCondition::visibilityOfElementLocated($buttonSearch); |
77
|
|
|
$this->waitUntil($condition); |
78
|
|
|
$buttonElement = $this->webDriver->findElement($buttonSearch); |
79
|
|
|
$this->webDriver->executeScript("arguments[0].scrollIntoView(true);", array($buttonElement)); |
80
|
|
|
$buttonElement->click(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Commit Purchase |
85
|
|
|
* @throws \Exception |
86
|
|
|
*/ |
87
|
|
|
public function commitPurchase() |
88
|
|
|
{ |
89
|
|
|
|
90
|
|
|
$condition = WebDriverExpectedCondition::titleContains(self::PAGANTIS_TITLE); |
91
|
|
|
$this->webDriver->wait(300)->until($condition, $this->webDriver->getCurrentURL()); |
92
|
|
|
$this->assertTrue((bool)$condition, "PR32"); |
93
|
|
|
|
94
|
|
|
// complete the purchase with redirect |
95
|
|
|
SeleniumHelper::finishForm($this->webDriver); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Verify Pagantis |
100
|
|
|
* |
101
|
|
|
* @throws \Exception |
102
|
|
|
*/ |
103
|
|
|
public function verifyPagantis() |
104
|
|
|
{ |
105
|
|
|
$condition = WebDriverExpectedCondition::titleContains(self::PAGANTIS_TITLE); |
106
|
|
|
$this->webDriver->wait(300)->until($condition, $this->webDriver->getCurrentURL()); |
107
|
|
|
$this->assertTrue((bool)$condition, $this->webDriver->getCurrentURL()); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function makeValidation() |
111
|
|
|
{ |
112
|
|
|
$this->checkConcurrency(); |
113
|
|
|
$this->checkPagantisOrderId(); |
114
|
|
|
$this->checkAlreadyProcessed(); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Check if with a empty parameter called order-received we can get a QuoteNotFoundException |
120
|
|
|
*/ |
121
|
|
|
protected function checkConcurrency() |
122
|
|
|
{ |
123
|
|
|
$notifyUrl = self::OSCURL.self::NOTIFICATION_FOLDER.'?order='; |
124
|
|
|
$this->assertNotEmpty($notifyUrl, $notifyUrl); |
125
|
|
|
$response = Request::post($notifyUrl)->expects('json')->send(); |
126
|
|
|
$this->assertNotEmpty($response->body->result, $response); |
127
|
|
|
$this->assertNotEmpty($response->body->status_code, $response); |
128
|
|
|
$this->assertNotEmpty($response->body->timestamp, $response); |
129
|
|
|
$this->assertContains( |
130
|
|
|
QuoteNotFoundException::ERROR_MESSAGE, |
131
|
|
|
$response->body->result, |
132
|
|
|
"PR=>".$response->body->result |
133
|
|
|
); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Check if with a parameter called order-received set to a invalid identification, |
138
|
|
|
* we can get a NoIdentificationException |
139
|
|
|
*/ |
140
|
|
|
protected function checkPagantisOrderId() |
141
|
|
|
{ |
142
|
|
|
$orderId=0; |
143
|
|
|
$notifyUrl = self::OSCURL.self::NOTIFICATION_FOLDER.'?order='.$orderId; |
144
|
|
|
$this->assertNotEmpty($notifyUrl, $notifyUrl); |
145
|
|
|
$response = Request::post($notifyUrl)->expects('json')->send(); |
146
|
|
|
$this->assertNotEmpty($response->body->result, $response); |
147
|
|
|
$this->assertNotEmpty($response->body->status_code, $response); |
148
|
|
|
$this->assertNotEmpty($response->body->timestamp, $response); |
149
|
|
|
$this->assertEquals( |
150
|
|
|
$response->body->merchant_order_id, |
151
|
|
|
$orderId, |
152
|
|
|
$response->body->merchant_order_id.'!='. $orderId |
153
|
|
|
); |
154
|
|
|
$this->assertContains( |
155
|
|
|
NoIdentificationException::ERROR_MESSAGE, |
156
|
|
|
$response->body->result, |
157
|
|
|
"PR=>".$response->body->result |
158
|
|
|
); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Check if re-launching the notification we can get a AlreadyProcessedException |
163
|
|
|
* |
164
|
|
|
* @throws \Httpful\Exception\ConnectionErrorException |
165
|
|
|
*/ |
166
|
|
|
protected function checkAlreadyProcessed() |
167
|
|
|
{ |
168
|
|
|
$notifyUrl = self::OSCURL.self::NOTIFICATION_FOLDER.'?order=145000008'; |
169
|
|
|
$response = Request::post($notifyUrl)->expects('json')->send(); |
170
|
|
|
$this->assertNotEmpty($response->body->result, $response); |
171
|
|
|
$this->assertNotEmpty($response->body->status_code, $response); |
172
|
|
|
$this->assertNotEmpty($response->body->timestamp, $response); |
173
|
|
|
$this->assertNotEmpty($response->body->merchant_order_id, $response); |
174
|
|
|
$this->assertNotEmpty($response->body->pagantis_order_id, $response); |
175
|
|
|
$this->assertContains( |
176
|
|
|
AlreadyProcessedException::ERROR_MESSAGE, |
177
|
|
|
$response->body->result, |
178
|
|
|
"PR51=>".$response->body->result |
179
|
|
|
); |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|