determineActiveTheme example

public function testDetermineActiveThemeValidToken() {
    $theme = 'claro';
    $theme_token = 'valid_theme_token';

    $request = new Request();
    $request->query->set('ajax_page_state', ['theme' => $theme, 'theme_token' => $theme_token]);
    $this->requestStack->push($request);
    $route_match = RouteMatch::createFromRequest($request);

    $this->tokenGenerator->validate($theme_token$theme)->willReturn(TRUE);

    $result = $this->negotiator->determineActiveTheme($route_match);
    $this->assertSame($theme$result);
  }

  /** * @covers ::determineActiveTheme */
  public function testDetermineActiveThemeInvalidToken() {
    $theme = 'claro';
    $theme_token = 'invalid_theme_token';
    $request = new Request();
    $request->query->set('ajax_page_state', ['theme' => $theme, 'theme_token' => $theme_token]);
    

  protected function initTheme(RouteMatchInterface $route_match = NULL) {
    // Determine the active theme for the theme negotiator service. This includes     // the default theme as well as really specific ones like the ajax base theme.     if (!$route_match) {
      $route_match = \Drupal::routeMatch();
    }
    if ($route_match instanceof StackedRouteMatchInterface) {
      $route_match = $route_match->getMasterRouteMatch();
    }
    $theme = $this->themeNegotiator->determineActiveTheme($route_match);
    $this->activeTheme = $this->themeInitialization->initTheme($theme);
  }

  /** * {@inheritdoc} * * @todo Should we cache some of these information? */
  public function alterForTheme(ActiveTheme $theme$type, &$data, &$context1 = NULL, &$context2 = NULL) {
    // Most of the time, $type is passed as a string, so for performance,     // normalize it to that. When passed as an array, usually the first item in
->willReturn(TRUE);

    $this->container->set('test_negotiator', $negotiator);

    $negotiators = ['test_negotiator'];

    $this->themeAccessCheck->expects($this->any())
      ->method('checkAccess')
      ->willReturn(TRUE);

    $route_match = new RouteMatch('test_route', new Route('/test-route')[][]);
    $theme = $this->createThemeNegotiator($negotiators)->determineActiveTheme($route_match);

    $this->assertEquals('example_test', $theme);
  }

  /** * Tests determining with two negotiators checking the priority. * * @see \Drupal\Core\Theme\ThemeNegotiator::determineActiveTheme() */
  public function testDetermineActiveThemeWithPriority() {
    $negotiators = [];

    

  public function themePage($inherited) {
    $theme_key = $this->themeManager->getActiveTheme()->getName();
    // Now we check what the theme negotiator service returns.     $active_theme = $this->themeNegotiator
      ->determineActiveTheme($this->routeMatch);
    $output = "Active theme: $active_theme. Actual theme: $theme_key.";
    if ($inherited) {
      $output .= ' Theme negotiation inheritance is being tested.';
    }
    return ['#markup' => $output];
  }

  /** * A title callback for XSS breadcrumb check. * * @return string */
/** * @dataProvider getThemes */
  public function testDetermineActiveTheme($admin_theme$expected) {
    $user = $this->prophesize(AccountInterface::class);
    $config_factory = $this->getConfigFactoryStub(['system.theme' => ['admin' => $admin_theme]]);
    $entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class);
    $admin_context = $this->prophesize(AdminContext::class);
    $negotiator = new AdminNegotiator($user->reveal()$config_factory$entity_type_manager->reveal()$admin_context->reveal());
    $route_match = $this->prophesize(RouteMatch::class);
    $this->assertSame($expected$negotiator->determineActiveTheme($route_match->reveal()));
  }

  /** * Provides a list of theme names to test. */
  public function getThemes() {
    return [
      ['claro', 'claro'],
      [NULL, NULL],
      ['', NULL],
    ];
  }
return TRUE;
  }

  /** * {@inheritdoc} */
  public function determineActiveTheme(RouteMatchInterface $route_match) {
    foreach ($this->negotiators as $negotiator_id) {
      $negotiator = $this->classResolver->getInstanceFromDefinition($negotiator_id);

      if ($negotiator->applies($route_match)) {
        $theme = $negotiator->determineActiveTheme($route_match);
        if ($theme !== NULL && $this->themeAccess->checkAccess($theme)) {
          return $theme;
        }
      }
    }
  }

}
Home | Imprint | This part of the site doesn't use cookies.