|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright 2024 Adobe |
| 4 | + * All Rights Reserved. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\CustomerImportExport\Test\Unit\Model\Import; |
| 9 | + |
| 10 | +use PHPUnit\Framework\TestCase; |
| 11 | +use Magento\CustomerImportExport\Model\Import\CountryWithWebsites; |
| 12 | +use Magento\Directory\Model\ResourceModel\Country\CollectionFactory as CountryCollectionFactory; |
| 13 | +use Magento\Directory\Model\AllowedCountries; |
| 14 | +use Magento\Store\Model\StoreManagerInterface; |
| 15 | +use Magento\Customer\Model\Config\Share as CustomerShareConfig; |
| 16 | +use Magento\Store\Api\Data\WebsiteInterface; |
| 17 | +use Magento\Store\Model\ScopeInterface; |
| 18 | +use Magento\Directory\Model\ResourceModel\Country\Collection as CountryCollection; |
| 19 | + |
| 20 | +class CountryWithWebsitesTest extends TestCase |
| 21 | +{ |
| 22 | + private $countriesFactoryMock; |
| 23 | + private $allowedCountriesReaderMock; |
| 24 | + private $storeManagerMock; |
| 25 | + private $shareConfigMock; |
| 26 | + private $countryWithWebsites; |
| 27 | + |
| 28 | + protected function setUp(): void |
| 29 | + { |
| 30 | + $this->countriesFactoryMock = $this->createMock(CountryCollectionFactory::class); |
| 31 | + $this->allowedCountriesReaderMock = $this->createMock(AllowedCountries::class); |
| 32 | + $this->storeManagerMock = $this->createMock(StoreManagerInterface::class); |
| 33 | + $this->shareConfigMock = $this->createMock(CustomerShareConfig::class); |
| 34 | + |
| 35 | + $this->countryWithWebsites = new CountryWithWebsites( |
| 36 | + $this->countriesFactoryMock, |
| 37 | + $this->allowedCountriesReaderMock, |
| 38 | + $this->storeManagerMock, |
| 39 | + $this->shareConfigMock |
| 40 | + ); |
| 41 | + } |
| 42 | + |
| 43 | + public function testGetCountiesPerWebsite() |
| 44 | + { |
| 45 | + $websiteMock = $this->createMock(WebsiteInterface::class); |
| 46 | + $websiteMock->method('getId')->willReturn(1); |
| 47 | + |
| 48 | + $this->storeManagerMock->method('getWebsites')->willReturn([$websiteMock]); |
| 49 | + $this->allowedCountriesReaderMock->method('getAllowedCountries') |
| 50 | + ->with(ScopeInterface::SCOPE_WEBSITE, 1) |
| 51 | + ->willReturn(['US', 'CA']); |
| 52 | + |
| 53 | + $countryCollectionMock = $this->createMock(CountryCollection::class); |
| 54 | + $countryCollectionMock->method('addFieldToFilter') |
| 55 | + ->with('country_id', ['in' => [['US', 'CA']]]) |
| 56 | + ->willReturnSelf(); |
| 57 | + $countryCollectionMock->method('toOptionArray') |
| 58 | + ->willReturn([ |
| 59 | + ['value' => 'US', 'label' => 'United States'], |
| 60 | + ['value' => 'CA', 'label' => 'Canada'] |
| 61 | + ]); |
| 62 | + |
| 63 | + $this->countriesFactoryMock->method('create')->willReturn($countryCollectionMock); |
| 64 | + |
| 65 | + $expectedResult = [ |
| 66 | + ['value' => 'US', 'label' => 'United States', 'website_ids' => [1]], |
| 67 | + ['value' => 'CA', 'label' => 'Canada', 'website_ids' => [1]] |
| 68 | + ]; |
| 69 | + |
| 70 | + $this->assertEquals($expectedResult, $this->countryWithWebsites->getCountiesPerWebsite()); |
| 71 | + } |
| 72 | +} |
0 commit comments