function SupportTicketCreationTest::testFailedTicketCreation in Support Ticketing System 8
Verifies that a transaction rolls back the failed creation.
File
- modules/
support_ticket/ src/ Tests/ SupportTicketCreationTest.php, line 82 - Contains \Drupal\support_ticket\Tests\SupportTicketCreationTest.
Class
- SupportTicketCreationTest
- Create a support ticket and test saving it.
Namespace
Drupal\support_ticket\TestsCode
function testFailedTicketCreation() {
// Create a support_ticket.
$edit = array(
'uid' => $this->loggedInUser
->id(),
'name' => $this->loggedInUser->name,
'support_ticket_type' => 'ticket',
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'title' => 'testing_transaction_exception',
);
try {
// An exception is generated by support_ticket_test_exception_support_ticket_insert() if the
// title is 'testing_transaction_exception'.
entity_create('support_ticket', $edit)
->save();
$this
->fail(t('Expected exception has not been thrown.'));
} catch (\Exception $e) {
$this
->pass(t('Expected exception has been thrown.'));
}
if (Database::getConnection()
->supportsTransactions()) {
// Check that the support_ticket does not exist in the database.
$support_ticket = $this
->supportTicketGetTicketByTitle($edit['title']);
$this
->assertFalse($support_ticket, 'Transactions supported, and support_ticket not found in database.');
}
else {
// Check that the support_ticket exists in the database.
$support_ticket = $this
->supportTicketGetTicketByTitle($edit['title']);
$this
->assertTrue($support_ticket, 'Transactions not supported, and support_ticket found in database.');
// Check that the failed rollback was logged.
$records = static::getWatchdogIdsForFailedExplicitRollback();
$this
->assertTrue(count($records) > 0, 'Transactions not supported, and rollback error logged to watchdog.');
}
// Check that the rollback error was logged.
$records = static::getWatchdogIdsForTestExceptionRollback();
$this
->assertTrue(count($records) > 0, 'Rollback explanatory error logged to watchdog.');
}