Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InstructionsConfigProviderTest.php
Go to the documentation of this file.
1 <?php
7 
13 
14 class InstructionsConfigProviderTest extends \PHPUnit\Framework\TestCase
15 {
17  protected $model;
18 
20  protected $methodOneMock;
21 
23  protected $methodTwoMock;
24 
26  protected $escaperMock;
27 
28  protected function setUp()
29  {
30  $this->methodOneMock = $this->createPartialMock(
31  \Magento\Payment\Model\Method\AbstractMethod::class,
32  ['isAvailable', 'getInstructions']
33  );
34  $this->methodTwoMock = $this->createPartialMock(
35  \Magento\Payment\Model\Method\AbstractMethod::class,
36  ['isAvailable', 'getInstructions']
37  );
38 
39  $paymentHelperMock = $this->createMock(\Magento\Payment\Helper\Data::class);
40  $paymentHelperMock->expects($this->exactly(2))
41  ->method('getMethodInstance')
42  ->willReturnMap([
43  [Banktransfer::PAYMENT_METHOD_BANKTRANSFER_CODE, $this->methodOneMock],
45  ]);
46 
47  $this->escaperMock = $this->createMock(\Magento\Framework\Escaper::class);
48  $this->escaperMock->expects($this->any())
49  ->method('escapeHtml')
50  ->willReturnArgument(0);
51 
52  $this->model = new InstructionsConfigProvider(
53  $paymentHelperMock,
54  $this->escaperMock
55  );
56  }
57 
66  public function testGetConfig($isOneAvailable, $instructionsOne, $isTwoAvailable, $instructionsTwo, $result)
67  {
68  $this->methodOneMock->expects($this->once())
69  ->method('isAvailable')
70  ->willReturn($isOneAvailable);
71  $this->methodOneMock->expects($this->any())
72  ->method('getInstructions')
73  ->willReturn($instructionsOne);
74 
75  $this->methodTwoMock->expects($this->once())
76  ->method('isAvailable')
77  ->willReturn($isTwoAvailable);
78  $this->methodTwoMock->expects($this->any())
79  ->method('getInstructions')
80  ->willReturn($instructionsTwo);
81 
82  $this->assertEquals($result, $this->model->getConfig());
83  }
84 
88  public function dataProviderGetConfig()
89  {
92  return [
93  [false, '', false, '', []],
94  [false, 'one', false, 'two', []],
95  [true, '', false, '', ['payment' => ['instructions' => [$oneCode => '']]]],
96  [true, 'text one', false, '', ['payment' => ['instructions' => [$oneCode => 'text one']]]],
97  [false, '', true, '', ['payment' => ['instructions' => [$twoCode => '']]]],
98  [false, '', true, 'text two', ['payment' => ['instructions' => [$twoCode => 'text two']]]],
99  [true, '', true, '', ['payment' => ['instructions' => [$oneCode => '', $twoCode => '']]]],
100  [
101  true,
102  'text one',
103  true,
104  'text two',
105  ['payment' => ['instructions' => [$oneCode => 'text one', $twoCode => 'text two']]]
106  ],
107  [
108  true,
109  "\n",
110  true,
111  "\n",
112  ['payment' => ['instructions' => [$oneCode => "<br />\n", $twoCode => "<br />\n"]]]
113  ],
114  ];
115  }
116 }
testGetConfig($isOneAvailable, $instructionsOne, $isTwoAvailable, $instructionsTwo, $result)