You are here

public function AuditLogEventTest::testSettersGetters in Audit Log 8

Same name and namespace in other branches
  1. 8.2 tests/src/Unit/AuditLogEventTest.php \Drupal\Tests\audit_log\Unit\AuditLogEventTest::testSettersGetters()

Verifies that event properties are correctly set and retrieved.

File

tests/src/Unit/AuditLogEventTest.php, line 21

Class

AuditLogEventTest
Tests the AuditLogEvent class.

Namespace

Drupal\Tests\audit_log\Unit

Code

public function testSettersGetters() {

  /** @var \Drupal\Core\Session\AccountInterface $account */
  $account = $this
    ->getMock(AccountInterface::class);

  /** @var \Drupal\Core\Entity\EntityInterface $entity */
  $entity = $this
    ->getMock(EntityInterface::class);
  $timestamp = time();
  $event = new AuditLogEvent();
  $event
    ->setCurrentState('published')
    ->setEntity($entity)
    ->setEventType('update')
    ->setMessage('Testing the AuditLogEvent Class')
    ->setMessagePlaceholders([
    'foo' => 'bar',
  ])
    ->setPreviousState('unpublished')
    ->setUser($account)
    ->setRequestTime($timestamp);
  $this
    ->assertEquals('published', $event
    ->getCurrentState());
  $this
    ->assertEquals('update', $event
    ->getEventType());
  $this
    ->assertEquals('Testing the AuditLogEvent Class', $event
    ->getMessage());
  $this
    ->assertEquals([
    'foo' => 'bar',
  ], $event
    ->getMessagePlaceholders());
  $this
    ->assertEquals('unpublished', $event
    ->getPreviousState());
  $this
    ->assertEquals($account, $event
    ->getUser());
  $this
    ->assertEquals($entity, $event
    ->getEntity());
  $this
    ->assertEquals($timestamp, $event
    ->getRequestTime());
}