‪TYPO3CMS  ‪main
CountryProviderTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
25 final class ‪CountryProviderTest extends UnitTestCase
26 {
31  {
32  $subject = new ‪CountryProvider();
33  ‪$countries = $subject->getAll();
34  self::assertGreaterThan(150, count(‪$countries));
35  }
36 
40  public function ‪findByIsoCodeReturnsValidObject(): void
41  {
42  $subject = new ‪CountryProvider();
43  $countryIsoCode2LowerCase = $subject->getByIsoCode('fr');
44  $countryIsoCode2 = $subject->getByIsoCode('FR');
45  self::assertInstanceOf(Country::class, $countryIsoCode2);
46  self::assertSame($countryIsoCode2LowerCase, $countryIsoCode2);
47  self::assertEquals('France', $countryIsoCode2->getName());
48  self::assertEquals('French Republic', $countryIsoCode2->getOfficialName());
49  }
50 
55  {
56  $subject = new ‪CountryProvider();
57  $countryIsoCode3LowerCase = $subject->getByIsoCode('fra');
58  $countryIsoCode3 = $subject->getByIsoCode('FRA');
59  $countryIsoCode2 = $subject->getByIsoCode('FR');
60  self::assertInstanceOf(Country::class, $countryIsoCode2);
61  self::assertSame($countryIsoCode3LowerCase, $countryIsoCode2);
62  self::assertSame($countryIsoCode3, $countryIsoCode2);
63  self::assertEquals('France', $countryIsoCode3->getName());
64  self::assertEquals('🇫🇷', $countryIsoCode3->getFlag());
65  self::assertEquals('French Republic', $countryIsoCode3->getOfficialName());
66  self::assertEquals('250', $countryIsoCode3->getNumericRepresentation());
67  self::assertEquals('FR', $countryIsoCode3->getAlpha2IsoCode());
68  self::assertEquals('FRA', $countryIsoCode3->getAlpha3IsoCode());
69  }
70 
75  public function ‪findByFilterReturnsValidObject(int $expectedCount, array $excludedCountries, array $includedCountries): void
76  {
77  $subject = new ‪CountryProvider();
78  $filter = new ‪CountryFilter();
79  $filter
80  ->setOnlyCountries($includedCountries)
81  ->setExcludeCountries($excludedCountries);
82  $list = $subject->getFiltered($filter);
83  self::assertCount($expectedCount, $list);
84  }
85 
86  public static function ‪findByFilterReturnsValidObjectDataProvider(): array
87  {
88  return [
89  'full list' => [249, [], []],
90  'invalid list' => [0, ['ABC', 'DEF'], ['GHI']],
91  'list with included only' => [4, [], ['AT', 'DEU', 'ABC', 'py', 'plw', 'DEF']],
92  'list with excluded only' => [245, ['AT', 'DEU', 'ABC', 'py', 'plw', 'DEF'], []],
93  'combined list' => [2, ['CF', 'CH', 'cz', 'abc'], ['efg', 'FI', 'FJ', 'CH', 'cz', 'abc']],
94  ];
95  }
96 }
‪TYPO3\CMS\Core\Tests\Unit\Country\CountryProviderTest\findAllCountriesReturnsCountryObjects
‪findAllCountriesReturnsCountryObjects()
Definition: CountryProviderTest.php:30
‪$countries
‪$countries
Definition: updateIsoDatabase.php:172
‪TYPO3\CMS\Core\Country\CountryFilter
Definition: CountryFilter.php:24
‪TYPO3\CMS\Core\Tests\Unit\Country\CountryProviderTest\findByThreeLetterIsoCodeReturnsValidObject
‪findByThreeLetterIsoCodeReturnsValidObject()
Definition: CountryProviderTest.php:54
‪TYPO3\CMS\Core\Tests\Unit\Country\CountryProviderTest\findByFilterReturnsValidObjectDataProvider
‪static findByFilterReturnsValidObjectDataProvider()
Definition: CountryProviderTest.php:86
‪TYPO3\CMS\Core\Tests\Unit\Country\CountryProviderTest
Definition: CountryProviderTest.php:26
‪TYPO3\CMS\Core\Tests\Unit\Country\CountryProviderTest\findByFilterReturnsValidObject
‪findByFilterReturnsValidObject(int $expectedCount, array $excludedCountries, array $includedCountries)
Definition: CountryProviderTest.php:75
‪TYPO3\CMS\Core\Country\Country
Definition: Country.php:25
‪TYPO3\CMS\Core\Tests\Unit\Country
Definition: CountryProviderTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Country\CountryProviderTest\findByIsoCodeReturnsValidObject
‪findByIsoCodeReturnsValidObject()
Definition: CountryProviderTest.php:40
‪TYPO3\CMS\Core\Country\CountryProvider
Definition: CountryProvider.php:26