Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 53ac028

Browse files
author
Dmytro Yushkin
committed
MAGETWO-63855: Create functional automated for complete Signifyd flow
1 parent f4cc47d commit 53ac028

File tree

9 files changed

+224
-8
lines changed

9 files changed

+224
-8
lines changed

Test/Block/Sanbox/CaseInfo.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,60 @@
66
namespace Magento\Signifyd\Test\Block\Sanbox;
77

88
use Magento\Mtf\Block\Block;
9+
use Magento\Mtf\Client\Locator;
910

1011
class CaseInfo extends Block
1112
{
1213
private $flagGoodButton = 'button.flag-case-good';
14+
private $cvvResponseDescription = '//span[contains(@ng-bind, "caseOrderSummary.cvvResponseDescription")]';
15+
private $cvvResponseCode = '//span[contains(@ng-bind, "caseOrderSummary.cvvResponseCode")]';
16+
private $avsResponseDescription = '//span[contains(@ng-bind, "caseOrderSummary.avsResponseDescription")]';
17+
private $avsResponseCode = '//span[contains(@ng-bind, "caseOrderSummary.avsResponseCode")]';
18+
private $orderId = '//span[contains(@ng-bind, "currentCase.caseIdDisplay")]';
19+
private $orderAmount = '//span[contains(@ng-bind, "currentCase.orderAmount")]';
20+
private $cardHolder = '//a[contains(@data-dropdown, "peopleLinks0")]//span';
21+
private $billingAddress = '//a[contains(@data-dropdown, "streetLinks0")]';
1322

1423
public function flagCaseGood()
1524
{
1625
$this->_rootElement->find($this->flagGoodButton)->click();
1726
}
27+
28+
public function getCvvResponse()
29+
{
30+
return sprintf(
31+
'%s (%s)',
32+
$this->_rootElement->find($this->cvvResponseDescription, Locator::SELECTOR_XPATH)->getText(),
33+
$this->_rootElement->find($this->cvvResponseCode, Locator::SELECTOR_XPATH)->getText()
34+
);
35+
}
36+
37+
public function getAvsResponse()
38+
{
39+
return sprintf(
40+
'%s (%s)',
41+
$this->_rootElement->find($this->avsResponseDescription, Locator::SELECTOR_XPATH)->getText(),
42+
$this->_rootElement->find($this->avsResponseCode, Locator::SELECTOR_XPATH)->getText()
43+
);
44+
}
45+
46+
public function getOrderId()
47+
{
48+
return $this->_rootElement->find($this->orderId, Locator::SELECTOR_XPATH)->getText();
49+
}
50+
51+
public function getOrderAmount()
52+
{
53+
return $this->_rootElement->find($this->orderAmount, Locator::SELECTOR_XPATH)->getText();
54+
}
55+
56+
public function getCardHolder()
57+
{
58+
return $this->_rootElement->find($this->cardHolder, Locator::SELECTOR_XPATH)->getText();
59+
}
60+
61+
public function getBillingAddress()
62+
{
63+
return $this->_rootElement->find($this->billingAddress, Locator::SELECTOR_XPATH)->getText();
64+
}
1865
}

Test/Block/Sanbox/CaseSearch.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class CaseSearch extends Form
2121

2222
public function fillSearchCriteria($searchCriteria)
2323
{
24+
$this->waitForElementVisible($this->searchInput);
2425
$this->_rootElement->find($this->searchInput)->setValue($searchCriteria);
2526
}
2627

