trait PromotedContentViewTestTrait

Provides a method to enable the promoted_content view.

@todo Revisit tests using this trait. https://www.drupal.org/project/drupal/issues/3592096

Hierarchy

19 files declare their use of PromotedContentViewTestTrait
AjaxPageStateTest.php in core/modules/system/tests/src/Functional/Render/AjaxPageStateTest.php
BreadcrumbTest.php in core/modules/system/tests/src/Functional/Menu/BreadcrumbTest.php
CommentLinksTest.php in core/modules/comment/tests/src/Functional/CommentLinksTest.php
CommentRssTest.php in core/modules/comment/tests/src/Functional/CommentRssTest.php
ConfigTranslationUiModulesTest.php in core/modules/config_translation/tests/src/Functional/ConfigTranslationUiModulesTest.php

... See full list

File

core/modules/node/tests/src/Traits/PromotedContentViewTestTrait.php, line 13

Namespace

Drupal\Tests\node\Traits
View source
trait PromotedContentViewTestTrait {
  
  /**
   * Enables the promoted_content view and optionally rebuilds the router.
   *
   * The promoted_content view is disabled by default so tests that rely on
   * the front page or RSS feed provided by this view need to explicitly
   * enable it and rebuild the router so the routes become available.
   *
   * @param bool $rebuildRouter
   *   Whether to rebuild the router after enabling the view. Defaults to TRUE.
   *
   * @return \Drupal\views\Entity\View
   *   The enabled view entity.
   */
  protected function enablePromotedContentView(bool $rebuildRouter = TRUE) {
    $view = \Drupal::entityTypeManager()->getStorage('view')
      ->load('promoted_content');
    $view->enable()
      ->save();
    if ($rebuildRouter) {
      \Drupal::service('router.builder')->rebuild();
    }
    return $view;
  }

}

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