Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TransactionsTest.php
Go to the documentation of this file.
1 <?php
7 
11 class TransactionsTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $objectManager;
17 
21  protected $transactionsTab;
22 
26  protected $authorizationMock;
27 
31  protected $coreRegistryMock;
32 
36  protected $orderMock;
37 
41  protected $paymentMock;
42 
43  protected function setUp()
44  {
45  $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
46 
47  $this->authorizationMock = $this->createMock(\Magento\Framework\Authorization::class);
48  $this->coreRegistryMock = $this->createMock(\Magento\Framework\Registry::class);
49  $this->orderMock = $this->createMock(\Magento\Sales\Model\Order::class);
50  $this->paymentMock = $this->createMock(\Magento\Sales\Model\Order\Payment::class);
51 
52  $this->coreRegistryMock->expects($this->any())
53  ->method('registry')
54  ->with('current_order')
55  ->willReturn($this->orderMock);
56 
57  $this->orderMock->expects($this->any())
58  ->method('getPayment')
59  ->willReturn($this->paymentMock);
60 
61  $this->transactionsTab = $this->objectManager->getObject(
62  \Magento\Sales\Block\Adminhtml\Order\View\Tab\Transactions::class,
63  [
64  'authorization' => $this->authorizationMock,
65  'registry' => $this->coreRegistryMock
66  ]
67  );
68  }
69 
70  public function testGetOrder()
71  {
72  $this->assertInstanceOf(\Magento\Sales\Model\Order::class, $this->transactionsTab->getOrder());
73  }
74 
81  public function testCanShowTab($methodClass, $expectedResult)
82  {
83  $methodInstance = $this->objectManager->getObject($methodClass);
84  $this->paymentMock->expects($this->any())
85  ->method('getMethodInstance')
86  ->willReturn($methodInstance);
87 
88  $this->assertEquals($expectedResult, $this->transactionsTab->canShowTab());
89  }
90 
94  public function canShowTabDataProvider()
95  {
96  return [
97  [\Magento\Sales\Test\Unit\Block\Adminhtml\Order\View\Tab\Stub\OnlineMethod::class, true],
98  [\Magento\OfflinePayments\Model\Cashondelivery::class, false],
99  [\Magento\OfflinePayments\Model\Checkmo::class, false],
100  [\Magento\OfflinePayments\Model\Banktransfer::class, false],
101  [\Magento\OfflinePayments\Model\Purchaseorder::class, false]
102  ];
103  }
104 
110  public function testIsHidden($isAllowed, $expectedResult)
111  {
112  $this->authorizationMock->expects($this->any())
113  ->method('isAllowed')
114  ->with('Magento_Sales::transactions_fetch')
115  ->willReturn($isAllowed);
116 
117  $this->assertEquals($expectedResult, $this->transactionsTab->isHidden());
118  }
119 
123  public function isHiddenDataProvider()
124  {
125  return [
126  [true, false],
127  [false, true]
128  ];
129  }
130 }
$isAllowed
Definition: get.php:20