Test/Constraint/AssertCaseInfo.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Signifyd\Test\Constraint;
7+
8+
use Magento\Customer\Test\Fixture\Address;
9+
use Magento\Customer\Test\Fixture\Customer;
10+
use Magento\Mtf\Constraint\AbstractConstraint;
11+
use Magento\Sales\Test\Fixture\OrderInjectable;
12+
use Magento\Signifyd\Test\Page\Sandbox\SignifydCases;
13+
14+
class AssertCaseInfo extends AbstractConstraint
15+
{
16+
private $cvvResponse = 'CVV2 Match (M)';
17+
private $avsResponse = 'Full match (Y)';
18+
19+
public function processAssert(
20+
SignifydCases $signifydCases,
21+
Customer $customer,
22+
OrderInjectable $order,
23+
Address $billingAddress,
24+
array $cartPrice
25+
) {
26+
\PHPUnit_Framework_Assert::assertEquals(
27+
$this->cvvResponse,
28+
$signifydCases->getCaseInfoBlock()->getCvvResponse()
29+
);
30+
31+
\PHPUnit_Framework_Assert::assertEquals(
32+
$this->avsResponse,
33+
$signifydCases->getCaseInfoBlock()->getAvsResponse()
34+
);
35+
36+
\PHPUnit_Framework_Assert::assertEquals(
37+
$order->getId(),
38+
$signifydCases->getCaseInfoBlock()->getOrderId()
39+
);
40+
41+
\PHPUnit_Framework_Assert::assertEquals(
42+
number_format($cartPrice['grand_total'], 2),
43+
$signifydCases->getCaseInfoBlock()->getOrderAmount()
44+
);
45+
46+
\PHPUnit_Framework_Assert::assertEquals(
47+
sprintf('%s %s', $customer->getFirstname(), $customer->getLastname()),
48+
$signifydCases->getCaseInfoBlock()->getCardHolder()
49+
);
50+
51+
\PHPUnit_Framework_Assert::assertContains(
52+
$billingAddress->getStreet(),
53+
$signifydCases->getCaseInfoBlock()->getBillingAddress()
54+
);
55+
}
56+
57+
/**
58+
* Returns a string representation of the object.
59+
*
60+
* @return string
61+
*/
62+
public function toString()
63+
{
64+
return 'Case information is correct.';
65+
}
66+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Signifyd\Test\Constraint;
7+
8+
use Magento\Mtf\Constraint\AbstractConstraint;
9+
use Magento\Sales\Test\Page\Adminhtml\OrderIndex;
10+
use Magento\Sales\Test\Page\Adminhtml\SalesOrderView;
11+
12+
class AssertGuaranteeCancelInCommentsHistory extends AbstractConstraint
13+
{
14+
/**
15+
* Pattern of message about canceled amount in order.
16+
*/
17+
private $guaranteeCancelPattern = 'Case Update: Case guarantee has been cancelled.';
18+
19+
/**
20+
* @param SalesOrderView $salesOrderView
21+
* @param OrderIndex $salesOrder
22+
* @param string $orderId
23+
* @return void
24+
*/
25+
public function processAssert(
26+
SalesOrderView $salesOrderView,
27+
OrderIndex $salesOrder,
28+
$orderId
29+
) {
30+
$salesOrder->open();
31+
$salesOrder->getSalesOrderGrid()->searchAndOpen(['id' => $orderId]);
32+
33+
/** @var \Magento\Sales\Test\Block\Adminhtml\Order\View\Tab\Info $infoTab */
34+
$infoTab = $salesOrderView->getOrderForm()->openTab('info')->getTab('info');
35+
$comments = $infoTab->getCommentsHistoryBlock()->getComments();
36+
37+
foreach ($comments as $key => $comment) {
38+
if (strstr($comment['comment'], 'Case Update') === false) {
39+
unset($comments[$key]);
40+
}
41+
}
42+
$comments = array_values($comments);
43+
44+
\PHPUnit_Framework_Assert::assertRegExp(
45+
$this->guaranteeCancelPattern,
46+
$comments[0]['comment'],
47+
'Incorrect guarantee cancel for the order #' . $orderId
48+
);
49+
}
50+
51+
/**
52+
* Returns a string representation of the object.
53+
*
54+
* @return string
55+
*/
56+
public function toString()
57+
{
58+
return "Message about guarantee cancel is available in Comments History section.";
59+
}
60+
}

Test/Repository/SandboxMerchant.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<repository class="Magento\Signifyd\Test\Repository\SandboxMerchant">
1010
<dataset name="sandbox_default">
1111
<field name="email" xsi:type="string">SIGNIFYD_EMAIL</field>
12-
<field name="password" xsi:type="string">SIGNIFYD_EMAIL</field>
12+
<field name="password" xsi:type="string">SIGNIFYD_PASSWORD</field>
1313
</dataset>
1414
</repository>
1515
</config>

Test/TestCase/OnePageCheckoutWithBraintreeTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class OnePageCheckoutWithBraintreeTest extends Scenario
2424
*
2525
* @return void
2626
*/
27-
public function test() {
27+
public function test()
28+
{
2829
$this->executeScenario();
2930
}
3031
}

Test/TestCase/OnePageCheckoutWithBraintreeTest.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99
<testCase name="Magento\Signifyd\Test\TestCase\OnePageCheckoutWithBraintreeTest" summary="One page checkout with Braintree payment method.">
1010
<variation name="OnePageCheckoutWithBraintreeVariation1" summary="Registered Checkout within Braintree Credit Card from Storefront with Signifyd" ticketId="MAGETWO-62120">
1111
<data name="products/0" xsi:type="string">catalogProductSimple::product_10_dollar</data>
12+
<data name="prices/grand_total" xsi:type="string">15.00</data>
13+
<data name="cartPrice/grand_total" xsi:type="string">15</data>
14+
<data name="cartPrice/sub_total" xsi:type="string">10</data>
15+
<data name="cartPrice/shipping_price" xsi:type="number">5</data>
1216
<data name="checkoutMethod" xsi:type="string">login</data>
1317
<data name="customer/dataset" xsi:type="string">signifyd_approve_us_customer</data>
18+
<data name="billingAddress/dataset" xsi:type="string">signifyd_approve_us_shipping_address</data>
1419
<data name="shippingAddress/dataset" xsi:type="string">signifyd_approve_us_shipping_address</data>
1520
<data name="shipping/shipping_service" xsi:type="string">Flat Rate</data>
1621
<data name="shipping/shipping_method" xsi:type="string">Fixed</data>
@@ -27,6 +32,10 @@
2732
<constraint name="Magento\Sales\Test\Constraint\AssertOrderStatusIsCorrect" />
2833
<constraint name="Magento\Sales\Test\Constraint\AssertOrderGrandTotal" />
2934
<constraint name="Magento\Signifyd\Test\Constraint\AssertSignifydCaseInCommentsHistory" />
35+
<constraint name="Magento\Sales\Test\Constraint\AssertOrderCancelSuccessMessage" />
36+
<constraint name="Magento\Sales\Test\Constraint\AssertOrderStatusIsCanceled" />
37+
<constraint name="Magento\Sales\Test\Constraint\AssertCancelInCommentsHistory" />
38+
<constraint name="Magento\Signifyd\Test\Constraint\AssertGuaranteeCancelInCommentsHistory" />
3039
</variation>
3140
</testCase>
3241
</config>

Test/TestStep/ObserveSignifydCaseStep.php

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
*/
66
namespace Magento\Signifyd\Test\TestStep;
77

8+
use Magento\Customer\Test\Fixture\Address;
89
use Magento\Customer\Test\Fixture\Customer;
910
use Magento\Mtf\TestStep\TestStepInterface;
11+
use Magento\Sales\Test\Fixture\OrderInjectable;
12+
use Magento\Signifyd\Test\Constraint\AssertCaseInfo;
1013
use Magento\Signifyd\Test\Fixture\SandboxMerchant;
1114
use Magento\Signifyd\Test\Page\Sandbox\SignifydCases;
1215
use Magento\Signifyd\Test\Page\Sandbox\SignifydLogin;
@@ -35,22 +38,51 @@ class ObserveSignifydCaseStep implements TestStepInterface
3538
*/
3639
private $customer;
3740

41+
/**
42+
* @var AssertCaseInfo
43+
*/
44+
private $assertCaseInfo;
45+
46+
/**
47+
* @var OrderInjectable
48+
*/
49+
private $order;
50+
51+
/**
52+
* @var array
53+
*/
54+
private $cartPrice;
55+
/**
56+
* @var Address
57+
*/
58+
private $billingAddress;
59+
3860
/**
3961
* @param SandboxMerchant $sandboxMerchant
4062
* @param SignifydLogin $signifydLogin
4163
* @param SignifydCases $signifydCases
4264
* @param Customer $customer
65+
* @param AssertCaseInfo $assertCaseInfo
66+
* @param OrderInjectable $order
4367
*/
4468
public function __construct(
4569
SandboxMerchant $sandboxMerchant,
4670
SignifydLogin $signifydLogin,
4771
SignifydCases $signifydCases,
48-
Customer $customer
72+
Customer $customer,
73+
AssertCaseInfo $assertCaseInfo,
74+
OrderInjectable $order,
75+
Address $billingAddress,
76+
array $cartPrice
4977
) {
5078
$this->sandboxMerchant = $sandboxMerchant;
5179
$this->signifydLogin = $signifydLogin;
5280
$this->signifydCases = $signifydCases;
5381
$this->customer = $customer;
82+
$this->assertCaseInfo = $assertCaseInfo;
83+
$this->order = $order;
84+
$this->cartPrice = $cartPrice;
85+
$this->billingAddress = $billingAddress;
5486
}
5587

5688
/**
@@ -64,12 +96,13 @@ public function run()
6496
$this->signifydLogin->getLoginBlock()->fill($this->sandboxMerchant);
6597
$this->signifydLogin->getLoginBlock()->sandboxLogin();
6698

67-
$this->signifydCases->getCaseSearchBlock()->waitForElementVisible('#queueSearchBar');
6899
$this->signifydCases->getCaseSearchBlock()
69100
->fillSearchCriteria($this->customer->getFirstname() . ' ' . $this->customer->getLastname());
70101
$this->signifydCases->getCaseSearchBlock()->searchCase();
71102

72103
$this->signifydCases->getCaseSearchBlock()->selectCase();
73104
$this->signifydCases->getCaseInfoBlock()->flagCaseGood();
105+
106+
$this->assertCaseInfo->processAssert($this->signifydCases, $this->customer, $this->order, $this->billingAddress, $this->cartPrice);
74107
}
75108
}

Test/etc/testcase.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
<step name="selectPaymentMethod" module="Magento_Checkout" next="fillBillingInformation" />
2020
<step name="fillBillingInformation" module="Magento_Checkout" next="placeOrder" />
2121
<step name="placeOrder" module="Magento_Checkout" next="observeSignifydCase" />
22-
<step name="observeSignifydCase" module="Magento_Signifyd" next="openSalesOrders" />
23-
<step name="openSalesOrders" module="Magento_Sales" next="openOrder" />
24-
<step name="openOrder" module="Magento_Sales" next="deleteCustomer" />
25-
<step name="deleteCustomer" module="Magento_Customer" />
22+
<step name="observeSignifydCase" module="Magento_Signifyd" next="openOrder" />
23+
<step name="openOrder" module="Magento_Sales" next="cancelOrder" />
24+
<step name="cancelOrder" module="Magento_Sales" />
2625
</scenario>
2726
</config>

0 commit comments

Comments
 (0)