BillingAgreementTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Test\Unit\CustomerData;
  7. use Magento\Customer\Helper\Session\CurrentCustomer;
  8. use Magento\Paypal\CustomerData\BillingAgreement;
  9. use Magento\Paypal\Helper\Data;
  10. use Magento\Paypal\Model\Config;
  11. use Magento\Paypal\Model\ConfigFactory;
  12. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  13. use Magento\Framework\Escaper;
  14. class BillingAgreementTest extends \PHPUnit\Framework\TestCase
  15. {
  16. /**
  17. * @var CurrentCustomer | \PHPUnit_Framework_MockObject_MockObject
  18. */
  19. private $currentCustomer;
  20. /**
  21. * @var Data | \PHPUnit_Framework_MockObject_MockObject
  22. */
  23. private $paypalData;
  24. /**
  25. * @var Config|\PHPUnit_Framework_MockObject_MockObject
  26. */
  27. private $paypalConfig;
  28. /**
  29. * @var BillingAgreement
  30. */
  31. private $billingAgreement;
  32. /**
  33. * @var Escaper
  34. */
  35. private $escaperMock;
  36. protected function setUp()
  37. {
  38. $helper = new ObjectManager($this);
  39. $this->paypalConfig = $this->createMock(Config::class);
  40. $this->escaperMock = $helper->getObject(Escaper::class);
  41. $this->paypalConfig
  42. ->expects($this->once())
  43. ->method('setMethod')
  44. ->will($this->returnSelf());
  45. $this->paypalConfig->expects($this->once())
  46. ->method('setMethod')
  47. ->with(Config::METHOD_EXPRESS);
  48. $paypalConfigFactory = $this->createPartialMock(ConfigFactory::class, ['create']);
  49. $paypalConfigFactory->expects($this->once())
  50. ->method('create')
  51. ->will($this->returnValue($this->paypalConfig));
  52. $customerId = 20;
  53. $this->currentCustomer = $this->createMock(CurrentCustomer::class);
  54. $this->currentCustomer->expects($this->any())
  55. ->method('getCustomerId')
  56. ->willReturn($customerId);
  57. $this->paypalData = $this->createMock(Data::class);
  58. $this->billingAgreement = $helper->getObject(
  59. BillingAgreement::class,
  60. [
  61. 'paypalConfigFactory' => $paypalConfigFactory,
  62. 'paypalData' => $this->paypalData,
  63. 'currentCustomer' => $this->currentCustomer,
  64. 'escaper' => $this->escaperMock
  65. ]
  66. );
  67. }
  68. public function testGetSectionData()
  69. {
  70. $this->paypalData->expects($this->once())
  71. ->method('shouldAskToCreateBillingAgreement')
  72. ->with($this->paypalConfig, $this->currentCustomer->getCustomerId())
  73. ->willReturn(true);
  74. $result = $this->billingAgreement->getSectionData();
  75. $this->assertArrayHasKey('askToCreate', $result);
  76. $this->assertArrayHasKey('confirmUrl', $result);
  77. $this->assertArrayHasKey('confirmMessage', $result);
  78. $this->assertEquals(
  79. 'Would you like to sign a billing agreement to streamline further purchases with PayPal?',
  80. $result['confirmMessage']
  81. );
  82. $this->assertTrue($result['askToCreate']);
  83. }
  84. public function testGetSectionDataNotNeedToCreateBillingAgreement()
  85. {
  86. $this->paypalData->expects($this->once())
  87. ->method('shouldAskToCreateBillingAgreement')
  88. ->with($this->paypalConfig, $this->currentCustomer->getCustomerId())
  89. ->willReturn(false);
  90. $result = $this->billingAgreement->getSectionData();
  91. $this->assertEmpty($result);
  92. }
  93. }