You are here

function SupportTicketCreationTest::testTicketCreation in Support Ticketing System 8

Creates a "ticket" support_ticket and verifies its consistency in the database.

File

modules/support_ticket/src/Tests/SupportTicketCreationTest.php, line 40
Contains \Drupal\support_ticket\Tests\SupportTicketCreationTest.

Class

SupportTicketCreationTest
Create a support ticket and test saving it.

Namespace

Drupal\support_ticket\Tests

Code

function testTicketCreation() {
  $ticket_type_storage = \Drupal::entityManager()
    ->getStorage('support_ticket_type');

  // Test /support_ticket/add page with only one content type.
  $this
    ->drupalGet('support_ticket/add');
  $this
    ->assertResponse(200);
  $this
    ->assertUrl('support_ticket/add/ticket');

  // Create a ticket.
  $edit = array();
  $edit['title[0][value]'] = $this
    ->randomMachineName(8);
  $edit['body[0][value]'] = $this
    ->randomMachineName(16);
  $edit['field_priority'] = '120';

  // 120 = 'high'
  $edit['field_state'] = 'inactive';
  $this
    ->drupalPostForm('support_ticket/add/ticket', $edit, t('Save'));

  // Check that the ticket has been created.
  $this
    ->assertRaw(t('@post %title has been created.', array(
    '@post' => 'Ticket',
    '%title' => $edit['title[0][value]'],
  )), 'Ticket created.');

  // Check that the support_ticket exists in the database.
  $ticket = $this
    ->supportTicketGetTicketByTitle($edit['title[0][value]']);
  $this
    ->assertTrue($ticket, 'Ticket found in database.');

  // View ticket to test single ticket output.
  $this
    ->drupalGet('support_ticket/' . $ticket
    ->id());

  // Base "Submitted by..." heading.
  $this
    ->assertText($ticket
    ->getOwner()
    ->getUsername());
  $this
    ->assertText(format_date($ticket
    ->getCreatedTime()));

  // Check field display output for basic ticket fields.
  $elements = $this
    ->cssSelect("div.field--name-field-priority div.field__item:contains('high')");
  $this
    ->assertEqual(count($elements), 1, 'Priority was set correctly.');
  $elements = $this
    ->cssSelect("div.field--name-field-state div.field__item:contains('inactive')");
  $this
    ->assertEqual(count($elements), 1, 'State was set correctly.');
}