class BatchInjectionCallbacks

Batch callbacks using dependency injection for testing batches.

Hierarchy

Expanded class hierarchy of BatchInjectionCallbacks

1 file declares its use of BatchInjectionCallbacks
BatchTestController.php in core/modules/system/tests/modules/batch_test/src/Controller/BatchTestController.php

File

core/modules/system/tests/modules/batch_test/src/BatchInjectionCallbacks.php, line 16

Namespace

Drupal\batch_test
View source
class BatchInjectionCallbacks {
  use StringTranslationTrait;
  public function __construct(protected readonly ThemeManagerInterface $themeManager, protected readonly RouteMatchInterface $routeMatch, protected readonly RequestStack $requestStack, protected readonly TitleResolverInterface $titleResolver) {
  }
  
  /**
   * Implements callback_batch_operation().
   *
   * Tests the progress page theme.
   */
  public function themeCallback() : void {
    $batch_test_helper = new BatchTestHelper();
    // Because drupalGet() steps through the full progressive batch before
    // returning control to the test function, we cannot test that the correct
    // theme is being used on the batch processing page by viewing that page
    // directly. Instead, we save the theme being used in a variable here, so
    // that it can be loaded and inspected in the thread running the test.
    $theme = $this->themeManager
      ->getActiveTheme()
      ->getName();
    $batch_test_helper->stack($theme);
  }
  
  /**
   * Tests the title on the progress page by performing a batch callback.
   */
  public function titleCallback() : void {
    $batch_test_helper = new BatchTestHelper();
    // Because drupalGet() steps through the full progressive batch before
    // returning control to the test function, we cannot test that the correct
    // title is being used on the batch processing page by viewing that page
    // directly. Instead, we save the title being used in a variable here, so
    // that it can be loaded and inspected in the thread running the test.
    $title = $this->titleResolver
      ->getTitle($this->requestStack
      ->getCurrentRequest(), $this->routeMatch
      ->getRouteObject());
    $batch_test_helper->stack($title);
  }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
BatchInjectionCallbacks::themeCallback public function Implements callback_batch_operation().
BatchInjectionCallbacks::titleCallback public function Tests the title on the progress page by performing a batch callback.
BatchInjectionCallbacks::__construct public function
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language. 1

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