setStringTranslation example

/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $configuration['settings'] = [
      'allowed_html' => '<a href> <p> <em> <strong> <cite> <blockquote> <code class="pretty boring align-*"> <ul alpaca-*="wooly-* strong"> <ol llama-*> <li> <dl> <dt> <dd> <br> <h3 id>',
      'filter_html_help' => 1,
      'filter_html_nofollow' => 0,
    ];
    $this->filter = new FilterHtml($configuration, 'filter_html', ['provider' => 'test']);
    $this->filter->setStringTranslation($this->getStringTranslationStub());
  }

  /** * @covers ::filterAttributes * * @dataProvider providerFilterAttributes * * @param string $html * Input HTML. * @param string $expected * The expected output string. */

        public function validate($module)
        {
            return $this->lazyLoadItself()->validate($module);
        }

        /** * {@inheritdoc} */
        public function setStringTranslation(\Drupal\Core\StringTranslation\TranslationInterface $translation)
        {
            return $this->lazyLoadItself()->setStringTranslation($translation);
        }

    }

}
/** * @return array */
      public function __serialize(): array {
        throw new \Exception();
      }

    };

    $this->container->set('bar', $translation_service);
    $entity_type->setStringTranslation($this->container->get('string_translation'));

    // This should not throw an exception.     $tmp = serialize($entity_type);
    $entity_type = unserialize($tmp);
    // And this should have the correct id.     $this->assertEquals('example_entity_type', $entity_type->id());
  }

}

  public function __construct(EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory, ForumManagerInterface $forum_manager, TranslationInterface $string_translation) {
    $this->entityTypeManager = $entity_type_manager;
    $this->config = $config_factory->get('forum.settings');
    $this->forumManager = $forum_manager;
    $this->setStringTranslation($string_translation);
    $this->termStorage = $entity_type_manager->getStorage('taxonomy_term');
  }

  /** * {@inheritdoc} */
  public function build(RouteMatchInterface $route_match) {
    $breadcrumb = new Breadcrumb();
    $breadcrumb->addCacheContexts(['route']);

    $links[] = Link::createFromRoute($this->t('Home'), '<front>');

    

class ProjectCoreCompatibilityTest extends UnitTestCase {

  /** * @covers ::setReleaseMessage * @dataProvider providerSetProjectCoreCompatibilityRanges */
  public function testSetProjectCoreCompatibilityRanges(array $project_data$core_data, array $core_releases, array $expected_releases, array $expected_security_updates) {
    $project_compatibility = new ProjectCoreCompatibility($core_data$core_releases);
    $project_compatibility->setStringTranslation($this->getStringTranslationStub());
    $project_compatibility->setReleaseMessage($project_data);
    $this->assertSame($expected_releases$project_data['releases']);
    $this->assertSame($expected_security_updates$project_data['security updates']);
  }

  /** * Data provider for testSetProjectCoreCompatibilityRanges(). */
  public function providerSetProjectCoreCompatibilityRanges() {
    $test_cases['no 9 releases'] = [
      'project_data' => [
        

  public function testValidate() {
    $definition = [
      'title' => 'Is InOperator Test',
      'group' => 'Test',
      'options callback' => '\Drupal\Tests\views\Unit\Plugin\filter\InOperatorTest::validate_options_callback',
    ];
    $filter = new InOperator([], 'in_operator', $definition);
    $filter->value = 'string';
    $filter->operator = 'in';
    $translation_stub = $this->getStringTranslationStub();
    $filter->setStringTranslation($translation_stub);
    $errors = $filter->validate();
    $this->assertSame('The value &#039;string&#039; is not an array for in on filter: ' . $filter->adminLabel(TRUE)(string) $errors[0]);
  }

  /** * @return array */
  public static function validate_options_callback() {
    return ['Yes', 'No'];
  }

}

        public function validate($module)
        {
            return $this->lazyLoadItself()->validate($module);
        }

        /** * {@inheritdoc} */
        public function setStringTranslation(\Drupal\Core\StringTranslation\TranslationInterface $translation)
        {
            return $this->lazyLoadItself()->setStringTranslation($translation);
        }

    }

}
protected $fieldTypePluginManager;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->fieldUninstallValidator = $this->getMockBuilder('Drupal\field\FieldUninstallValidator')
      ->disableOriginalConstructor()
      ->onlyMethods(['getFieldStoragesByModule', 'getFieldTypeLabel'])
      ->getMock();
    $this->fieldUninstallValidator->setStringTranslation($this->getStringTranslationStub());
  }

  /** * @covers ::validate */
  public function testValidateNoStorages() {
    $this->fieldUninstallValidator->expects($this->once())
      ->method('getFieldStoragesByModule')
      ->willReturn([]);

    $module = $this->randomMachineName();
    
protected $memoryLimit = 10000000;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->migration = $this->getMigration();
    $this->message = $this->createMock('Drupal\migrate\MigrateMessageInterface');

    $this->executable = new TestMigrateExecutable($this->migration, $this->message);
    $this->executable->setStringTranslation($this->getStringTranslationStub());
  }

  /** * Runs the actual test. * * @param string $message * The second message to assert. * @param bool $memory_exceeded * Whether to test the memory exceeded case. * @param int|null $memory_usage_first * (optional) The first memory usage value. Defaults to NULL. * @param int|null $memory_usage_second * (optional) The fake amount of memory usage reported after memory reclaim. * Defaults to NULL. * @param int|null $memory_limit * (optional) The memory limit. Defaults to NULL. */

  public function __construct(
    protected EntityTypeManagerInterface $entityTypeManager,
    protected EntityRepositoryInterface $entityRepository,
    protected DateFormatterInterface $dateFormatter,
    TranslationInterface $translation,
  ) {
    $this->setStringTranslation($translation);
  }

  /** * {@inheritdoc} */
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('entity_type.manager'),
      $container->get('entity.repository'),
      $container->get('date.formatter'),
      $container->get('string_translation'),
    );

  public function __construct(ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, CacheBackendInterface $cache_backend, TranslationInterface $string_translation) {
    $this->factory = new ContainerFactory($this);
    $this->moduleHandler = $module_handler;
    $this->themeHandler = $theme_handler;
    $this->setStringTranslation($string_translation);
    $this->alterInfo('breakpoints');
    $this->setCacheBackend($cache_backend, 'breakpoints', ['breakpoints']);
  }

  /** * {@inheritdoc} */
  protected function getDiscovery() {
    if (!isset($this->discovery)) {
      $this->discovery = new YamlDiscovery('breakpoints', $this->moduleHandler->getModuleDirectories() + $this->themeHandler->getThemeDirectories());
      $this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery);
    }
