Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ObscureTest.php
Go to the documentation of this file.
1 <?php
11 
12 class ObscureTest extends \PHPUnit\Framework\TestCase
13 {
18 
22  protected $_model;
23 
24  protected function setUp()
25  {
26  $factoryMock = $this->createMock(\Magento\Framework\Data\Form\Element\Factory::class);
27  $collectionFactoryMock = $this->createMock(\Magento\Framework\Data\Form\Element\CollectionFactory::class);
28  $escaperMock = $this->createMock(\Magento\Framework\Escaper::class);
29  $this->_model = new \Magento\Framework\Data\Form\Element\Obscure(
30  $factoryMock,
31  $collectionFactoryMock,
32  $escaperMock
33  );
34  $formMock = new \Magento\Framework\DataObject();
35  $formMock->getHtmlIdPrefix('id_prefix');
36  $formMock->getHtmlIdPrefix('id_suffix');
37  $this->_model->setForm($formMock);
38  }
39 
43  public function testConstruct()
44  {
45  $this->assertEquals('password', $this->_model->getType());
46  $this->assertEquals('textfield', $this->_model->getExtType());
47  }
48 
52  public function testGetEscapedValue()
53  {
54  $this->_model->setValue('Obscure Text');
55  $this->assertContains('value="******"', $this->_model->getElementHtml());
56  $this->_model->setValue('');
57  $this->assertContains('value=""', $this->_model->getElementHtml());
58  }
59 
63  public function testGetHtmlAttributes()
64  {
65  $this->assertEmpty(
66  array_diff(
67  [
68  'type',
69  'title',
70  'class',
71  'style',
72  'onclick',
73  'onchange',
74  'onkeyup',
75  'disabled',
76  'readonly',
77  'maxlength',
78  'tabindex',
79  ],
80  $this->_model->getHtmlAttributes()
81  )
82  );
83  }
84 }