1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Vault\Model\ResourceModel;
use Magento\Braintree\Model\Ui\PayPal\ConfigProvider as PayPalConfigProvider;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Magento\Framework\ObjectManagerInterface;
use Magento\Sales\Model\Order;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Vault\Model\PaymentTokenManagement;
use Magento\Vault\Setup\InstallSchema;
class PaymentTokenTest extends \PHPUnit\Framework\TestCase
{
const CUSTOMER_ID = 1;
const TOKEN = 'mx29vk';
const ORDER_INCREMENT_ID = '100000001';
/**
* @var ObjectManagerInterface
*/
private $objectManager;
/**
* @var PaymentToken
*/
private $paymentToken;
/**
* @var ResourceConnection
*/
private $resource;
/**
* @var AdapterInterface
*/
private $connection;
/**
* @var PaymentTokenManagement
*/
private $paymentTokenManagement;
/**
* @var Order
*/
private $order;
protected function setUp()
{
$this->objectManager = Bootstrap::getObjectManager();
$this->order = $this->objectManager->create(Order::class);
$this->paymentToken = $this->objectManager->create(PaymentToken::class);
$this->paymentTokenManagement = $this->objectManager->get(PaymentTokenManagement::class);
$this->resource = $this->objectManager->get(ResourceConnection::class);
$this->connection = $this->resource->getConnection();
}
/**
* @magentoDataFixture Magento/Sales/_files/order.php
* @magentoDataFixture Magento/Braintree/_files/paypal_vault_token.php
*/
public function testAddLinkToOrderPaymentExists()
{
$this->order->loadByIncrementId(self::ORDER_INCREMENT_ID);
$paymentToken = $this->paymentTokenManagement
->getByGatewayToken(self::TOKEN, PayPalConfigProvider::PAYPAL_CODE, self::CUSTOMER_ID);
$this->connection->insert(
$this->resource->getTableName('vault_payment_token_order_payment_link'),
[
'order_payment_id' => $this->order->getPayment()->getEntityId(),
'payment_token_id' => $paymentToken->getEntityId()
]
);
static::assertTrue(
$this->paymentToken->addLinkToOrderPayment(
$paymentToken->getEntityId(),
$this->order->getPayment()->getEntityId()
)
);
}
/**
* @magentoDataFixture Magento/Sales/_files/order.php
* @magentoDataFixture Magento/Braintree/_files/paypal_vault_token.php
*/
public function testAddLinkToOrderPaymentCreate()
{
$this->order->loadByIncrementId(self::ORDER_INCREMENT_ID);
$paymentToken = $this->paymentTokenManagement
->getByGatewayToken(self::TOKEN, PayPalConfigProvider::PAYPAL_CODE, self::CUSTOMER_ID);
$select = $this->connection->select()
->from($this->resource->getTableName('vault_payment_token_order_payment_link'))
->where('order_payment_id = ?', (int) $this->order->getPayment()->getEntityId())
->where('payment_token_id =?', (int) $paymentToken->getEntityId());
static::assertEmpty($this->connection->fetchRow($select));
static::assertTrue(
$this->paymentToken->addLinkToOrderPayment(
$paymentToken->getEntityId(),
$this->order->getPayment()->getEntityId()
)
);
static::assertNotEmpty($this->connection->fetchRow($select));
}
}