/** * {@inheritdoc} */
  public function getFormObject($entity_type_id$operation) {
    if (!$class = $this->getDefinition($entity_type_id, TRUE)->getFormClass($operation)) {
      throw new InvalidPluginDefinitionException($entity_type_idsprintf('The "%s" entity type did not specify a "%s" form class.', $entity_type_id$operation));
    }

    $form_object = $this->classResolver->getInstanceFromDefinition($class);

    return $form_object
      ->setStringTranslation($this->stringTranslation)
      ->setModuleHandler($this->moduleHandler)
      ->setEntityTypeManager($this)
      ->setOperation($operation);
  }

  /** * {@inheritdoc} */
  public function getRouteProviders($entity_type_id) {
    if (!isset($this->handlers['route_provider'][$entity_type_id])) {
      $route_provider_classes = $this->getDefinition($entity_type_id, TRUE)->getRouteProviderClasses();

      
protected $forumUninstallValidator;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->forumUninstallValidator = $this->getMockBuilder('Drupal\forum\ForumUninstallValidator')
      ->disableOriginalConstructor()
      ->onlyMethods(['hasForumNodes', 'hasTermsForVocabulary', 'getForumVocabulary'])
      ->getMock();
    $this->forumUninstallValidator->setStringTranslation($this->getStringTranslationStub());
  }

  /** * @covers ::validate */
  public function testValidateNotForum() {
    $this->forumUninstallValidator->expects($this->never())
      ->method('hasForumNodes');
    $this->forumUninstallValidator->expects($this->never())
      ->method('hasTermsForVocabulary');
    $this->forumUninstallValidator->expects($this->never())
      
protected $bookUninstallValidator;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->bookUninstallValidator = $this->getMockBuilder('Drupal\book\BookUninstallValidator')
      ->disableOriginalConstructor()
      ->onlyMethods(['hasBookOutlines', 'hasBookNodes'])
      ->getMock();
    $this->bookUninstallValidator->setStringTranslation($this->getStringTranslationStub());
  }

  /** * @covers ::validate */
  public function testValidateNotBook() {
    $this->bookUninstallValidator->expects($this->never())
      ->method('hasBookOutlines');
    $this->bookUninstallValidator->expects($this->never())
      ->method('hasBookNodes');

    

      ]
    );

    $forum_manager = $this->createMock('Drupal\forum\ForumManagerInterface');

    // Build a breadcrumb builder to test.     $breadcrumb_builder = new ForumListingBreadcrumbBuilder($entity_type_manager$config_factory$forum_manager$translation_manager);

    // Add a translation manager for t().     $translation_manager = $this->getStringTranslationStub();
    $breadcrumb_builder->setStringTranslation($translation_manager);

    // The forum listing we need a breadcrumb back from.     $prophecy = $this->prophesize('Drupal\taxonomy\Entity\Term');
    $prophecy->label()->willReturn('You_should_not_see_this');
    $prophecy->id()->willReturn(23);
    $prophecy->getCacheTags()->willReturn(['taxonomy_term:23']);
    $prophecy->getCacheContexts()->willReturn([]);
    $prophecy->getCacheMaxAge()->willReturn(Cache::PERMANENT);
    $forum_listing = $prophecy->reveal();

    // Our data set.
Home | Imprint | This part of the site doesn't use cookies.