function CountryCodeConstraintTest::testConstraintLoadsChoicesFromCountryManager
Same name in other branches
- 10 core/tests/Drupal/Tests/Core/Validation/Plugin/Validation/Constraint/CountryCodeConstraintTest.php \Drupal\Tests\Core\Validation\Plugin\Validation\Constraint\CountryCodeConstraintTest::testConstraintLoadsChoicesFromCountryManager()
File
-
core/
tests/ Drupal/ Tests/ Core/ Validation/ Plugin/ Validation/ Constraint/ CountryCodeConstraintTest.php, line 19
Class
- CountryCodeConstraintTest
- @covers \Drupal\Core\Validation\Plugin\Validation\Constraint\CountryCodeConstraint @group validation
Namespace
Drupal\Tests\Core\Validation\Plugin\Validation\ConstraintCode
public function testConstraintLoadsChoicesFromCountryManager() : void {
$countries = [
'US' => 'United States',
'CA' => 'Canada',
'MX' => 'Mexico',
];
// The CountryCode constraint should call the country manager's getList()
// method to compile a list of valid choices.
$country_manager = $this->createMock(CountryManagerInterface::class);
$country_manager->expects($this->atLeastOnce())
->method('getList')
->willReturn($countries);
$container = new ContainerBuilder();
$container->set(CountryManagerInterface::class, $country_manager);
$constraint = CountryCodeConstraint::create($container, [], 'CountryCode', []);
$this->assertInstanceOf(Choice::class, $constraint);
$this->assertSame(array_keys($countries), $constraint->choices);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.