Skip to content

Commit 51a3124

Browse files
author
Viktor Paladiychuk
committed
MAGETWO-54836: Contribution of Bug Fixes - part 2
1 parent 49d7b06 commit 51a3124

File tree

2 files changed

+96
-34
lines changed

2 files changed

+96
-34
lines changed

app/code/Magento/Translation/Test/Unit/Model/Inline/ParserTest.php

Lines changed: 95 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,90 +5,138 @@
55
*/
66
namespace Magento\Translation\Test\Unit\Model\Inline;
77

8+
use Magento\Translation\Model\Inline\Parser;
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
use Magento\Framework\Translate\InlineInterface;
11+
use Magento\Framework\App\Cache\TypeListInterface;
12+
use Magento\Store\Model\StoreManagerInterface;
13+
use Magento\Store\Api\Data\StoreInterface;
14+
use Magento\Translation\Model\ResourceModel\StringUtilsFactory;
15+
use Magento\Translation\Model\ResourceModel\StringUtils;
16+
use Magento\Translation\Model\Inline\CacheManager;
17+
818
/**
919
* Class ParserTest to test \Magento\Translation\Model\Inline\Parser
1020
*/
1121
class ParserTest extends \PHPUnit_Framework_TestCase
1222
{
1323
/**
14-
* @var \Magento\Translation\Model\Inline\Parser|\PHPUnit_Framework_MockObject_MockObject
24+
* @var Parser
1525
*/
1626
private $model;
1727

1828
/**
19-
* @var \Magento\Translation\Model\ResourceModel\StringUtilsFactory|\PHPUnit_Framework_MockObject_MockObject
29+
* @var ObjectManager
2030
*/
21-
private $resourceMock;
31+
private $objectManager;
32+
33+
/**
34+
* @var InlineInterface|\PHPUnit_Framework_MockObject_MockObject
35+
*/
36+
private $translateInlineMock;
37+
38+
/**
39+
* @var TypeListInterface|\PHPUnit_Framework_MockObject_MockObject
40+
*/
41+
private $appCacheMock;
2242

2343
/**
24-
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
44+
* @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
2545
*/
2646
private $storeManagerMock;
2747

48+
/**
49+
* @var StoreInterface|\PHPUnit_Framework_MockObject_MockObject
50+
*/
51+
private $storeMock;
52+
2853
/**
2954
* @var \Zend_Filter_Interface|\PHPUnit_Framework_MockObject_MockObject
3055
*/
3156
private $inputFilterMock;
3257

58+
/**
59+
* @var StringUtilsFactory|\PHPUnit_Framework_MockObject_MockObject
60+
*/
61+
private $resourceFactoryMock;
62+
3363
/**
3464
* @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject
3565
*/
3666
private $appStateMock;
3767

3868
/**
39-
* @var \Magento\Framework\App\Cache\TypeListInterface|\PHPUnit_Framework_MockObject_MockObject
69+
* @var StringUtils|\PHPUnit_Framework_MockObject_MockObject
4070
*/
41-
private $appCacheMock;
71+
private $resourceMock;
4272

4373
/**
44-
* @var \Magento\Framework\Translate\InlineInterface|\PHPUnit_Framework_MockObject_MockObject
74+
* @var CacheManager|\PHPUnit_Framework_MockObject_MockObject
4575
*/
46-
private $translateInlineMock;
76+
private $cacheManagerMock;
4777

4878
protected function setUp()
4979
{
50-
$this->resourceMock = $this->getMockBuilder('Magento\Translation\Model\ResourceModel\StringUtilsFactory')
51-
->disableOriginalConstructor()
52-
->setMethods([])
80+
$this->objectManager = new ObjectManager($this);
81+
$this->translateInlineMock = $this->getMockForAbstractClass('Magento\Framework\Translate\InlineInterface');
82+
$this->appCacheMock = $this->getMockForAbstractClass('Magento\Framework\App\Cache\TypeListInterface');
83+
$this->storeManagerMock = $this->getMockForAbstractClass('Magento\Store\Model\StoreManagerInterface');
84+
$this->storeMock = $this->getMockForAbstractClass('Magento\Store\Api\Data\StoreInterface');
85+
$this->storeManagerMock->expects($this->any())
86+
->method('getStore')
87+
->willReturn($this->storeMock);
88+
$this->resourceFactoryMock = $this->getMockBuilder('Magento\Translation\Model\ResourceModel\StringUtilsFactory')
89+
->setMethods(['create'])
5390
->getMock();
54-
55-
$this->storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManagerInterface')
91+
$this->resourceMock = $this->getMockBuilder('Magento\Translation\Model\ResourceModel\StringUtils')
5692
->disableOriginalConstructor()
5793
->setMethods([])
5894
->getMock();
5995

60-
$this->inputFilterMock = $this->getMockBuilder('Zend_Filter_Interface')
61-
->disableOriginalConstructor()
62-
->setMethods([])
63-
->getMock();
96+
$this->inputFilterMock = $this->getMockBuilder('Zend_Filter_Interface');
6497

65-
$this->appStateMock = $this->getMockBuilder('Magento\Framework\App\State')
98+
$this->resourceFactoryMock->expects($this->any())
99+
->method('create')
100+
->willReturn($this->resourceMock);
101+
$this->cacheManagerMock = $this->getMockBuilder('Magento\Translation\Model\Inline\CacheManager')
66102
->disableOriginalConstructor()
67103
->setMethods([])
68104
->getMock();
69105

70-
$this->appCacheMock = $this->getMockBuilder('Magento\Framework\App\Cache\TypeListInterface')
106+
$this->appStateMock = $this->getMockBuilder('Magento\Framework\App\State')
71107
->disableOriginalConstructor()
72108
->setMethods([])
73109
->getMock();
110+
}
74111

75-
$this->translateInlineMock= $this->getMockBuilder('Magento\Framework\Translate\InlineInterface')
76-
->disableOriginalConstructor()
77-
->setMethods([])
78-
->getMock();
112+
public function testProcessAjaxPostNotAllowed()
113+
{
114+
$expected = ['inline' => 'not allowed'];
115+
$this->translateInlineMock->expects($this->once())
116+
->method('isAllowed')
117+
->willReturn(false);
118+
$this->model = $this->objectManager->getObject(
119+
Parser::class,
120+
['translateInline' => $this->translateInlineMock]
121+
);
122+
$this->assertEquals($expected, $this->model->processAjaxPost([]));
123+
}
79124

80-
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
81-
$this->model = $objectManagerHelper->getObject(
82-
'Magento\Translation\Model\Inline\Parser',
125+
public function testProcessAjaxPost()
126+
{
127+
$this->translateInlineMock->expects($this->once())
128+
->method('isAllowed')
129+
->willReturn(true);
130+
$this->model = $this->objectManager->getObject(
131+
Parser::class,
83132
[
84-
"_resourceFactory" => $this->resourceMock,
85-
"_storeManager" => $this->storeManagerMock,
86-
"_inputFilter" => $this->inputFilterMock,
87-
"_appState" => $this->appStateMock,
88-
"_appCache" => $this->appCacheMock,
89-
"_translateInline" => $this->translateInlineMock
133+
'cacheManager' => $this->cacheManagerMock,
134+
'resource' => $this->resourceFactoryMock,
135+
'storeManager' => $this->storeManagerMock,
136+
'translateInline' => $this->translateInlineMock
90137
]
91138
);
139+
$this->model->processAjaxPost([]);
92140
}
93141

94142
public function testProcessResponseBodyStringProcessingAttributesCorrectly()
@@ -104,6 +152,21 @@ public function testProcessResponseBodyStringProcessingAttributesCorrectly()
104152
];
105153
$this->translateInlineMock->expects($this->any())->method('getAdditionalHtmlAttribute')->willReturn(null);
106154

155+
$this->model = $this->objectManager->getObject(
156+
Parser::class,
157+
[
158+
'cacheManager' => $this->cacheManagerMock,
159+
'resource' => $this->resourceFactoryMock,
160+
'storeManager' => $this->storeManagerMock,
161+
'translateInline' => $this->translateInlineMock,
162+
'_resourceFactory' => $this->resourceMock,
163+
'_inputFilter' => $this->inputFilterMock,
164+
'_appState' => $this->appStateMock,
165+
'_appCache' => $this->appCacheMock,
166+
'_translateInline' => $this->translateInlineMock
167+
]
168+
);
169+
107170
$processedContent = $this->model->processResponseBodyString($testContent);
108171
foreach ($processedAttributes as $attribute) {
109172
$this->assertContains($attribute, $processedContent, "data-translate attribute not processed correctly");

app/code/Magento/Widget/Test/Unit/Model/WidgetTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ public function testGetWidgetDeclarationWithZeroValueParam()
229229

230230
$result = $this->widget->getWidgetDeclaration('Magento\CatalogWidget\Block\Product\ProductsList', $params);
231231
$this->assertContains('{{widget type="Magento\CatalogWidget\Block\Product\ProductsList"', $result);
232-
$this->assertContains('conditions_encoded="encoded-conditions-string"', $result);
233232
$this->assertContains('page_var_name="pasdf"}}', $result);
234-
$this->assertContains('products_count="0"', $result);
233+
$this->assertContains('products_count=""', $result);
235234
}
236235
}

0 commit comments

Comments
 (0)