57 $this->contextMock = $this->getMockBuilder(\
Magento\Framework\
App\Helper\Context::class)
58 ->disableOriginalConstructor()
60 $this->storeManagerMock = $this->getMockBuilder(\
Magento\Store\Model\StoreManagerInterface::class)
61 ->disableOriginalConstructor()
63 $this->salesConfigMock = $this->getMockBuilder(\
Magento\Sales\Model\Config::class)
64 ->disableOriginalConstructor()
66 $this->priceCurrency = $this->getMockBuilder(
67 \
Magento\Framework\Pricing\PriceCurrencyInterface::class
70 $this->escaperMock = $this->getMockBuilder(\
Magento\Framework\Escaper::class)
71 ->disableOriginalConstructor()
74 $this->adminHelper = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject(
75 \
Magento\Sales\Helper\Admin::class,
77 'context' => $this->contextMock,
78 'storeManager' => $this->storeManagerMock,
79 'salesConfig' => $this->salesConfigMock,
80 'priceCurrency' => $this->priceCurrency,
81 'escaper' => $this->escaperMock
85 $this->magentoObjectMock = $this->getMockBuilder(\
Magento\Framework\DataObject::class)
86 ->disableOriginalConstructor()
87 ->setMethods([
'getOrder',
'getData'])
90 $this->orderMock = $this->getMockBuilder(\
Magento\Sales\Model\Order::class)
91 ->disableOriginalConstructor()
93 $this->orderMock->expects($this->any())
94 ->method(
'formatBasePrice')
95 ->will($this->returnValue(
'formattedBasePrice'));
96 $this->orderMock->expects($this->any())
97 ->method(
'formatPrice')
98 ->will($this->returnValue(
'formattedPrice'));
99 $this->orderMock->expects($this->any())
101 ->will($this->returnValue(
'data'));
116 $isCurrencyDifferent =
true,
117 $magentoDataObjectHasOrder =
true,
121 $this->orderMock->expects($this->any())
122 ->method(
'isCurrencyDifferent')
123 ->will($this->returnValue($isCurrencyDifferent));
124 $storeMock = $this->getMockBuilder(\
Magento\Store\Model\Store::class)
125 ->disableOriginalConstructor()
127 $this->storeManagerMock->expects($this->any())
129 ->will($this->returnValue($storeMock));
130 $this->priceCurrency->expects($this->any())
132 ->will($this->returnValue(
'storeFormattedPrice'));
134 if (!$dataObjectIsOrder) {
136 if ($magentoDataObjectHasOrder) {
139 $this->magentoObjectMock->expects($this->once())
141 ->will($this->returnValue($returnRes));
148 $this->adminHelper->displayPrices($dataObject, $basePrice,
$price, $strong, $separator)
164 $isCurrencyDifferent =
true,
165 $magentoDataObjectHasOrder =
true,
169 $this->orderMock->expects($this->any())
170 ->method(
'isCurrencyDifferent')
171 ->will($this->returnValue($isCurrencyDifferent));
172 $storeMock = $this->getMockBuilder(\
Magento\Store\Model\Store::class)
173 ->disableOriginalConstructor()
175 $this->storeManagerMock->expects($this->any())
177 ->will($this->returnValue($storeMock));
178 $this->priceCurrency->expects($this->any())
180 ->will($this->returnValue(
'storeFormattedPrice'));
182 if (!$dataObjectIsOrder) {
184 if ($magentoDataObjectHasOrder) {
187 $this->magentoObjectMock->expects($this->once())
189 ->will($this->returnValue($returnRes));
190 $this->magentoObjectMock->expects($this->any())
192 ->will($this->returnValue(
'data'));
197 $this->adminHelper->displayPriceAttribute($dataObject,
'code', $strong, $separator)
208 '<strong>formattedBasePrice</strong><br/>[formattedPrice]',
212 '<strong>formattedBasePrice</strong><br/>[formattedPrice]',
226 '<strong>formattedPrice</strong>',
233 '<strong>formattedPrice</strong>',
241 '<strong>formattedBasePrice</strong>seperator[formattedPrice]',
249 'storeFormattedPrice',
257 '<strong>storeFormattedPrice</strong>',
276 $productMock = $this->getMockBuilder(\
Magento\Catalog\Model\Product::class)
277 ->disableOriginalConstructor()
279 $productMock->expects($this->any())
280 ->method(
'getTypeId')
281 ->will($this->returnValue(
$type));
283 ->disableOriginalConstructor()
284 ->setMethods([
'__wakeup',
'getProductType'])
287 ->method(
'getProductType')
288 ->will($this->returnValue(
$type));
289 $quoteMock = $this->getMockBuilder(\
Magento\Quote\Model\Quote\Item::class)
290 ->disableOriginalConstructor()
292 $quoteMock->expects($this->any())
293 ->method(
'getProductType')
294 ->will($this->returnValue(
$type));
296 'product' => $productMock,
298 'quote' => $quoteMock,
301 $collectionClassName = \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection::class;
302 $collectionMock = $this->getMockBuilder($collectionClassName)
303 ->disableOriginalConstructor()
305 $collectionMock->expects($this->any())
307 ->will($this->returnValue([
$items[$itemKey]]));
308 $collectionMock->expects($this->exactly($calledTimes))
309 ->method(
'removeItemByKey');
310 $this->salesConfigMock->expects($this->any())
311 ->method(
'getAvailableProductTypes')
312 ->will($this->returnValue([
'validProductType']));
313 $this->adminHelper->applySalableProductTypesFilter($collectionMock);
322 [
'product',
'validProductType', 0],
323 [
'product',
'invalidProductType', 1],
324 [
'order',
'validProductType', 0],
325 [
'order',
'invalidProductType', 1],
326 [
'quote',
'validProductType', 0],
327 [
'quote',
'invalidProductType', 1],
328 [
'other',
'validProductType', 1],
341 ->expects($this->any())
342 ->method(
'escapeHtml')
343 ->will($this->returnValue($expected));
344 $actual = $this->adminHelper->escapeHtmlWithLinks(
$data, $allowedTags);
345 $this->assertEquals($expected, $actual);
355 '<a>some text in tags</a>',
356 '<a>some text in tags</a>',
357 'allowedTags' => null
360 'Transaction ID: "<a target="_blank" href="https://www.paypal.com/?id=XX123XX">XX123XX</a>"',
361 'Transaction ID: "<a target="_blank" href="https://www.paypal.com/?id=XX123XX">XX123XX</a>"',
362 'allowedTags' => [
'b',
'br',
'strong',
'i',
'u',
'a']
365 '<a>some text in tags</a>',
366 '<a>some text in tags</a>',
367 'allowedTags' => [
'a']
369 'Not replacement with placeholders' => [
370 "<a><script>alert(1)</script></a>",
371 '<a><script>alert(1)</script></a>',
372 'allowedTags' => [
'a']
374 'Normal usage, url escaped' => [
375 '<a href=\"#\">Foo</a>',
376 '<a href="#">Foo</a>',
377 'allowedTags' => [
'a']
379 'Normal usage, url not escaped' => [
380 "<a href=http://example.com?foo=1&bar=2&baz[name]=BAZ>Foo</a>",
381 '<a href="http://example.com?foo=1&bar=2&baz[name]=BAZ">Foo</a>',
382 'allowedTags' => [
'a']
385 "<a href=\"javascript:alert(59)\">Foo</a>",
386 '<a href="#">Foo</a>',
387 'allowedTags' => [
'a']
389 'Additional regex test' => [
390 "<a href=\"http://example1.com\" href=\"http://example2.com\">Foo</a>",
391 '<a href="http://example1.com">Foo</a>',
392 'allowedTags' => [
'a']
394 'Break of valid urls' => [
395 "<a href=\"http://example.com?foo=text with space\">Foo</a>",
396 '<a href="#">Foo</a>',
397 'allowedTags' => [
'a']
testDisplayPrices( $expected, $dataObjectIsOrder, $isCurrencyDifferent=true, $magentoDataObjectHasOrder=true, $strong=false, $separator='< br/>')
testEscapeHtmlWithLinks($data, $expected, $allowedTags=null)
displayPricesDataProvider()
applySalableProductTypesFilterDataProvider()
escapeHtmlWithLinksDataProvider()
testDisplayPriceAttribute( $expected, $dataObjectIsOrder, $isCurrencyDifferent=true, $magentoDataObjectHasOrder=true, $strong=false, $separator='< br/>')
testApplySalableProductTypesFilter($itemKey, $type, $calledTimes)