You are here

public function NodeRevisionsAutocleanTest::addRevision in Node Revisions Autoclean 8

Adds revision to a node.

Parameters

Drupal\node\Entity\Node $node: Node.

Drupal\user\Entity\User $user: User.

bool $published: Published.

string $langcode: Langcode, default default site langcode.

\DateTime $dt: Datetime, current if null.

4 calls to NodeRevisionsAutocleanTest::addRevision()
NodeRevisionsAutocleanTest::createNodeWithRevisions in tests/src/Functional/NodeRevisionsAutocleanTest.php
Creates node and its revisions.
NodeRevisionsAutocleanTest::testDeleteDateRevisions in tests/src/Functional/NodeRevisionsAutocleanTest.php
Tests that revisions are deleted as they should be with date constraint.
NodeRevisionsAutocleanTest::testDeleteMultilanguageRevisions in tests/src/Functional/NodeRevisionsAutocleanTest.php
Tests node revisions autoclean with multiple languages.
NodeRevisionsAutocleanTest::testDeleteRevisions in tests/src/Functional/NodeRevisionsAutocleanTest.php
Tests that revisions are deleted as they should be.

File

tests/src/Functional/NodeRevisionsAutocleanTest.php, line 137

Class

NodeRevisionsAutocleanTest
Class NodeRevisionsAutocleanTest.

Namespace

Drupal\Tests\node_revisions_autoclean\Functional

Code

public function addRevision(Node &$node, User $user, $published = FALSE, $langcode = NULL, \DateTime $dt = NULL) {
  sleep(1);
  if (!isset($dt)) {
    $dt = new \DateTime();
  }
  if (!isset($langcode)) {
    $langcode = $this->languageManager
      ->getDefaultLanguage()
      ->getId();
  }
  $node
    ->setNewRevision(TRUE);
  $node
    ->set('langcode', $langcode);
  $node
    ->setRevisionCreationTime($dt
    ->getTimestamp());
  $node
    ->setRevisionUserId($user
    ->id());
  $node
    ->setPublished($published);
  $node
    ->save();
}