Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
BillingAgreementTest.php
Go to the documentation of this file.
1 <?php
7 
12 use Magento\Paypal\Model\ConfigFactory;
14 
15 class BillingAgreementTest extends \PHPUnit\Framework\TestCase
16 {
17 
21  private $currentCustomer;
22 
26  private $paypalData;
27 
31  private $paypalConfig;
32 
36  private $billingAgreement;
37 
38  protected function setUp()
39  {
40  $this->paypalConfig = $this->createMock(Config::class);
41  $this->paypalConfig
42  ->expects($this->once())
43  ->method('setMethod')
44  ->will($this->returnSelf());
45 
46  $this->paypalConfig->expects($this->once())
47  ->method('setMethod')
48  ->with(Config::METHOD_EXPRESS);
49 
50  $paypalConfigFactory = $this->createPartialMock(ConfigFactory::class, ['create']);
51  $paypalConfigFactory->expects($this->once())
52  ->method('create')
53  ->will($this->returnValue($this->paypalConfig));
54 
55  $customerId = 20;
56  $this->currentCustomer = $this->createMock(CurrentCustomer::class);
57  $this->currentCustomer->expects($this->any())
58  ->method('getCustomerId')
59  ->willReturn($customerId);
60 
61  $this->paypalData = $this->createMock(Data::class);
62 
63  $helper = new ObjectManager($this);
64  $this->billingAgreement = $helper->getObject(
65  BillingAgreement::class,
66  [
67  'paypalConfigFactory' => $paypalConfigFactory,
68  'paypalData' => $this->paypalData,
69  'currentCustomer' => $this->currentCustomer
70  ]
71  );
72  }
73 
74  public function testGetSectionData()
75  {
76  $this->paypalData->expects($this->once())
77  ->method('shouldAskToCreateBillingAgreement')
78  ->with($this->paypalConfig, $this->currentCustomer->getCustomerId())
79  ->willReturn(true);
80 
81  $result = $this->billingAgreement->getSectionData();
82 
83  $this->assertArrayHasKey('askToCreate', $result);
84  $this->assertArrayHasKey('confirmUrl', $result);
85  $this->assertArrayHasKey('confirmMessage', $result);
86  $this->assertTrue($result['askToCreate']);
87  }
88 
90  {
91  $this->paypalData->expects($this->once())
92  ->method('shouldAskToCreateBillingAgreement')
93  ->with($this->paypalConfig, $this->currentCustomer->getCustomerId())
94  ->willReturn(false);
95 
96  $result = $this->billingAgreement->getSectionData();
97 
98  $this->assertEmpty($result);
99  }
100 }
$helper
Definition: iframe.phtml:13