ViewTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Paypal\Test\Unit\Block\Adminhtml\Order;
  8. use Magento\Paypal\Model\Adminhtml\Express;
  9. use Magento\Paypal\Block\Adminhtml\Order\View;
  10. use Magento\Sales\Model\Order;
  11. use Magento\Sales\Model\Order\Payment;
  12. use PHPUnit\Framework\TestCase;
  13. use Magento\Framework\Exception\LocalizedException;
  14. use \PHPUnit_Framework_MockObject_MockObject as MockObject;
  15. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  16. /**
  17. * Test adminhtml sales order view.
  18. */
  19. class ViewTest extends TestCase
  20. {
  21. /**
  22. * @var View
  23. */
  24. private $view;
  25. /**
  26. * @var Express|MockObject
  27. */
  28. private $express;
  29. /**
  30. * @var Payment|MockObject
  31. */
  32. private $payment;
  33. /**
  34. * @var Order|MockObject
  35. */
  36. private $order;
  37. protected function setUp()
  38. {
  39. $objectManager = new ObjectManager($this);
  40. $this->order = $this->createPartialMock(
  41. Order::class,
  42. ['canUnhold', 'isPaymentReview', 'getState', 'isCanceled', 'getPayment']
  43. );
  44. $this->express = $this->createPartialMock(
  45. Express::class,
  46. ['isOrderAuthorizationAllowed']
  47. );
  48. $this->payment = $this->createMock(Payment::class);
  49. $this->view = $objectManager->getObject(
  50. View::class,
  51. [
  52. 'express' => $this->express,
  53. 'data' => [],
  54. ]
  55. );
  56. }
  57. /**
  58. * Tests if authorization action is allowed for order.
  59. *
  60. * @param bool $canUnhold
  61. * @param bool $isPaymentReview
  62. * @param bool $isCanceled
  63. * @param bool $authAllowed
  64. * @param string $orderState
  65. * @param bool $canAuthorize
  66. * @throws LocalizedException
  67. * @dataProvider orderDataProvider
  68. */
  69. public function testIsOrderAuthorizationAllowed(
  70. bool $canUnhold,
  71. bool $isPaymentReview,
  72. bool $isCanceled,
  73. bool $authAllowed,
  74. string $orderState,
  75. bool $canAuthorize
  76. ) {
  77. $this->order->method('canUnhold')
  78. ->willReturn($canUnhold);
  79. $this->order->method('isPaymentReview')
  80. ->willReturn($isPaymentReview);
  81. $this->order->method('isCanceled')
  82. ->willReturn($isCanceled);
  83. $this->order->method('getState')
  84. ->willReturn($orderState);
  85. $this->order->method('getPayment')
  86. ->willReturn($this->payment);
  87. $this->express->method('isOrderAuthorizationAllowed')
  88. ->with($this->payment)
  89. ->willReturn($authAllowed);
  90. $this->assertEquals($canAuthorize, $this->view->canAuthorize($this->order));
  91. }
  92. /**
  93. * Data provider for order methods call.
  94. *
  95. * @return array
  96. */
  97. public function orderDataProvider(): array
  98. {
  99. return [
  100. [true, false, false, true, Order::STATE_PROCESSING, false],
  101. [false, true, false, true, Order::STATE_PROCESSING, false],
  102. [false, false, true, true, Order::STATE_PROCESSING, false],
  103. [false, false, false, false, Order::STATE_PROCESSING, false],
  104. [false, false, false, true, Order::STATE_COMPLETE, false],
  105. [false, false, false, true, Order::STATE_CLOSED, false],
  106. [false, false, false, true, Order::STATE_PROCESSING, true],
  107. ];
  108. }
  109. }