class StringTranslationTraitTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/StringTranslation/StringTranslationTraitTest.php \Drupal\Tests\Core\StringTranslation\StringTranslationTraitTest
@coversDefaultClass \Drupal\Core\StringTranslation\StringTranslationTrait @group StringTranslation
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Core\StringTranslation\StringTranslationTraitTest
Expanded class hierarchy of StringTranslationTraitTest
File
- core/
tests/ Drupal/ Tests/ Core/ StringTranslation/ StringTranslationTraitTest.php, line 16 - Contains \Drupal\Tests\Core\StringTranslation\StringTranslationTraitTest.
Namespace
Drupal\Tests\Core\StringTranslationView source
class StringTranslationTraitTest extends UnitTestCase {
/**
* A reflection of self::$translation.
*
* @var \ReflectionClass
*/
protected $reflection;
/**
* The mock under test that uses StringTranslationTrait.
*
* @var object
* @see PHPUnit_Framework_MockObject_Generator::getObjectForTrait()
*/
protected $translation;
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->translation = $this
->getObjectForTrait('\\Drupal\\Core\\StringTranslation\\StringTranslationTrait');
$stub = $this
->getStringTranslationStub();
$stub
->expects($this
->any())
->method('formatPlural')
->will($this
->returnArgument(2));
$this->translation
->setStringTranslation($stub);
$this->reflection = new \ReflectionClass(get_class($this->translation));
}
/**
* @covers ::t
*/
public function testT() {
$method = $this->reflection
->getMethod('t');
$method
->setAccessible(TRUE);
$this
->assertEquals('something', $method
->invoke($this->translation, 'something'));
}
/**
* @covers ::formatPlural
*/
public function testFormatPlural() {
$method = $this->reflection
->getMethod('formatPlural');
$method
->setAccessible(TRUE);
$this
->assertEquals('apples', $method
->invoke($this->translation, 2, 'apple', 'apples'));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
StringTranslationTraitTest:: |
protected | property | A reflection of self::$translation. | |
StringTranslationTraitTest:: |
protected | property | The mock under test that uses StringTranslationTrait. | |
StringTranslationTraitTest:: |
protected | function |
Overrides UnitTestCase:: |
|
StringTranslationTraitTest:: |
public | function | @covers ::formatPlural | |
StringTranslationTraitTest:: |
public | function | @covers ::t | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in 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. |