function UnitTestCase::getStringTranslationStub

Same name in other branches
  1. 9 core/tests/Drupal/Tests/UnitTestCase.php \Drupal\Tests\UnitTestCase::getStringTranslationStub()
  2. 8.9.x core/tests/Drupal/Tests/UnitTestCase.php \Drupal\Tests\UnitTestCase::getStringTranslationStub()
  3. 10 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\MockObject|\Drupal\Core\StringTranslation\TranslationInterface A mock translation object.

71 calls to UnitTestCase::getStringTranslationStub()
BanAdminTest::testIpValidation in core/modules/ban/tests/src/Unit/BanAdminTest.php
Tests various user input to confirm correct validation.
BanAdminTest::testRouteParameter in core/modules/ban/tests/src/Unit/BanAdminTest.php
Test passing an IP address as a route parameter.
BanAdminTest::testSubmit in core/modules/ban/tests/src/Unit/BanAdminTest.php
Test form submission.
BaseFieldDefinitionTestBase::setUp in core/tests/Drupal/Tests/Core/Field/BaseFieldDefinitionTestBase.php
BlockManagerTest::setUp in core/tests/Drupal/Tests/Core/Block/BlockManagerTest.php

... See full list

File

core/tests/Drupal/Tests/UnitTestCase.php, line 169

Class

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

Namespace

Drupal\Tests

Code

public function getStringTranslationStub() {
    $translation = $this->createMock('Drupal\\Core\\StringTranslation\\TranslationInterface');
    $translation->expects($this->any())
        ->method('translate')
        ->willReturnCallback(function ($string, array $args = [], array $options = []) 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;
}

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