You are here

public function RevisionLogDefaultTest::testRevisionLogDefault in Revision Log Default 8

Tests that revision log defaults are set correctly.

File

tests/src/Kernel/RevisionLogDefaultTest.php, line 53

Class

RevisionLogDefaultTest
Tests the revision_log_default module.

Namespace

Drupal\Tests\revision_log_default\Kernel

Code

public function testRevisionLogDefault() {
  $this
    ->createUser();

  // Test that a default revision log is set for creating new nodes.
  $node = Node::create([
    'type' => 'page',
    'title' => $this
      ->randomMachineName(),
  ]);
  $node
    ->save();
  $this
    ->assertEquals($node->revision_log
    ->getString(), 'Created new page');

  // Test that a default revision log is set when a new language is created.
  $french = $node
    ->addTranslation('fr');
  $french->revision_log = '';
  $french->title = $this
    ->randomMachineName();
  $french
    ->save();
  $this
    ->assertEquals($french->revision_log
    ->getString(), 'Created French translation');

  // Test that updating fields sets a sane default revision log.
  $node->title = $this
    ->randomMachineName();
  $node->revision_log = '';
  $node
    ->save();
  $this
    ->assertEquals($node->revision_log
    ->getString(), 'Updated the Title field');
  $node->title = $this
    ->randomMachineName();
  $node->body = $this
    ->randomMachineName();
  $node->revision_log = '';
  $node
    ->save();
  $this
    ->assertEquals($node->revision_log
    ->getString(), 'Updated the Title and Body fields');
}