Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PresentationTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
10 class PresentationTest extends \PHPUnit\Framework\TestCase
11 {
15  private $presentation;
16 
20  private $attributeMock;
21 
22  protected function setUp()
23  {
24  $this->presentation = new \Magento\Catalog\Model\Product\Attribute\Frontend\Inputtype\Presentation();
25  $this->attributeMock = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class)
26  ->disableOriginalConstructor()
27  ->getMock();
28  }
29 
36  public function testGetPresentationInputType(string $inputType, bool $isWysiwygEnabled, string $expectedResult)
37  {
38  $this->attributeMock->expects($this->once())->method('getFrontendInput')->willReturn($inputType);
39  $this->attributeMock->expects($this->any())->method('getIsWysiwygEnabled')->willReturn($isWysiwygEnabled);
40  $this->assertEquals($expectedResult, $this->presentation->getPresentationInputType($this->attributeMock));
41  }
42 
47  {
48  return [
49  'attribute_is_textarea_and_wysiwyg_enabled' => ['textarea', true, 'texteditor'],
50  'attribute_is_input_and_wysiwyg_enabled' => ['input', true, 'input'],
51  'attribute_is_textarea_and_wysiwyg_disabled' => ['textarea', false, 'textarea'],
52  ];
53  }
54 
60  public function testConvertPresentationDataToInputType(array $data, array $expectedResult)
61  {
62  $this->assertEquals($expectedResult, $this->presentation->convertPresentationDataToInputType($data));
63  }
64 
69  {
70  return [
71  [['key' => 'value'], ['key' => 'value']],
72  [
73  ['frontend_input' => 'texteditor'],
74  ['frontend_input' => 'textarea', 'is_wysiwyg_enabled' => 1]
75  ],
76  [
77  ['frontend_input' => 'textarea'],
78  ['frontend_input' => 'textarea', 'is_wysiwyg_enabled' => 0]
79  ],
80  [
81  ['frontend_input' => 'input'],
82  ['frontend_input' => 'input']
83  ]
84  ];
85  }
86 }
testGetPresentationInputType(string $inputType, bool $isWysiwygEnabled, string $expectedResult)