You are here

public function AutoEntityLabelTest::testOptionalOption in Automatic Entity Label 8.3

Tests node creation with optional settings.

File

tests/src/Kernel/AutoEntityLabelTest.php, line 101

Class

AutoEntityLabelTest
Tests for auto entity label.

Namespace

Drupal\Tests\auto_entitylabel\Kernel

Code

public function testOptionalOption() {
  $this
    ->setConfiguration([
    'status' => AutoEntityLabelManager::OPTIONAL,
    'pattern' => '[node:author:name]',
  ]);
  $user = $this
    ->createUser();
  $title = 'Test Node';
  $node = $this
    ->createNode([
    'title' => $title,
    'uid' => $user
      ->id(),
    'type' => $this->nodeType
      ->id(),
  ]);
  $this
    ->assertEquals($title, $node
    ->getTitle(), 'The title is untouched.');
  $node = $this
    ->createNode([
    'title' => '',
    'uid' => $user
      ->id(),
    'type' => $this->nodeType
      ->id(),
  ]);
  $this
    ->assertEquals($user
    ->getAccountName(), $node
    ->getTitle(), 'The title is set.');
}