CountryToCodeTest.php in Tamper 8
File
tests/src/Unit/Plugin/Tamper/CountryToCodeTest.php
View source
<?php
namespace Drupal\Tests\tamper\Unit\Plugin\Tamper;
use Drupal\Core\Locale\CountryManagerInterface;
use Drupal\tamper\Plugin\Tamper\CountryToCode;
class CountryToCodeTest extends TamperPluginTestBase {
protected $countryManagerMock;
protected function instantiatePlugin() {
return new CountryToCode([], 'country_to_code', [], $this
->getMockSourceDefinition());
}
protected function setUp() {
$this->countryManagerMock = $this
->createMock(CountryManagerInterface::class);
$this->countryManagerMock
->expects($this
->any())
->method('getList')
->will($this
->returnValue([
'AG' => 'Antigua and Barbuda',
'CA' => 'Canada',
'US' => 'United States of America',
]));
parent::setUp();
$this->plugin
->setCountryManager($this->countryManagerMock);
}
public function testCountryCodeTitleCaseCountry() {
$this
->assertEquals('CA', $this->plugin
->tamper('Canada'));
}
public function testCountryCodeUpperCaseCountry() {
$this
->assertEquals('US', $this->plugin
->tamper('UNITED STATES OF AMERICA'));
}
public function testCountryCodeLowerCaseCountry() {
$this
->assertEquals('AG', $this->plugin
->tamper('antigua and barbuda'));
}
}