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