Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ElementFactoryTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class ElementFactoryTest extends \PHPUnit\Framework\TestCase
11 {
13  private $_objectManager;
14 
16  private $_attributeMetadata;
17 
19  private $_entityTypeCode = 'customer_address';
20 
22  private $_elementFactory;
23 
24  protected function setUp()
25  {
26  $this->_objectManager = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
27  $this->_attributeMetadata = $this->createMock(\Magento\Customer\Model\Data\AttributeMetadata::class);
28  $this->_elementFactory = new ElementFactory($this->_objectManager, new \Magento\Framework\Stdlib\StringUtils());
29  }
30 
33  {
34  $this->_attributeMetadata->expects(
35  $this->once()
36  )->method(
37  'getDataModel'
38  )->will(
39  $this->returnValue(\Magento\Customer\Model\Attribute\Data\Postcode::class)
40  );
41 
42  $dataModel = $this->createMock(\Magento\Customer\Model\Metadata\Form\Text::class);
43  $this->_objectManager->expects($this->once())->method('create')->will($this->returnValue($dataModel));
44 
45  $actual = $this->_elementFactory->create($this->_attributeMetadata, '95131', $this->_entityTypeCode);
46  $this->assertSame($dataModel, $actual);
47  }
48 
50  {
51  $this->_attributeMetadata->expects($this->once())->method('getDataModel')->will($this->returnValue(''));
52  $this->_attributeMetadata->expects(
53  $this->once()
54  )->method(
55  'getFrontendInput'
56  )->will(
57  $this->returnValue('text')
58  );
59 
60  $dataModel = $this->createMock(\Magento\Customer\Model\Metadata\Form\Text::class);
61  $params = [
62  'entityTypeCode' => $this->_entityTypeCode,
63  'value' => 'Some Text',
64  'isAjax' => false,
65  'attribute' => $this->_attributeMetadata,
66  ];
67  $this->_objectManager->expects(
68  $this->once()
69  )->method(
70  'create'
71  )->with(
72  \Magento\Customer\Model\Metadata\Form\Text::class,
73  $params
74  )->will(
75  $this->returnValue($dataModel)
76  );
77 
78  $actual = $this->_elementFactory->create($this->_attributeMetadata, 'Some Text', $this->_entityTypeCode);
79  $this->assertSame($dataModel, $actual);
80  }
81 }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18