Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
AbstractWidgetTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class AbstractWidgetTest extends \PHPUnit\Framework\TestCase
11 {
13  const KEY_FIELD_ID_FORMAT = 'field_id_format';
14 
15  const KEY_FIELD_NAME_FORMAT = 'field_name_format';
16 
17  const FORMAT_D = '%d';
18 
19  const FORMAT_S = '%s';
20 
22  private $_addressHelper;
23 
25  private $_block;
26 
27  protected function setUp()
28  {
29  $this->_addressHelper = $this->createMock(\Magento\Customer\Helper\Address::class);
30 
31  $this->_block = new \Magento\Customer\Block\Widget\AbstractWidget(
32  $this->createMock(\Magento\Framework\View\Element\Template\Context::class),
33  $this->_addressHelper,
34  $this->getMockBuilder(\Magento\Customer\Api\CustomerMetadataInterface::class)->getMockForAbstractClass()
35  );
36  }
37 
44  public function testGetConfig($key, $expectedValue)
45  {
46  $this->_addressHelper->expects(
47  $this->once()
48  )->method(
49  'getConfig'
50  )->with(
51  $key
52  )->will(
53  $this->returnValue($expectedValue)
54  );
55  $this->assertEquals($expectedValue, $this->_block->getConfig($key));
56  }
57 
61  public function getConfigDataProvider()
62  {
63  return [['key', 'value'], [null, null]];
64  }
65 
70  public function testGetFieldIdFormatHasData()
71  {
72  $this->_block->setData(self::KEY_FIELD_ID_FORMAT, self::FORMAT_D);
73  $this->assertEquals(self::FORMAT_D, $this->_block->getFieldIdFormat());
74  }
75 
80  {
81  $this->assertEquals(self::FORMAT_S, $this->_block->getFieldIdFormat());
82  }
83 
89  {
90  $this->_block->setData(self::KEY_FIELD_NAME_FORMAT, self::FORMAT_D);
91  $this->assertEquals(self::FORMAT_D, $this->_block->getFieldNameFormat());
92  }
93 
98  {
99  $this->assertEquals(self::FORMAT_S, $this->_block->getFieldNameFormat());
100  }
101 
113  public function testGetFieldId($format, $fieldId, $expectedValue, $method)
114  {
115  $this->_block->setData(self::KEY_FIELD_ID_FORMAT, $format);
116  $this->assertTrue(call_user_func($method, $blockFieldId = $this->_block->getFieldId($fieldId)));
117  $this->assertSame($expectedValue, $blockFieldId);
118  }
119 
123  public function getFieldIdDataProvider()
124  {
125  return [
126  [self::FORMAT_S, 'Id', 'Id', 'is_string'],
127  [self::FORMAT_D, '123', '123', 'is_numeric'],
128  [self::FORMAT_D, 'Id', '0', 'is_numeric']
129  ];
130  }
131 
143  public function testGetFieldName($format, $fieldName, $expectedValue, $method)
144  {
145  $this->_block->setData(self::KEY_FIELD_NAME_FORMAT, $format);
146  $this->assertTrue(call_user_func($method, $blockFieldName = $this->_block->getFieldName($fieldName)));
147  $this->assertEquals($expectedValue, $blockFieldName);
148  }
149 
153  public function getFieldNameDataProvider()
154  {
155  return [
156  [self::FORMAT_S, 'Name', 'Name', 'is_string'],
157  [self::FORMAT_D, '123', '123', 'is_numeric'],
158  [self::FORMAT_D, 'Name', '0', 'is_numeric']
159  ];
160  }
161 }
testGetFieldId($format, $fieldId, $expectedValue, $method)
$fieldId
Definition: element.phtml:16
$format
Definition: list.phtml:12
$method
Definition: info.phtml:13
testGetFieldName($format, $fieldName, $expectedValue, $method)