You are here

function SupportTicketSaveTest::testDeterminingChanges in Support Ticketing System 8

Tests support_ticket presave and static support_ticket load cache.

This test determines changes in hook_ENTITY_TYPE_presave() and verifies that the static support_ticket load cache is cleared upon save.

File

modules/support_ticket/src/Tests/SupportTicketSaveTest.php, line 145
Contains \Drupal\support_ticket\Tests\SupportTicketSaveTest.

Class

SupportTicketSaveTest
Tests $support_ticket->save() for saving tickets.

Namespace

Drupal\support_ticket\Tests

Code

function testDeterminingChanges() {

  // Initial creation.
  $support_ticket = entity_create('support_ticket', array(
    'uid' => $this->webUser
      ->id(),
    'support_ticket_type' => 'ticket',
    'title' => 'test_changes',
  ));
  $support_ticket
    ->save();

  // Update the support_ticket without applying changes.
  $support_ticket
    ->save();
  $this
    ->assertEqual($support_ticket
    ->label(), 'test_changes', 'No changes have been determined.');

  // Apply changes.
  $support_ticket->title = 'updated';
  $support_ticket
    ->save();

  // The hook implementations support_ticket_test_support_ticket_presave() and
  // support_ticket_test_support_ticket_update() determine changes and change the title.
  $this
    ->assertEqual($support_ticket
    ->label(), 'updated_presave_update', 'Changes have been determined.');

  // Test the static support_ticket load cache to be cleared.
  $support_ticket = SupportTicket::load($support_ticket
    ->id());
  $this
    ->assertEqual($support_ticket
    ->label(), 'updated_presave', 'Static cache has been cleared.');
}