You are here

public function UnitTestCase::getStringTranslationStub in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/UnitTestCase.php \Drupal\Tests\UnitTestCase::getStringTranslationStub()

Returns a stub translation manager that just returns the passed string.

Return value

\PHPUnit_Framework_MockObject_MockBuilder A MockBuilder of \Drupal\Core\StringTranslation\TranslationInterface

35 calls to UnitTestCase::getStringTranslationStub()
AggregatorPluginSettingsBaseTest::setUp in core/modules/aggregator/tests/src/Unit/Plugin/AggregatorPluginSettingsBaseTest.php
BaseFieldDefinitionTestBase::setUp in core/tests/Drupal/Tests/Core/Field/BaseFieldDefinitionTestBase.php
BookManagerTest::setUp in core/modules/book/tests/src/Unit/BookManagerTest.php
BookUninstallValidatorTest::setUp in core/modules/book/tests/src/Unit/BookUninstallValidatorTest.php
CategorizingPluginManagerTraitTest::setUp in core/tests/Drupal/Tests/Core/Plugin/CategorizingPluginManagerTraitTest.php

... See full list

File

core/tests/Drupal/Tests/UnitTestCase.php, line 209
Contains \Drupal\Tests\UnitTestCase.

Class

UnitTestCase
Provides a base class and helpers for Drupal unit tests.

Namespace

Drupal\Tests

Code

public function getStringTranslationStub() {
  $translation = $this
    ->getMock('Drupal\\Core\\StringTranslation\\TranslationInterface');
  $translation
    ->expects($this
    ->any())
    ->method('translate')
    ->willReturnCallback(function ($string, array $args = array(), array $options = array()) use ($translation) {
    return new TranslatableMarkup($string, $args, $options, $translation);
  });
  $translation
    ->expects($this
    ->any())
    ->method('translateString')
    ->willReturnCallback(function (TranslatableMarkup $wrapper) {
    return $wrapper
      ->getUntranslatedString();
  });
  $translation
    ->expects($this
    ->any())
    ->method('formatPlural')
    ->willReturnCallback(function ($count, $singular, $plural, array $args = [], array $options = []) use ($translation) {
    $wrapper = new PluralTranslatableMarkup($count, $singular, $plural, $args, $options, $translation);
    return $wrapper;
  });
  return $translation;
}