Skip to content

Commit e72b3f7

Browse files
ENGCOM-6392: [Checkout] Cover DirectoryData by Unit Test #25905
2 parents 57a2aad + b33010e commit e72b3f7

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Checkout\Test\Unit\CustomerData;
10+
11+
use Magento\Checkout\CustomerData\DirectoryData;
12+
use Magento\Directory\Helper\Data as HelperData;
13+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
14+
use Magento\Directory\Model\Country;
15+
use PHPUnit\Framework\TestCase;
16+
17+
class DirectoryDataTest extends TestCase
18+
{
19+
/**
20+
* @var DirectoryData
21+
*/
22+
private $model;
23+
24+
/**
25+
* @var HelperData|\PHPUnit_Framework_MockObject_MockObject
26+
*/
27+
private $directoryHelperMock;
28+
29+
/**
30+
* @var ObjectManagerHelper
31+
*/
32+
private $objectManager;
33+
34+
/**
35+
* Setup environment for testing
36+
*/
37+
protected function setUp()
38+
{
39+
$this->objectManager = new ObjectManagerHelper($this);
40+
$this->directoryHelperMock = $this->createMock(HelperData::class);
41+
42+
$this->model = $this->objectManager->getObject(
43+
DirectoryData::class,
44+
[
45+
'directoryHelper' => $this->directoryHelperMock
46+
]
47+
);
48+
}
49+
50+
/**
51+
* Test getSectionData() function
52+
*/
53+
public function testGetSectionData()
54+
{
55+
$regions = [
56+
'US' => [
57+
'TX' => [
58+
'code' => 'TX',
59+
'name' => 'Texas'
60+
]
61+
]
62+
];
63+
64+
$testCountryInfo = $this->objectManager->getObject(Country::class);
65+
$testCountryInfo->setData('country_id', 'US');
66+
$testCountryInfo->setData('iso2_code', 'US');
67+
$testCountryInfo->setData('iso3_code', 'USA');
68+
$testCountryInfo->setData('name_default', 'United States of America');
69+
$testCountryInfo->setData('name_en_US', 'United States of America');
70+
$countries = ['US' => $testCountryInfo];
71+
72+
$this->directoryHelperMock->expects($this->any())
73+
->method('getRegionData')
74+
->willReturn($regions);
75+
76+
$this->directoryHelperMock->expects($this->any())
77+
->method('getCountryCollection')
78+
->willReturn($countries);
79+
80+
/* Assert result */
81+
$this->assertEquals(
82+
[
83+
'US' => [
84+
'name' => 'United States of America',
85+
'regions' => [
86+
'TX' => [
87+
'code' => 'TX',
88+
'name' => 'Texas'
89+
]
90+
]
91+
]
92+
],
93+
$this->model->getSectionData()
94+
);
95+
}
96+
}

0 commit comments

Comments
 (0)