You are here

public function LogNamePatternTest::testEditLog in Log entity 2.x

Edit log entity.

File

tests/src/Functional/LogNamePatternTest.php, line 65

Class

LogNamePatternTest
Tests the Log name pattern.

Namespace

Drupal\Tests\log\Functional

Code

public function testEditLog() {
  $log = $this
    ->createLogEntity([
    'type' => 'name_pattern',
  ]);
  $log
    ->save();

  // Test that a manually set name does not get overwritten.
  $edit = [
    'name[0][value]' => $this
      ->randomMachineName(),
  ];
  $this
    ->drupalPostForm($log
    ->toUrl('edit-form'), $edit, $this
    ->t('Save'));
  $this
    ->assertText($edit['name[0][value]']);

  // Test that clearing the name forces it to be auto-generated.
  $edit = [
    'name[0][value]' => '',
    'status' => 'pending',
  ];
  $this
    ->drupalPostForm($log
    ->toUrl('edit-form'), $edit, $this
    ->t('Save'));
  $this
    ->assertText($log
    ->id() . ' pending');

  // Test that updating a log with an auto-generated name automatically
  // updates the name.
  $edit = [
    'status' => 'done',
  ];
  $this
    ->drupalPostForm($log
    ->toUrl('edit-form'), $edit, $this
    ->t('Save'));
  $this
    ->assertText($log
    ->id() . ' done');
}