More updates to stop using dev or alpha or beta versions.
[yaffs-website] / web / core / tests / Drupal / Tests / Core / StringTranslation / StringTranslationTraitTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\StringTranslation;
4
5 use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
6 use Drupal\Core\StringTranslation\TranslatableMarkup;
7 use Drupal\Core\StringTranslation\TranslationInterface;
8 use Drupal\Tests\UnitTestCase;
9 use Prophecy\Argument;
10
11 /**
12  * @coversDefaultClass \Drupal\Core\StringTranslation\StringTranslationTrait
13  * @group StringTranslation
14  */
15 class StringTranslationTraitTest extends UnitTestCase {
16
17   /**
18    * A reflection of self::$translation.
19    *
20    * @var \ReflectionClass
21    */
22   protected $reflection;
23
24   /**
25    * The mock under test that uses StringTranslationTrait.
26    *
27    * @var object
28    * @see PHPUnit_Framework_MockObject_Generator::getObjectForTrait()
29    */
30   protected $translation;
31
32   /**
33    * {@inheritdoc}
34    */
35   protected function setUp() {
36     $this->translation = $this->getObjectForTrait('\Drupal\Core\StringTranslation\StringTranslationTrait');
37     $mock = $this->prophesize(TranslationInterface::class);
38     $mock->translate(Argument::cetera())->shouldNotBeCalled();
39     $mock->formatPlural(Argument::cetera())->shouldNotBeCalled();
40     $mock->translateString(Argument::cetera())->will(function ($args) {
41       return $args[0]->getUntranslatedString();
42     });
43     $this->translation->setStringTranslation($mock->reveal());
44     $this->reflection = new \ReflectionClass(get_class($this->translation));
45   }
46
47   /**
48    * @covers ::t
49    */
50   public function testT() {
51     $method = $this->reflection->getMethod('t');
52     $method->setAccessible(TRUE);
53
54     $result = $method->invoke($this->translation, 'something');
55     $this->assertInstanceOf(TranslatableMarkup::class, $result);
56     $this->assertEquals('something', $result);
57   }
58
59   /**
60    * @covers ::formatPlural
61    */
62   public function testFormatPlural() {
63     $method = $this->reflection->getMethod('formatPlural');
64     $method->setAccessible(TRUE);
65
66     $result = $method->invoke($this->translation, 2, 'apple', 'apples');
67     $this->assertInstanceOf(PluralTranslatableMarkup::class, $result);
68     $this->assertEquals('apples', $result);
69   }
70
71 }