Skip to content

Commit 02c01c0

Browse files
committed
[Shipping] Cover Helper Data by Unit Test
1 parent 36ea828 commit 02c01c0

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Shipping\Test\Unit\Helper;
9+
10+
use PHPUnit\Framework\TestCase;
11+
use Magento\Shipping\Helper\Data as HelperData;
12+
use Magento\Framework\Url\DecoderInterface;
13+
use Magento\Framework\App\Helper\Context;
14+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
15+
16+
/**
17+
* Data helper test
18+
*
19+
* Class \Magento\Shipping\Test\Unit\Helper\DataTest
20+
*/
21+
class DataTest extends TestCase
22+
{
23+
/**
24+
* @var HelperData
25+
*/
26+
private $helper;
27+
28+
/**
29+
* @var DecoderInterface|\PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
private $urlDecoderMock;
32+
33+
/**
34+
* @var Context|\PHPUnit_Framework_MockObject_MockObject
35+
*/
36+
private $contextMock;
37+
38+
/**
39+
* @var ObjectManagerHelper
40+
*/
41+
private $objectManagerHelper;
42+
43+
/**
44+
* Setup environment to test
45+
*/
46+
protected function setUp()
47+
{
48+
$this->contextMock = $this->createMock(Context::class);
49+
$this->urlDecoderMock = $this->createMock(DecoderInterface::class);
50+
$this->contextMock->expects($this->any())->method('getUrlDecoder')
51+
->willReturn($this->urlDecoderMock);
52+
$this->objectManagerHelper = new ObjectManagerHelper($this);
53+
54+
$this->helper = $this->objectManagerHelper->getObject(
55+
HelperData::class,
56+
[
57+
'context' => $this->contextMock
58+
]
59+
);
60+
}
61+
62+
/**
63+
* test decodeTrackingHash() with data provider below
64+
*
65+
* @param string $hash
66+
* @param string $urlDecodeResult
67+
* @param array $expected
68+
* @dataProvider decodeTrackingHashDataProvider
69+
*/
70+
public function testDecodeTrackingHash($hash, $urlDecodeResult, $expected)
71+
{
72+
$this->urlDecoderMock->expects($this->any())->method('decode')
73+
->with($hash)
74+
->willReturn($urlDecodeResult);
75+
$this->assertEquals($expected, $this->helper->decodeTrackingHash($hash));
76+
}
77+
78+
/**
79+
* Dataset to test getData()
80+
*
81+
* @return array
82+
*/
83+
public function decodeTrackingHashDataProvider()
84+
{
85+
return [
86+
'Test with hash key is allowed' => [
87+
strtr(base64_encode('order_id:1:protected_code'), '+/=', '-_,'),
88+
'order_id:1:protected_code',
89+
[
90+
'key' => 'order_id',
91+
'id' => 1,
92+
'hash' => 'protected_code'
93+
]
94+
],
95+
'Test with hash key is not allowed' => [
96+
strtr(base64_encode('invoice_id:1:protected_code'), '+/=', '-_,'),
97+
'invoice_id:1:protected_code',
98+
[]
99+
]
100+
];
101+
}
102+
}

0 commit comments

Comments
 (0)