function ChangePromotedDefaultTest::testRunUpdates

@covers node_post_update_create_promote_base_field_overrides

File

core/modules/node/tests/src/Functional/Update/ChangePromotedDefaultTest.php, line 29

Class

ChangePromotedDefaultTest
Tests creating base field overrides for the promote field on node types.

Namespace

Drupal\Tests\node\Functional\Update

Code

public function testRunUpdates() : void {
  /** @var \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager */
  $entityFieldManager = \Drupal::service(EntityFieldManagerInterface::class);
  $promoteFieldDefinition = $entityFieldManager->getBaseFieldDefinitions('node')['promote'];
  $false_result = [
    0 => [
      'value' => 0,
    ],
  ];
  $true_result = [
    0 => [
      'value' => 1,
    ],
  ];
  $article_promote_1 = $promoteFieldDefinition->getConfig('article');
  $this->assertTrue($article_promote_1->isNew());
  $page_promote_1 = $promoteFieldDefinition->getConfig('page');
  $this->assertEquals($false_result, $page_promote_1->getDefaultValueLiteral());
  $this->runUpdates();
  $article_promote_2 = $promoteFieldDefinition->getConfig('article');
  $this->assertEquals($true_result, $article_promote_2->getDefaultValueLiteral());
  $page_promote_2 = $promoteFieldDefinition->getConfig('page');
  $this->assertEquals($false_result, $page_promote_2->getDefaultValueLiteral());
}

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