58 $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
59 $this->factoryMock = $this->createMock(\
Magento\Framework\Data\
Form\Element\Factory::class);
60 $this->collectionFactoryMock = $this->createMock(\
Magento\Framework\Data\
Form\Element\CollectionFactory::class);
61 $this->escaperMock = $this->createMock(\
Magento\Framework\Escaper::class);
62 $this->configMock = $this->createPartialMock(\
Magento\Framework\DataObject::class, [
'getData']);
64 $this->serializer = $this->createMock(\
Magento\Framework\
Serialize\Serializer\Json::class);
66 $this->model = $this->objectManager->getObject(
69 'factoryElement' => $this->factoryMock,
70 'factoryCollection' => $this->collectionFactoryMock,
71 'escaper' => $this->escaperMock,
72 'data' => [
'config' => $this->configMock],
73 'serializer' => $this->serializer
78 $this->createPartialMock(\
Magento\Framework\Data\Form::class, [
'getHtmlIdPrefix',
'getHtmlIdSuffix']);
79 $this->model->setForm($this->formMock);
84 $this->assertEquals(
'textarea', $this->model->getType());
85 $this->assertEquals(
'textarea', $this->model->getExtType());
89 $this->configMock->expects($this->once())->method(
'getData')->with(
'enabled')->willReturn(
true);
91 $model = $this->objectManager->getObject(
94 'factoryElement' => $this->factoryMock,
95 'factoryCollection' => $this->collectionFactoryMock,
96 'escaper' => $this->escaperMock,
97 'data' => [
'config' => $this->configMock]
101 $this->assertEquals(
'wysiwyg',
$model->getType());
102 $this->assertEquals(
'wysiwyg',
$model->getExtType());
107 $html = $this->model->getElementHtml();
108 $this->assertContains(
'</textarea>', $html);
109 $this->assertContains(
'rows="2"', $html);
110 $this->assertContains(
'cols="15"', $html);
111 $this->assertRegExp(
'/class=\".*textarea.*\"/i', $html);
112 $this->assertNotRegExp(
'/.*mage\/adminhtml\/wysiwyg\/widget.*/i', $html);
114 $this->configMock->expects($this->any())->method(
'getData')
117 [
'enabled',
null,
true],
118 [
'hidden',
null,
null]
121 $html = $this->model->getElementHtml();
122 $this->assertRegExp(
'/.*mage\/adminhtml\/wysiwyg\/widget.*/i', $html);
124 $this->configMock->expects($this->any())->method(
'getData')
127 [
'enabled',
null,
null],
128 [
'widget_window_url',
null,
'localhost'],
129 [
'add_widgets',
null,
true],
130 [
'hidden',
null,
null]
133 $html = $this->model->getElementHtml();
134 $this->assertRegExp(
'/.*mage\/adminhtml\/wysiwyg\/widget.*/i', $html);
144 public function testIsEnabled($expected, $globalFlag, $attributeFlag =
null)
147 ->expects($this->once())
150 ->willReturn($globalFlag);
152 if ($attributeFlag !==
null) {
153 $this->model->setData(
'wysiwyg', $attributeFlag);
155 $this->assertEquals($expected, $this->model->isEnabled());
164 'Global disabled, attribute isnt set' => [
false,
false],
165 'Global disabled, attribute disabled' => [
false,
false,
false],
166 'Global disabled, attribute enabled' => [
false,
false,
true],
168 'Global enabled, attribute isnt set' => [
true,
true],
169 'Global enabled, attribute disabled' => [
false,
true,
false],
170 'Global enabled, attribute enabled' => [
true,
true,
true]
176 $this->assertEmpty($this->model->isHidden());
178 $this->configMock->expects($this->once())->method(
'getData')->with(
'hidden')->willReturn(
true);
179 $this->assertTrue($this->model->isHidden());
184 $this->assertEquals(
'Insert Image...', $this->model->translate(
'Insert Image...'));
189 $config = $this->createPartialMock(\
Magento\Framework\DataObject::class, [
'getData']);
190 $this->assertEquals(
$config, $this->model->getConfig());
192 $this->configMock->expects($this->once())->method(
'getData')->with(
'test')->willReturn(
'test');
193 $this->assertEquals(
'test', $this->model->getConfig(
'test'));
201 $callback =
function (
$params) {
205 $this->configMock->expects($this->any())->method(
'getData')->withConsecutive([
'enabled'])->willReturn(
true);
206 $this->serializer->expects($this->any())
207 ->method(
'serialize')
208 ->willReturnCallback($callback);
210 $html = $this->model->getElementHtml();
212 $this->assertRegExp(
'/.*"Insert Image...":"Insert Image...".*/i', $html);
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]