class TranslationTest

Same name in this branch
  1. 9 core/modules/field/tests/src/Kernel/TranslationTest.php \Drupal\Tests\field\Kernel\TranslationTest
Same name and namespace in other branches
  1. 11.x core/modules/field/tests/src/Kernel/TranslationTest.php \Drupal\Tests\field\Kernel\TranslationTest
  2. 11.x core/tests/Drupal/Tests/Core/Annotation/TranslationTest.php \Drupal\Tests\Core\Annotation\TranslationTest
  3. 10 core/modules/field/tests/src/Kernel/TranslationTest.php \Drupal\Tests\field\Kernel\TranslationTest
  4. 10 core/tests/Drupal/Tests/Core/Annotation/TranslationTest.php \Drupal\Tests\Core\Annotation\TranslationTest
  5. 8.9.x core/modules/field/tests/src/Kernel/TranslationTest.php \Drupal\Tests\field\Kernel\TranslationTest
  6. 8.9.x core/tests/Drupal/Tests/Core/Annotation/TranslationTest.php \Drupal\Tests\Core\Annotation\TranslationTest

@coversDefaultClass \Drupal\Core\Annotation\Translation
@group Annotation

Hierarchy

Expanded class hierarchy of TranslationTest

File

core/tests/Drupal/Tests/Core/Annotation/TranslationTest.php, line 13

Namespace

Drupal\Tests\Core\Annotation
View source
class TranslationTest extends UnitTestCase {
  
  /**
   * The translation manager used for testing.
   *
   * @var \Drupal\Core\StringTranslation\TranslationInterface|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $translationManager;
  
  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    $this->translationManager = $this->getStringTranslationStub();
  }
  
  /**
   * @covers ::get
   *
   * @dataProvider providerTestGet
   */
  public function testGet(array $values, $expected) {
    $container = new ContainerBuilder();
    $container->set('string_translation', $this->translationManager);
    \Drupal::setContainer($container);
    $annotation = new Translation($values);
    $this->assertSame($expected, (string) $annotation->get());
  }
  
  /**
   * Provides data to self::testGet().
   */
  public function providerTestGet() {
    $data = [];
    $data[] = [
      [
        'value' => 'Foo',
      ],
      'Foo',
    ];
    $random = $this->randomMachineName();
    $random_html_entity = '&' . $random;
    $data[] = [
      [
        'value' => 'Foo @bar @baz %qux',
        'arguments' => [
          '@bar' => $random,
          '@baz' => $random_html_entity,
          '%qux' => $random_html_entity,
        ],
        'context' => $this->randomMachineName(),
      ],
      'Foo ' . $random . ' &amp;' . $random . ' <em class="placeholder">&amp;' . $random . '</em>',
    ];
    return $data;
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.