class TranslationMock in Plugin 8.2
Provides a mock implementation of \Drupal\Core\StringTranslation\TranslationInterface.
This is an alternative to UnitTestCase::getStringTranslationStub(), which cannot be used inside usort() callbacks, for instance.
Hierarchy
- class \Drupal\Tests\plugin\Unit\TranslationMock implements TranslationInterface
Expanded class hierarchy of TranslationMock
1 file declares its use of TranslationMock
- ListPluginTypesTest.php in tests/
src/ Unit/ Controller/ ListPluginTypesTest.php
File
- tests/
src/ Unit/ TranslationMock.php, line 15
Namespace
Drupal\Tests\plugin\UnitView source
class TranslationMock implements TranslationInterface {
/**
* {@inheritdoc}
*/
public function translate($string, array $args = array(), array $options = array()) {
return new TranslatableMarkup($string, $args, $options);
}
/**
* {@inheritdoc}
*/
public function translateString(TranslatableMarkup $translatable_string) {
return new FormattableMarkup($translatable_string
->getUntranslatedString(), $translatable_string
->getArguments());
}
/**
* {@inheritdoc}
*/
public function formatPlural($count, $singular, $plural, array $args = array(), array $options = array()) {
return $count === 1 ? new FormattableMarkup($singular, $args) : new FormattableMarkup($plural, $args + [
'@count' => $count,
]);
}
/**
* {@inheritdoc}
*/
public function formatPluralTranslated($count, $translation, array $args = array(), array $options = array()) {
return new FormattableMarkup($translation, $args);
}
/**
* {@inheritdoc}
*/
public function getNumberOfPlurals($langcode = NULL) {
return mt_rand();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TranslationMock:: |
public | function |
Formats a string containing a count of items. Overrides TranslationInterface:: |
|
TranslationMock:: |
public | function | ||
TranslationMock:: |
public | function | ||
TranslationMock:: |
public | function |
Translates a string to the current language or to a given language. Overrides TranslationInterface:: |
|
TranslationMock:: |
public | function |
Translates a TranslatableMarkup object to a string. Overrides TranslationInterface:: |