Skip to content

Commit

Permalink
Merge pull request #233 from magento-mpi/MAGETWO-45682
Browse files Browse the repository at this point in the history
[MPI] Sprint 73 Functional tests and Bugfix
  • Loading branch information
dkvashninbay committed Dec 9, 2015
2 parents 4876b4f + f39b555 commit 2f74e09
Show file tree
Hide file tree
Showing 36 changed files with 772 additions and 208 deletions.
6 changes: 5 additions & 1 deletion app/code/Magento/Paypal/Model/Hostedpro/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,11 @@ protected function getAmountData(Order $order)
*/
private function getNonTaxableAmount(Order $order)
{
// PayPal denied transaction with 0 amount
$subtotal = $order->getBaseSubtotal() ? : $order->getPayment()->getBaseAmountAuthorized();

return [
'subtotal' => $this->formatPrice($order->getBaseSubtotal()),
'subtotal' => $this->formatPrice($subtotal),
'total' => $this->formatPrice($order->getPayment()->getBaseAmountAuthorized()),
'tax' => $this->formatPrice($order->getBaseTaxAmount()),
'shipping' => $this->formatPrice($order->getBaseShippingAmount()),
Expand All @@ -198,6 +201,7 @@ private function getNonTaxableAmount(Order $order)
private function getTaxableAmount(Order $order)
{
$amount = $this->formatPrice($order->getPayment()->getBaseAmountAuthorized());

return [
'amount' => $amount,
'subtotal' => $amount // subtotal always is required
Expand Down
64 changes: 64 additions & 0 deletions app/code/Magento/Paypal/Test/Unit/Model/Hostedpro/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,63 @@ public function testSetAmountWithoutTax($total, $subtotal, $tax, $shipping, $dis
static::assertEquals($expectation, $this->_model->getData());
}

/**
* @covers \Magento\Paypal\Model\Hostedpro\Request::setAmount()
* @param $total
* @param $subtotal
* @param $tax
* @param $shipping
* @param $discount
* @dataProvider amountWithoutTaxZeroSubtotalDataProvider
*/
public function testSetAmountWithoutTaxZeroSubtotal($total, $subtotal, $tax, $shipping, $discount)
{
$expectation = [
'subtotal' => $total,
'total' => $total,
'tax' => $tax,
'shipping' => $shipping,
'discount' => abs($discount)
];

static::assertFalse($this->taxData->priceIncludesTax());

$payment = $this->getMockBuilder(Payment::class)
->disableOriginalConstructor()
->getMock();

$order = $this->getMockBuilder(Order::class)
->disableOriginalConstructor()
->getMock();

$payment->expects(static::exactly(2))
->method('getBaseAmountAuthorized')
->willReturn($total);

$order->expects(static::exactly(2))
->method('getPayment')
->willReturn($payment);

$order->expects(static::once())
->method('getBaseDiscountAmount')
->willReturn($discount);

$order->expects(static::once())
->method('getBaseTaxAmount')
->willReturn($tax);

$order->expects(static::once())
->method('getBaseShippingAmount')
->willReturn($shipping);

$order->expects(static::once())
->method('getBaseSubtotal')
->willReturn($subtotal);
$this->_model->setAmount($order);

static::assertEquals($expectation, $this->_model->getData());
}

/**
* @covers \Magento\Paypal\Model\Hostedpro\Request::setAmount()
*/
Expand Down Expand Up @@ -313,4 +370,11 @@ public function amountWithoutTaxDataProvider()
['total' => 5.00, 'subtotal' => 10.00, 'tax' => 0.00, 'shipping' => 20.00, 'discount' => -25.00],
];
}

public function amountWithoutTaxZeroSubtotalDataProvider()
{
return [
['total' => 10.00, 'subtotal' => 0.00, 'tax' => 0.00, 'shipping' => 20.00, 'discount' => 0.00],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* See COPYING.txt for license details.
*/

namespace Magento\Authorizenet\Test\Block\Authorizenet\Form;
namespace Magento\Authorizenet\Test\Block\Form;

use Magento\Payment\Test\Block\Form\Cc as CreditCard;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
<mapping strict="1">
<wrapper>payment</wrapper>
<fields>
<cc_type>
<input>select</input>
</cc_type>
<cc_number />
<cc_exp_month>
<input>select</input>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/fixture.xsd">
<fixture name="credit_card_authorizenet"
module="Magento_Authorizenet"
type="virtual"
entity_type="credit_card_authorizenet"
repository_class="Magento\Authorizenet\Test\Repository\CreditCard"
class="Magento\Authorizenet\Test\Fixture\CreditCardAuthorizenet">
<field name="cc_number" />
<field name="cc_exp_month" />
<field name="cc_exp_year" />
<field name="cc_cid" />
</fixture>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,63 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/Magento/Mtf/Repository/etc/repository.xsd">
<repository class="Magento\Config\Test\Repository\ConfigData">
<dataset name="authorizenet">
<field name="payment/authorizenet/active" xsi:type="array">
<field name="payment/authorizenet_directpost/active" xsi:type="array">
<item name="scope" xsi:type="string">payment</item>
<item name="scope_id" xsi:type="number">1</item>
<item name="label" xsi:type="string">Yes</item>
<item name="value" xsi:type="number">1</item>
</field>
<field name="payment/authorizenet/login" xsi:type="array">
<field name="payment/authorizenet_directpost/login" xsi:type="array">
<item name="scope" xsi:type="string">payment</item>
<item name="scope_id" xsi:type="number">1</item>
<item name="label" xsi:type="string"/>
<item name="value" xsi:type="string">PAYMENT_AUTHORIZENET_LOGIN</item>
</field>
<field name="payment/authorizenet/trans_key" xsi:type="array">
<field name="payment/authorizenet_directpost/trans_key" xsi:type="array">
<item name="scope" xsi:type="string">payment</item>
<item name="scope_id" xsi:type="number">1</item>
<item name="label" xsi:type="string"/>
<item name="value" xsi:type="string">PAYMENT_AUTHORIZENET_TRANS_KEY</item>
</field>
<field name="payment/authorizenet/test" xsi:type="array">
<field name="payment/authorizenet_directpost/trans_md5" xsi:type="array">
<item name="scope" xsi:type="string">payment</item>
<item name="scope_id" xsi:type="number">1</item>
<item name="label" xsi:type="string"/>
<item name="value" xsi:type="string">PAYMENT_AUTHORIZENET_TRANS_MD5</item>
</field>
<field name="payment/authorizenet_directpost/test" xsi:type="array">
<item name="scope" xsi:type="string">payment</item>
<item name="scope_id" xsi:type="number">1</item>
<item name="label" xsi:type="string">No</item>
<item name="value" xsi:type="number">0</item>
</field>
<field name="payment/authorizenet/cgi_url" xsi:type="array">
<field name="payment/authorizenet_directpost/cgi_url" xsi:type="array">
<item name="scope" xsi:type="string">payment</item>
<item name="scope_id" xsi:type="number">1</item>
<item name="label" xsi:type="string"/>
<item name="value" xsi:type="string">https://test.authorize.net/gateway/transact.dll</item>
</field>
<field name="payment/authorizenet/debug" xsi:type="array">
<field name="payment/authorizenet_directpost/cgi_url_td" xsi:type="array">
<item name="scope" xsi:type="string">payment</item>
<item name="scope_id" xsi:type="number">1</item>
<item name="label" xsi:type="string"/>
<item name="value" xsi:type="string">https://apitest.authorize.net/xml/v1/request.api</item>
</field>
<field name="payment/authorizenet_directpost/debug" xsi:type="array">
<item name="scope" xsi:type="string">payment</item>
<item name="scope_id" xsi:type="number">1</item>
<item name="label" xsi:type="string">Yes</item>
<item name="value" xsi:type="number">1</item>
</field>
<field name="payment/authorizenet/useccv" xsi:type="array">
<field name="payment/authorizenet_directpost/useccv" xsi:type="array">
<item name="scope" xsi:type="string">payment</item>
<item name="scope_id" xsi:type="number">1</item>
<item name="label" xsi:type="string">Yes</item>
<item name="value" xsi:type="number">1</item>
</field>
</dataset>
<dataset name="authorizenet_rollback">
<field name="payment/authorizenet/active" xsi:type="array">
<field name="payment/authorizenet_directpost/active" xsi:type="array">
<item name="scope" xsi:type="string">payment</item>
<item name="scope_id" xsi:type="number">1</item>
<item name="label" xsi:type="string">No</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/Magento/Mtf/Repository/etc/repository.xsd">
<repository class="Magento\Payment\Test\Repository\CreditCard">
<repository class="Magento\Authorizenet\Test\Repository\CreditCard">
<dataset name="visa_authorizenet">
<field name="cc_type" xsi:type="string">Visa</field>
<field name="cc_number" xsi:type="string">4007000000027</field>
<field name="cc_number" xsi:type="string">4111111111111111</field>
<field name="cc_exp_month" xsi:type="string">01 - January</field>
<field name="cc_exp_year" xsi:type="string">2016</field>
<field name="cc_exp_year" xsi:type="string">2020</field>
<field name="cc_cid" xsi:type="string">123</field>
</dataset>
</repository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@
<data name="shipping/shipping_service" xsi:type="string">Flat Rate</data>
<data name="shipping/shipping_method" xsi:type="string">Fixed</data>
<data name="prices" xsi:type="array">
<item name="grandTotal" xsi:type="string">156.81</item>
<item name="grandTotal" xsi:type="string">145.98</item>
</data>
<data name="payment/method" xsi:type="string">authorizenet</data>
<data name="creditCard/dataset" xsi:type="string">visa_default</data>
<data name="creditCardClass" xsi:type="string">credit_card_authorizenet</data>
<data name="payment/method" xsi:type="string">authorizenet_directpost</data>
<data name="creditCard/dataset" xsi:type="string">visa_authorizenet</data>
<data name="configData" xsi:type="string">authorizenet</data>
<data name="tag" xsi:type="string">test_type:3rd_party_test</data>
<data name="status" xsi:type="string">Processing</data>
<data name="tag" xsi:type="string">test_type:3rd_party_test_deprecated</data>
<constraint name="Magento\Checkout\Test\Constraint\AssertOrderSuccessPlacedMessage" />
<constraint name="Magento\Checkout\Test\Constraint\AssertMinicartEmpty" />
<constraint name="Magento\Sales\Test\Constraint\AssertOrderGrandTotal" />
<constraint name="Magento\Sales\Test\Constraint\AssertOrderCommentsHistory" />
<constraint name="Magento\Sales\Test\Constraint\AssertOrderStatusIsCorrect" />
<constraint name="Magento\Sales\Test\Constraint\AssertAuthorizationInCommentsHistory" />
</variation>
</testCase>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Braintree\Test\Block\Form;


use Magento\Mtf\Block\Mapper;
use Magento\Mtf\Client\Locator;
use Magento\Mtf\Block\BlockFactory;
use Magento\Mtf\Client\BrowserInterface;
use Magento\Mtf\Client\Element\SimpleElement;
use Magento\Mtf\Fixture\FixtureInterface;
use Magento\Payment\Test\Block\Form\Cc as CreditCard;

/**
* Class Cc
* Form for filling credit card data for Braintree payment method
*/
class Cc extends CreditCard
{
/**
* Braintree iFrame locator
*
* @var array
*/
protected $braintreeForm = [
"credit_card_number" => "#braintree-hosted-field-number",
"credit_card_exp_month" => "#braintree-hosted-field-expirationMonth",
"credit_card_exp_year" => "#braintree-hosted-field-expirationYear",
"cvv" => "#braintree-hosted-field-cvv",
];

public function fill(FixtureInterface $fixture, SimpleElement $element = null)
{
$mapping = $this->dataMapping($fixture->getData());
foreach ($this->braintreeForm as $field => $iframe) {
$this->browser->switchToFrame(new Locator($iframe));
$element = $this->browser->find('body');
$this->_fill([$mapping[$field]], $element);
$this->browser->switchToFrame();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" ?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<mapping strict="0">
<fields>
<credit_card_number>
<selector>#credit-card-number</selector>
</credit_card_number>
<credit_card_exp_month>
<selector>#expiration-month</selector>
</credit_card_exp_month>
<credit_card_exp_year>
<selector>#expiration-year</selector>
</credit_card_exp_year>
<cvv>
<selector>#cvv</selector>
</cvv>
</fields>
</mapping>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/fixture.xsd">
<fixture name="credit_card_braintree"
module="Magento_Braintree"
type="virtual"
entity_type="credit_card_braintree"
repository_class="Magento\Braintree\Test\Repository\CreditCard"
class="Magento\Braintree\Test\Fixture\CreditCardBraintree">
<field name="credit_card_number" />
<field name="credit_card_exp_month" />
<field name="credit_card_exp_year" />
<field name="cvv" />
</fixture>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/pages.xsd">
<page name="CheckoutOnepage" mca="checkout/index">
<block name="braintreeBlock" class="\Magento\Braintree\Test\Block\Form\Сс" locator="body" strategy="xpath"/>
</page>
</config>
Loading

0 comments on commit 2f74e09

Please sign in to comment.