|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\Paypal\Test\Unit\Model\ResourceModel; |
| 8 | + |
| 9 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; |
| 10 | + |
| 11 | +/** |
| 12 | + * Class AgreementTest |
| 13 | + */ |
| 14 | +class AgreementTest extends \PHPUnit_Framework_TestCase |
| 15 | +{ |
| 16 | + /** |
| 17 | + * @var \Magento\Paypal\Model\ResourceModel\Billing\Agreement |
| 18 | + */ |
| 19 | + protected $agreementResource; |
| 20 | + |
| 21 | + /** |
| 22 | + * @var \Magento\Framework\DB\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject |
| 23 | + */ |
| 24 | + protected $connectionMock; |
| 25 | + |
| 26 | + /** |
| 27 | + * @var \Magento\Framework\Data\Collection\AbstractDb|\PHPUnit_Framework_MockObject_MockObject |
| 28 | + */ |
| 29 | + protected $collectionMock; |
| 30 | + |
| 31 | + /** |
| 32 | + * @var \Magento\Framework\DB\Select|\PHPUnit_Framework_MockObject_MockObject |
| 33 | + */ |
| 34 | + protected $selectMock; |
| 35 | + |
| 36 | + /** |
| 37 | + * @var \Magento\Framework\App\ResourceConnection|\PHPUnit_Framework_MockObject_MockObject |
| 38 | + */ |
| 39 | + protected $resourceConnectionMock; |
| 40 | + |
| 41 | + public function setUp() |
| 42 | + { |
| 43 | + $objectManager = new ObjectManagerHelper($this); |
| 44 | + $contextMock = $this->getMockBuilder('Magento\Framework\Model\ResourceModel\Db\Context') |
| 45 | + ->disableOriginalConstructor() |
| 46 | + ->getMock(); |
| 47 | + $this->resourceConnectionMock = $this->getMock( |
| 48 | + 'Magento\Framework\App\ResourceConnection', |
| 49 | + [ |
| 50 | + 'getConnection', |
| 51 | + 'getTableName' |
| 52 | + ], |
| 53 | + [], |
| 54 | + '', |
| 55 | + false |
| 56 | + ); |
| 57 | + $this->collectionMock = $this->getMockBuilder('Magento\Framework\Data\Collection\AbstractDb') |
| 58 | + ->disableOriginalConstructor() |
| 59 | + ->setMethods(['getSelect']) |
| 60 | + ->getMockForAbstractClass(); |
| 61 | + $this->connectionMock = $this->getMock( |
| 62 | + 'Magento\Framework\DB\Adapter\Pdo\Mysql', |
| 63 | + [], |
| 64 | + [], |
| 65 | + '', |
| 66 | + false |
| 67 | + ); |
| 68 | + $this->selectMock = $this->getMock('Magento\Framework\DB\Select', [], [], '', false); |
| 69 | + $contextMock->expects($this->once())->method('getResources')->willReturn($this->resourceConnectionMock); |
| 70 | + $this->agreementResource = $objectManager->getObject( |
| 71 | + 'Magento\Paypal\Model\ResourceModel\Billing\Agreement', |
| 72 | + [ |
| 73 | + 'context' => $contextMock, |
| 74 | + ] |
| 75 | + ); |
| 76 | + } |
| 77 | + |
| 78 | + public function testAddOrdersFilter() |
| 79 | + { |
| 80 | + $this->resourceConnectionMock->expects($this->exactly(2)) |
| 81 | + ->method('getConnection') |
| 82 | + ->willReturn($this->connectionMock); |
| 83 | + $this->resourceConnectionMock->expects($this->once()) |
| 84 | + ->method('getTableName') |
| 85 | + ->with('paypal_billing_agreement_order') |
| 86 | + ->willReturn('pref_paypal_billing_agreement_order'); |
| 87 | + $this->connectionMock->expects($this->once()) |
| 88 | + ->method('select') |
| 89 | + ->willReturn($this->selectMock); |
| 90 | + $this->selectMock->expects($this->once()) |
| 91 | + ->method('from') |
| 92 | + ->with(['pbao' => 'pref_paypal_billing_agreement_order'], ['order_id'], null) |
| 93 | + ->willReturnSelf(); |
| 94 | + $this->selectMock->expects($this->exactly(2)) |
| 95 | + ->method('where') |
| 96 | + ->withConsecutive( |
| 97 | + ['pbao.agreement_id IN(?)', [100]], |
| 98 | + ['main_table.entity_id IN (?)', [500]] |
| 99 | + ) |
| 100 | + ->willReturnSelf(); |
| 101 | + $this->connectionMock->expects($this->once()) |
| 102 | + ->method('fetchCol') |
| 103 | + ->with($this->selectMock, []) |
| 104 | + ->willReturn([500]); |
| 105 | + $this->collectionMock->expects($this->once()) |
| 106 | + ->method('getSelect') |
| 107 | + ->willReturn($this->selectMock); |
| 108 | + $this->assertEquals( |
| 109 | + $this->agreementResource, |
| 110 | + $this->agreementResource->addOrdersFilter($this->collectionMock, 100) |
| 111 | + ); |
| 112 | + } |
| 113 | +} |
0 commit comments