theme_get_suggestions example

/** * Ensure page-front template suggestion is added when on front page. */
  public function testFrontPageThemeSuggestion() {
    // Set the current route to user.login because theme_get_suggestions() will     // query it to see if we are on the front page.     $request = Request::create('/user/login');
    $request->attributes->set(RouteObjectInterface::ROUTE_NAME, 'user.login');
    $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/user/login'));
    \Drupal::requestStack()->push($request);
    $this->config('system.site')->set('page.front', '/user/login')->save();
    $suggestions = theme_get_suggestions(['user', 'login'], 'page');
    // Set it back to not annoy the batch runner.     \Drupal::requestStack()->pop();
    $this->assertContains('page__front', $suggestions, 'Front page template was suggested.');
  }

  /** * Tests theme can provide classes. */
  public function testClassLoading() {
    // Install test theme and set it as default.     $this->config('system.theme')
      
$this->assertFalse($output, '\Drupal::theme() returns FALSE when a hook suggestion is not implemented.');
  }

  /** * Tests function theme_get_suggestions() for SA-CORE-2009-003. */
  public function testThemeSuggestions() {
    // Set the front page as something random otherwise the CLI     // test runner fails.     $this->config('system.site')->set('page.front', '/nobody-home')->save();
    $args = ['node', '1', 'edit'];
    $suggestions = theme_get_suggestions($args, 'page');
    $this->assertEquals(['page__node', 'page__node__%', 'page__node__1', 'page__node__edit']$suggestions, 'Found expected node edit page suggestions');
    // Check attack vectors.     $args = ['node', '\\1'];
    $suggestions = theme_get_suggestions($args, 'page');
    $this->assertEquals(['page__node', 'page__node__%', 'page__node__1']$suggestions, 'Removed invalid \\ from suggestions');
    $args = ['node', '1/'];
    $suggestions = theme_get_suggestions($args, 'page');
    $this->assertEquals(['page__node', 'page__node__%', 'page__node__1']$suggestions, 'Removed invalid / from suggestions');
    $args = ['node', "1\0"];
    $suggestions = theme_get_suggestions($args, 'page');
    $this->assertEquals(['page__node', 'page__node__%', 'page__node__1']$suggestions, 'Removed invalid \\0 from suggestions');
    
Home | Imprint | This part of the site doesn't use cookies.