You are here

public function PreserveTitlesOptionTest::assertPreserveTitlesOption in Automatic Entity Label 8.3

Asserts that 'Preserve already created titles' option works correctly.

Parameters

bool $value: Value for 'preserve_titles' to be set.

int $numberOfNodes: Number of testing nodes to be created.

2 calls to PreserveTitlesOptionTest::assertPreserveTitlesOption()
PreserveTitlesOptionTest::testPreserveTitlesOptionDisabled in tests/src/Functional/PreserveTitlesOptionTest.php
Tests disabled 'Preserve already created titles'.
PreserveTitlesOptionTest::testPreserveTitlesOptionEnabled in tests/src/Functional/PreserveTitlesOptionTest.php
Tests enabled 'Preserve already created titles'.

File

tests/src/Functional/PreserveTitlesOptionTest.php, line 100

Class

PreserveTitlesOptionTest
Tests 'Preserve already created titles' option.

Namespace

Drupal\Tests\auto_entitylabel\Functional

Code

public function assertPreserveTitlesOption(bool $value, int $numberOfNodes) {
  $editNodeId = rand(1, $numberOfNodes);
  $webAssert = $this
    ->assertSession();
  $this
    ->createTestNodes($numberOfNodes, 'page');
  $this->configFactory
    ->getEditable("auto_entitylabel.settings.node.{$this->nodeType->id()}")
    ->set('status', AutoEntityLabelManager::ENABLED)
    ->set('pattern', 'Test node [current-user:account-name]')
    ->set('preserve_titles', $value)
    ->save();
  $this
    ->drupalGet('/node/' . $editNodeId . '/edit');
  $webAssert
    ->buttonExists('Save')
    ->click();
  if ($value) {
    $page = $this->nodeStorage
      ->load($editNodeId);
    $this
      ->assertNotEquals('Test node ' . $this->user
      ->getAccountName(), $page
      ->get('title')->value);
  }
  else {
    $page = $this->nodeStorage
      ->load($editNodeId);
    $this
      ->assertEquals('Test node ' . $this->user
      ->getAccountName(), $page
      ->get('title')->value);
  }
}