You are here

public function LogActionsTest::testCloneSingleLog in Log entity 2.x

Tests cloning a single log.

File

tests/src/Functional/LogActionsTest.php, line 15

Class

LogActionsTest
Tests the Log form actions.

Namespace

Drupal\Tests\log\Functional

Code

public function testCloneSingleLog() {
  $timestamp = \Drupal::time()
    ->getRequestTime();
  $log = $this
    ->createLogEntity([
    'name' => $this
      ->randomMachineName(),
    'created' => \Drupal::time()
      ->getRequestTime(),
    'done' => TRUE,
    'timestamp' => $timestamp,
  ]);
  $log
    ->save();
  $num_of_logs = $this->storage
    ->getQuery()
    ->count()
    ->execute();
  $this
    ->assertEqual($num_of_logs, 1, 'There is one log in the system.');
  $edit = [];
  $edit['action'] = 'log_clone_action';
  $edit['log_bulk_form[0]'] = TRUE;
  $this
    ->drupalPostForm('admin/content/log', $edit, $this
    ->t('Apply to selected items'));
  $this
    ->assertResponse(200);
  $this
    ->assertText($this
    ->t('Are you sure you want to clone this log?'));
  $this
    ->assertText($this
    ->t('New date'));
  $new_timestamp = strtotime(date('Y-n-j', strtotime('+1 day', $timestamp)));
  $edit_clone = [];
  $edit_clone['date[month]'] = date('n', $new_timestamp);
  $edit_clone['date[year]'] = date('Y', $new_timestamp);
  $edit_clone['date[day]'] = date('j', $new_timestamp);
  $this
    ->drupalPostForm(NULL, $edit_clone, $this
    ->t('Clone'));
  $this
    ->assertResponse(200);
  $this
    ->assertUrl('admin/content/log');
  $this
    ->assertText($this
    ->t('Cloned 1 log'));
  $logs = $this->storage
    ->loadMultiple();
  $this
    ->assertEqual(count($logs), 2, 'There are two logs in the system.');
  $timestamps = [];
  foreach ($logs as $log) {
    $timestamps[] = $log
      ->get('timestamp')->value;
  }
  $this
    ->assertEqual($timestamps, [
    $timestamp,
    $new_timestamp,
  ], 'Timestamp on the new log has been updated.');
}