class NodePageVariableDeprecationTest

Tests page variable deprecation.

Attributes

#[Group('node')] #[IgnoreDeprecations]

Hierarchy

Expanded class hierarchy of NodePageVariableDeprecationTest

File

core/modules/node/tests/src/Functional/NodePageVariableDeprecationTest.php, line 14

Namespace

Drupal\Tests\node\Functional
View source
class NodePageVariableDeprecationTest extends NodeTestBase {
  
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'test_theme';
  
  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $this->drupalCreateContentType([
      'type' => 'test_page_variable',
    ]);
    EntityViewMode::create([
      'id' => 'node.test_page_variable',
      'targetEntityType' => 'node',
      'status' => TRUE,
      'enabled' => TRUE,
      'label' => 'Test page variable',
    ])->save();
  }
  
  /**
   * Tests that deprecations are thrown correctly for the page variable.
   */
  public function testPageVariableDeprecation() : void {
    // Create a dummy node to skip node--1.html.twig in test_theme.
    $this->drupalCreateNode();
    $node = $this->drupalCreateNode([
      'type' => 'test_page_variable',
    ]);
    $this->expectDeprecation("'page' is deprecated in drupal:11.3.0 and is removed in drupal:13.0.0. Use 'view_mode' instead. See https://www.drupal.org/node/3458593");
    $this->drupalGet($node->toUrl());
    $this->assertSession()
      ->pageTextContains('The page variable is set');
    $build = \Drupal::entityTypeManager()->getViewBuilder('node')
      ->view($node, 'test_page_variable');
    $output = (string) \Drupal::service('renderer')->renderRoot($build);
    $this->assertStringNotContainsString('The page variable is set', $output);
  }

}

Members

Title Sort descending Modifiers Object type Summary
BodyFieldCreationTrait::createBodyField protected function Creates a field of an body field storage on the specified bundle.
NodePageVariableDeprecationTest::$defaultTheme protected property
NodePageVariableDeprecationTest::setUp protected function
NodePageVariableDeprecationTest::testPageVariableDeprecation public function Tests that deprecations are thrown correctly for the page variable.

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