Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PaymentMethodTest.php
Go to the documentation of this file.
1 <?php
7 
11 
15 class PaymentMethodTest extends \PHPUnit\Framework\TestCase
16 {
20  protected $model;
21 
25  protected $paymentHelper;
26 
27  protected function setUp()
28  {
29  $objectManager = new ObjectManager($this);
30  $contextMock = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\ContextInterface::class)
31  ->getMockForAbstractClass();
32  $processor = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\Processor::class)
33  ->disableOriginalConstructor()
34  ->getMock();
35  $contextMock->expects($this->never())->method('getProcessor')->willReturn($processor);
36  $this->paymentHelper = $this->createMock(\Magento\Payment\Helper\Data::class);
37  $this->model = $objectManager->getObject(
38  \Magento\Sales\Ui\Component\Listing\Column\PaymentMethod::class,
39  ['paymentHelper' => $this->paymentHelper, 'context' => $contextMock]
40  );
41  }
42 
43  public function testPrepareDataSource()
44  {
45  $itemName = 'itemName';
46  $oldItemValue = 'oldItemValue';
47  $newItemValue = 'newItemValue';
48  $dataSource = [
49  'data' => [
50  'items' => [
51  [$itemName => $oldItemValue]
52  ]
53  ]
54  ];
55 
56  $payment = $this->getMockForAbstractClass(\Magento\Payment\Model\MethodInterface::class);
57  $payment->expects($this->once())
58  ->method('getTitle')
59  ->willReturn($newItemValue);
60  $this->paymentHelper->expects($this->once())
61  ->method('getMethodInstance')
62  ->with($oldItemValue)
63  ->willReturn($payment);
64 
65  $this->model->setData('name', $itemName);
66  $dataSource = $this->model->prepareDataSource($dataSource);
67  $this->assertEquals($newItemValue, $dataSource['data']['items'][0][$itemName]);
68  }
69 }
$objectManager
Definition: bootstrap.php:17
$processor
Definition: 404.php:10
$payment
Definition: order.php:17