InstructionsConfigProviderTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\OfflinePayments\Test\Unit\Model;
  7. use Magento\Framework\Escaper;
  8. use Magento\OfflinePayments\Model\Banktransfer;
  9. use Magento\OfflinePayments\Model\Cashondelivery;
  10. use Magento\OfflinePayments\Model\InstructionsConfigProvider;
  11. use Magento\Payment\Model\Method\AbstractMethod;
  12. class InstructionsConfigProviderTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /** @var InstructionsConfigProvider */
  15. protected $model;
  16. /** @var AbstractMethod|\PHPUnit_Framework_MockObject_MockObject */
  17. protected $methodOneMock;
  18. /** @var AbstractMethod|\PHPUnit_Framework_MockObject_MockObject */
  19. protected $methodTwoMock;
  20. /** @var Escaper|\PHPUnit_Framework_MockObject_MockObject */
  21. protected $escaperMock;
  22. protected function setUp()
  23. {
  24. $this->methodOneMock = $this->createPartialMock(
  25. \Magento\Payment\Model\Method\AbstractMethod::class,
  26. ['isAvailable', 'getInstructions']
  27. );
  28. $this->methodTwoMock = $this->createPartialMock(
  29. \Magento\Payment\Model\Method\AbstractMethod::class,
  30. ['isAvailable', 'getInstructions']
  31. );
  32. $paymentHelperMock = $this->createMock(\Magento\Payment\Helper\Data::class);
  33. $paymentHelperMock->expects($this->exactly(2))
  34. ->method('getMethodInstance')
  35. ->willReturnMap([
  36. [Banktransfer::PAYMENT_METHOD_BANKTRANSFER_CODE, $this->methodOneMock],
  37. [Cashondelivery::PAYMENT_METHOD_CASHONDELIVERY_CODE, $this->methodTwoMock],
  38. ]);
  39. $this->escaperMock = $this->createMock(\Magento\Framework\Escaper::class);
  40. $this->escaperMock->expects($this->any())
  41. ->method('escapeHtml')
  42. ->willReturnArgument(0);
  43. $this->model = new InstructionsConfigProvider(
  44. $paymentHelperMock,
  45. $this->escaperMock
  46. );
  47. }
  48. /**
  49. * @param bool $isOneAvailable
  50. * @param string $instructionsOne
  51. * @param bool $isTwoAvailable
  52. * @param string $instructionsTwo
  53. * @param array $result
  54. * @dataProvider dataProviderGetConfig
  55. */
  56. public function testGetConfig($isOneAvailable, $instructionsOne, $isTwoAvailable, $instructionsTwo, $result)
  57. {
  58. $this->methodOneMock->expects($this->once())
  59. ->method('isAvailable')
  60. ->willReturn($isOneAvailable);
  61. $this->methodOneMock->expects($this->any())
  62. ->method('getInstructions')
  63. ->willReturn($instructionsOne);
  64. $this->methodTwoMock->expects($this->once())
  65. ->method('isAvailable')
  66. ->willReturn($isTwoAvailable);
  67. $this->methodTwoMock->expects($this->any())
  68. ->method('getInstructions')
  69. ->willReturn($instructionsTwo);
  70. $this->assertEquals($result, $this->model->getConfig());
  71. }
  72. /**
  73. * @return array
  74. */
  75. public function dataProviderGetConfig()
  76. {
  77. $oneCode = Banktransfer::PAYMENT_METHOD_BANKTRANSFER_CODE;
  78. $twoCode = Cashondelivery::PAYMENT_METHOD_CASHONDELIVERY_CODE;
  79. return [
  80. [false, '', false, '', []],
  81. [false, 'one', false, 'two', []],
  82. [true, '', false, '', ['payment' => ['instructions' => [$oneCode => '']]]],
  83. [true, 'text one', false, '', ['payment' => ['instructions' => [$oneCode => 'text one']]]],
  84. [false, '', true, '', ['payment' => ['instructions' => [$twoCode => '']]]],
  85. [false, '', true, 'text two', ['payment' => ['instructions' => [$twoCode => 'text two']]]],
  86. [true, '', true, '', ['payment' => ['instructions' => [$oneCode => '', $twoCode => '']]]],
  87. [
  88. true,
  89. 'text one',
  90. true,
  91. 'text two',
  92. ['payment' => ['instructions' => [$oneCode => 'text one', $twoCode => 'text two']]]
  93. ],
  94. [
  95. true,
  96. "\n",
  97. true,
  98. "\n",
  99. ['payment' => ['instructions' => [$oneCode => "<br />\n", $twoCode => "<br />\n"]]]
  100. ],
  101. ];
  102. }
  103. }