Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FormTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class FormTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $_object;
17 
21  protected $_storeManager;
22 
26  protected $_eventManager;
27 
31  protected $_escaper;
32 
33  protected function setUp()
34  {
35  $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
36  $this->_storeManager = $this->getMockBuilder(
37  \Magento\Store\Model\StoreManager::class
38  )->setMethods(
39  ['getStore']
40  )->disableOriginalConstructor()->getMock();
41  $this->_eventManager = $this->getMockBuilder(
42  \Magento\Framework\Event\ManagerInterface::class
43  )->setMethods(
44  ['dispatch']
45  )->disableOriginalConstructor()->getMock();
46  $this->_escaper = $helper->getObject(\Magento\Framework\Escaper::class);
47  $context = $helper->getObject(
48  \Magento\Framework\View\Element\Template\Context::class,
49  [
50  'storeManager' => $this->_storeManager,
51  'eventManager' => $this->_eventManager,
52  'escaper' => $this->_escaper
53  ]
54  );
55  $this->_object = $helper->getObject(\Magento\Payment\Block\Form::class, ['context' => $context]);
56  }
57 
61  public function testGetMethodException()
62  {
63  $method = new \Magento\Framework\DataObject([]);
64  $this->_object->setData('method', $method);
65  $this->_object->getMethod();
66  }
67 
68  public function testGetMethodCode()
69  {
70  $method = $this->createMock(\Magento\Payment\Model\MethodInterface::class);
71  $method->expects($this->once())
72  ->method('getCode')
73  ->will($this->returnValue('method_code'));
74  $this->_object->setData('method', $method);
75  $this->assertEquals('method_code', $this->_object->getMethodCode());
76  }
77 
81  public function testGetInfoData($field, $value, $expected)
82  {
83  $methodInstance = $this->getMockBuilder(\Magento\Payment\Model\Method\AbstractMethod::class)
84  ->setMethods(['getData'])
85  ->disableOriginalConstructor()
86  ->getMock();
87  $methodInstance->expects($this->any())
88  ->method('getData')
89  ->with($field)
90  ->will($this->returnValue($value));
91  $method = $this->getMockBuilder(
92  \Magento\Payment\Model\MethodInterface::class
93  )->getMockForAbstractClass();
94  $method->expects($this->any())
95  ->method('getInfoInstance')
96  ->will($this->returnValue($methodInstance));
97  $this->_object->setData('method', $method);
98  $this->assertEquals($expected, $this->_object->getInfoData($field));
99  }
100 
104  public function getInfoDataProvider()
105  {
106  return [
107  ['info', 'blah-blah', 'blah-blah'],
108  ['field1', ['key' => 'val'], ['val']],
109  [
110  'some_field',
111  ['aa', '!@#$%^&*()_#$%@^%&$%^*%&^*', 'cc'],
112  ['aa', '!@#$%^&amp;*()_#$%@^%&amp;$%^*%&amp;^*', 'cc']
113  ]
114  ];
115  }
116 
117  public function testSetMethod()
118  {
119  $methodInterfaceMock = $this->getMockBuilder(\Magento\Payment\Model\MethodInterface::class)
120  ->getMockForAbstractClass();
121 
122  $this->assertSame($this->_object, $this->_object->setMethod($methodInterfaceMock));
123  }
124 }
$helper
Definition: iframe.phtml:13
testGetInfoData($field, $value, $expected)
Definition: FormTest.php:81
$value
Definition: gender.phtml:16
$method
Definition: info.phtml:13