class CurrencyLocaleTest in Currency 8.3
Same name in this branch
- 8.3 tests/src/Kernel/CurrencyLocaleTest.php \Drupal\Tests\currency\Kernel\CurrencyLocaleTest
- 8.3 tests/src/Unit/Entity/CurrencyLocaleTest.php \Drupal\Tests\currency\Unit\Entity\CurrencyLocaleTest
@coversDefaultClass \Drupal\currency\Entity\CurrencyLocale
@group Currency
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\currency\Unit\Entity\CurrencyLocaleTest
Expanded class hierarchy of CurrencyLocaleTest
File
- tests/
src/ Unit/ Entity/ CurrencyLocaleTest.php, line 16
Namespace
Drupal\Tests\currency\Unit\EntityView source
class CurrencyLocaleTest extends UnitTestCase {
/**
* The country manager.
*
* @var \Drupal\Core\Locale\CountryManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $countryManager;
/**
* The string translator.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $stringTranslation;
/**
* The class under test.
*
* @var \Drupal\currency\Entity\CurrencyLocale
*/
protected $sut;
/**
* {@inheritdoc}
*
* @covers ::setCountryManager
*/
function setUp() : void {
$this->countryManager = $this
->createMock(CountryManagerInterface::class);
$this->stringTranslation = $this
->getStringTranslationStub();
$this->sut = new CurrencyLocale([], $this
->randomMachineName());
$this->sut
->setCountryManager($this->countryManager);
$this->sut
->setStringTranslation($this->stringTranslation);
}
/**
* @covers ::setDecimalSeparator
* @covers ::getDecimalSeparator
*/
function testGetDecimalSeparator() {
$separator = $this
->randomMachineName();
$this
->assertSame($this->sut, $this->sut
->setDecimalSeparator($separator));
$this
->assertSame($separator, $this->sut
->getDecimalSeparator());
}
/**
* @covers ::setGroupingSeparator
* @covers ::getGroupingSeparator
*/
function testGetGroupingSeparator() {
$separator = $this
->randomMachineName();
$this
->assertSame($this->sut, $this->sut
->setGroupingSeparator($separator));
$this
->assertSame($separator, $this->sut
->getGroupingSeparator());
}
/**
* @covers ::setLocale
* @covers ::getLocale
*/
function testGetLocale() {
$language_code = $this
->randomMachineName();
$country_code = $this
->randomMachineName();
$this
->assertSame($this->sut, $this->sut
->setLocale($language_code, $country_code));
$this
->assertSame(strtolower($language_code) . '_' . strtoupper($country_code), $this->sut
->getLocale());
}
/**
* @covers ::id
*
* @depends testGetLocale
*/
function testId() {
$language_code = $this
->randomMachineName();
$country_code = $this
->randomMachineName();
$this
->assertSame($this->sut, $this->sut
->setLocale($language_code, $country_code));
$this
->assertSame(strtolower($language_code) . '_' . strtoupper($country_code), $this->sut
->id());
}
/**
* @covers ::getLanguageCode
*
* @depends testGetLocale
*/
function testGetLanguageCode() {
$language_code = $this
->randomMachineName();
$country_code = $this
->randomMachineName();
$this
->assertSame($this->sut, $this->sut
->setLocale($language_code, $country_code));
$this
->assertSame(strtolower($language_code), $this->sut
->getLanguageCode());
}
/**
* @covers ::getCountryCode
*
* @depends testGetLocale
*/
function testGetCountryCode() {
$language_code = $this
->randomMachineName();
$country_code = $this
->randomMachineName();
$this
->assertSame($this->sut, $this->sut
->setLocale($language_code, $country_code));
$this
->assertSame(strtoupper($country_code), $this->sut
->getCountryCode());
}
/**
* @covers ::setPattern
* @covers ::getPattern
*/
function testGetPattern() {
$pattern = $this
->randomMachineName();
$this
->assertSame($this->sut, $this->sut
->setPattern($pattern));
$this
->assertSame($pattern, $this->sut
->getPattern());
}
/**
* @covers ::label
* @covers ::getCountryManager
*
* @depends testGetLocale
*/
function testLabel() {
$languages = LanguageManager::getStandardLanguageList();
$language_code = array_rand($languages);
$country_code_a = strtoupper($this
->randomMachineName());
$country_code_b = strtoupper($this
->randomMachineName());
$country_code_c = strtoupper($this
->randomMachineName());
$country_list = [
$country_code_a => $this
->randomMachineName(),
$country_code_b => $this
->randomMachineName(),
$country_code_c => $this
->randomMachineName(),
];
$this->countryManager
->expects($this
->atLeastOnce())
->method('getList')
->willReturn($country_list);
$this->sut
->setLocale($language_code, $country_code_b);
$this
->assertInstanceOf(TranslatableMarkup::class, $this->sut
->label());
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CurrencyLocaleTest:: |
protected | property | The country manager. | |
CurrencyLocaleTest:: |
protected | property | The string translator. | |
CurrencyLocaleTest:: |
protected | property | The class under test. | |
CurrencyLocaleTest:: |
function |
@covers ::setCountryManager Overrides UnitTestCase:: |
||
CurrencyLocaleTest:: |
function | @covers ::getCountryCode | ||
CurrencyLocaleTest:: |
function | @covers ::setDecimalSeparator @covers ::getDecimalSeparator | ||
CurrencyLocaleTest:: |
function | @covers ::setGroupingSeparator @covers ::getGroupingSeparator | ||
CurrencyLocaleTest:: |
function | @covers ::getLanguageCode | ||
CurrencyLocaleTest:: |
function | @covers ::setLocale @covers ::getLocale | ||
CurrencyLocaleTest:: |
function | @covers ::setPattern @covers ::getPattern | ||
CurrencyLocaleTest:: |
function | @covers ::id | ||
CurrencyLocaleTest:: |
function | @covers ::label @covers ::getCountryManager | ||
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |