function SupportTicketSaveTest::testImport in Support Ticketing System 8
Checks whether custom support_ticket IDs are saved properly during an import operation.
Workflow:
- first create a piece of ticket
- save the ticket
- check if support_ticket exists
File
- modules/
support_ticket/ src/ Tests/ SupportTicketSaveTest.php, line 50 - Contains \Drupal\support_ticket\Tests\SupportTicketSaveTest.
Class
- SupportTicketSaveTest
- Tests $support_ticket->save() for saving tickets.
Namespace
Drupal\support_ticket\TestsCode
function testImport() {
// SupportTicket ID must be a number that is not in the database.
$stids = \Drupal::entityManager()
->getStorage('support_ticket')
->getQuery()
->sort('stid', 'DESC')
->range(0, 1)
->execute();
$max_stid = reset($stids);
$test_stid = $max_stid + mt_rand(1000, 1000000);
$title = $this
->randomMachineName(8);
$support_ticket = array(
'title' => $title,
'body' => array(
array(
'value' => $this
->randomMachineName(32),
),
),
'uid' => $this->webUser
->id(),
'support_ticket_type' => 'ticket',
'stid' => $test_stid,
);
/** @var \Drupal\support_ticket\SupportTicketInterface $support_ticket */
$support_ticket = entity_create('support_ticket', $support_ticket);
$support_ticket
->enforceIsNew();
$this
->assertEqual($support_ticket
->getOwnerId(), $this->webUser
->id());
$support_ticket
->save();
// Test the import.
$support_ticket_by_stid = SupportTicket::load($test_stid);
$this
->assertTrue($support_ticket_by_stid, 'SupportTicket load by support_ticket ID.');
$support_ticket_by_title = $this
->supportTicketGetTicketByTitle($title);
$this
->assertTrue($support_ticket_by_title, 'SupportTicket load by support_ticket title.');
}