‪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 
20 use PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
27 final class ‪CountryProviderTest extends UnitTestCase
28 {
29  #[Test]
31  {
32  $subject = new ‪CountryProvider();
33  ‪$countries = $subject->getAll();
34  self::assertGreaterThan(150, count(‪$countries));
35  }
36 
37  #[Test]
38  public function ‪findByIsoCodeReturnsValidObject(): void
39  {
40  $subject = new ‪CountryProvider();
41  $countryIsoCode2LowerCase = $subject->getByIsoCode('fr');
42  $countryIsoCode2 = $subject->getByIsoCode('FR');
43  self::assertInstanceOf(Country::class, $countryIsoCode2);
44  self::assertSame($countryIsoCode2LowerCase, $countryIsoCode2);
45  self::assertEquals('France', $countryIsoCode2->getName());
46  self::assertEquals('French Republic', $countryIsoCode2->getOfficialName());
47  }
48 
49  #[Test]
51  {
52  $subject = new ‪CountryProvider();
53  $countryIsoCode3LowerCase = $subject->getByIsoCode('fra');
54  $countryIsoCode3 = $subject->getByIsoCode('FRA');
55  $countryIsoCode2 = $subject->getByIsoCode('FR');
56  self::assertInstanceOf(Country::class, $countryIsoCode2);
57  self::assertSame($countryIsoCode3LowerCase, $countryIsoCode2);
58  self::assertSame($countryIsoCode3, $countryIsoCode2);
59  self::assertEquals('France', $countryIsoCode3->getName());
60  self::assertEquals('🇫🇷', $countryIsoCode3->getFlag());
61  self::assertEquals('French Republic', $countryIsoCode3->getOfficialName());
62  self::assertEquals('250', $countryIsoCode3->getNumericRepresentation());
63  self::assertEquals('FR', $countryIsoCode3->getAlpha2IsoCode());
64  self::assertEquals('FRA', $countryIsoCode3->getAlpha3IsoCode());
65  }
66 
67  #[DataProvider('findByFilterReturnsValidObjectDataProvider')]
68  #[Test]
69  public function ‪findByFilterReturnsValidObject(int $expectedCount, array $excludedCountries, array $includedCountries): void
70  {
71  $subject = new ‪CountryProvider();
72  $filter = new ‪CountryFilter();
73  $filter
74  ->setOnlyCountries($includedCountries)
75  ->setExcludeCountries($excludedCountries);
76  $list = $subject->getFiltered($filter);
77  self::assertCount($expectedCount, $list);
78  }
79 
80  public static function ‪findByFilterReturnsValidObjectDataProvider(): array
81  {
82  return [
83  'full list' => [249, [], []],
84  'invalid list' => [0, ['ABC', 'DEF'], ['GHI']],
85  'list with included only' => [4, [], ['AT', 'DEU', 'ABC', 'py', 'plw', 'DEF']],
86  'list with excluded only' => [245, ['AT', 'DEU', 'ABC', 'py', 'plw', 'DEF'], []],
87  'combined list' => [2, ['CF', 'CH', 'cz', 'abc'], ['efg', 'FI', 'FJ', 'CH', 'cz', 'abc']],
88  ];
89  }
90 }
‪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:50
‪TYPO3\CMS\Core\Tests\Unit\Country\CountryProviderTest\findByFilterReturnsValidObjectDataProvider
‪static findByFilterReturnsValidObjectDataProvider()
Definition: CountryProviderTest.php:80
‪TYPO3\CMS\Core\Tests\Unit\Country\CountryProviderTest
Definition: CountryProviderTest.php:28
‪TYPO3\CMS\Core\Tests\Unit\Country\CountryProviderTest\findByFilterReturnsValidObject
‪findByFilterReturnsValidObject(int $expectedCount, array $excludedCountries, array $includedCountries)
Definition: CountryProviderTest.php:69
‪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:38
‪TYPO3\CMS\Core\Country\CountryProvider
Definition: CountryProvider.php:26