123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Paypal\Test\Unit\Model\Method\Checks;
- use Magento\Paypal\Model\Method\Checks\SpecificationPlugin;
- use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
- use Magento\Paypal\Model\Billing\AgreementFactory as BillingAgreementFactory;
- use Magento\Payment\Model\Checks\SpecificationInterface;
- use Magento\Payment\Model\MethodInterface;
- use Magento\Quote\Model\Quote;
- use Magento\Paypal\Model\ResourceModel\Billing\Agreement\Collection as BillingAgreementCollection;
- use Magento\Paypal\Model\Billing\Agreement as BillingAgreement;
- class SpecificationPluginTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var SpecificationPlugin
- */
- private $plugin;
- /**
- * @var ObjectManagerHelper
- */
- private $objectManagerHelper;
- /**
- * @var BillingAgreementFactory|\PHPUnit_Framework_MockObject_MockObject
- */
- private $billingAgreementFactoryMock;
- /**
- * @var SpecificationInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- private $specificationMock;
- /**
- * @var MethodInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- private $paymentMethodMock;
- /**
- * @var Quote|\PHPUnit_Framework_MockObject_MockObject
- */
- private $quoteMock;
- /**
- * @var BillingAgreementCollection|\PHPUnit_Framework_MockObject_MockObject
- */
- private $billingAgreementCollectionMock;
- /**
- * @var BillingAgreement|\PHPUnit_Framework_MockObject_MockObject
- */
- private $billingAgreementMock;
- protected function setUp()
- {
- $this->billingAgreementFactoryMock = $this->getMockBuilder(BillingAgreementFactory::class)
- ->disableOriginalConstructor()
- ->setMethods(['create'])
- ->getMock();
- $this->specificationMock = $this->getMockBuilder(SpecificationInterface::class)
- ->getMockForAbstractClass();
- $this->paymentMethodMock = $this->getMockBuilder(MethodInterface::class)
- ->getMockForAbstractClass();
- $this->quoteMock = $this->getMockBuilder(Quote::class)
- ->disableOriginalConstructor()
- ->setMethods(['getCustomerId'])
- ->getMock();
- $this->billingAgreementCollectionMock = $this->getMockBuilder(BillingAgreementCollection::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->billingAgreementMock = $this->getMockBuilder(BillingAgreement::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->objectManagerHelper = new ObjectManagerHelper($this);
- $this->plugin = $this->objectManagerHelper->getObject(
- SpecificationPlugin::class,
- [
- 'agreementFactory' => $this->billingAgreementFactoryMock
- ]
- );
- }
- public function testAfterIsApplicableNotOriginallyApplicable()
- {
- $this->setExpectations('any', 'any');
- $this->assertFalse(
- $this->plugin->afterIsApplicable(
- $this->specificationMock,
- false,
- $this->paymentMethodMock,
- $this->quoteMock
- )
- );
- }
- public function testAfterIsApplicableNotAgreement()
- {
- $this->setExpectations('not_agreement', 'any');
- $this->assertTrue(
- $this->plugin->afterIsApplicable(
- $this->specificationMock,
- true,
- $this->paymentMethodMock,
- $this->quoteMock
- )
- );
- }
- public function testAfterIsApplicableNoCustomerId()
- {
- $this->setExpectations('paypal_billing_agreement', null);
- $this->assertFalse(
- $this->plugin->afterIsApplicable(
- $this->specificationMock,
- true,
- $this->paymentMethodMock,
- $this->quoteMock
- )
- );
- }
- /**
- * @param int $count
- *
- * @dataProvider afterIsApplicableDataProvider
- */
- public function testAfterIsApplicable($count)
- {
- $this->setExpectations('paypal_billing_agreement', 1);
- $this->billingAgreementFactoryMock->expects(static::once())
- ->method('create')
- ->willReturn($this->billingAgreementMock);
- $this->billingAgreementMock->expects(static::once())
- ->method('getAvailableCustomerBillingAgreements')
- ->with(1)
- ->willReturn($this->billingAgreementCollectionMock);
- $this->billingAgreementCollectionMock->expects(static::once())
- ->method('count')
- ->willReturn($count);
- $this->assertEquals(
- $count > 0,
- $this->plugin->afterIsApplicable($this->specificationMock, true, $this->paymentMethodMock, $this->quoteMock)
- );
- }
- /**
- * @return array
- */
- public function afterIsApplicableDataProvider()
- {
- return [[0], [1], [2]];
- }
- /**
- * Set expectations
- *
- * @param mixed $paymentMethodCode
- * @param mixed $customerId
- * @return void
- */
- private function setExpectations($paymentMethodCode, $customerId)
- {
- $this->paymentMethodMock->expects(static::any())
- ->method('getCode')
- ->willReturn($paymentMethodCode);
- $this->quoteMock->expects(static::any())
- ->method('getCustomerId')
- ->willReturn($customerId);
- }
- }
|