function SupportTicketFormButtonsTest::testSupportTicketFormButtons in Support Ticketing System 8
Tests that the right buttons are displayed for saving support_tickets.
File
- modules/
support_ticket/ src/ Tests/ SupportTicketFormButtonsTest.php, line 46 - Contains \Drupal\support_ticket\Tests\SupportTicketFormButtonsTest.
Class
- SupportTicketFormButtonsTest
- Tests all the different buttons on the support_ticket form.
Namespace
Drupal\support_ticket\TestsCode
function testSupportTicketFormButtons() {
$support_ticket_storage = $this->container
->get('entity.manager')
->getStorage('support_ticket');
// Login as administrative user.
$this
->drupalLogin($this->adminUser);
// Verify the buttons on a support_ticket add form.
$this
->drupalGet('support_ticket/add/ticket');
$this
->assertButtons(array(
t('Save and publish'),
t('Save as unpublished'),
));
// Save the support_ticket and assert it's published after clicking
// 'Save and publish'.
$edit = array(
'title[0][value]' => $this
->randomString(),
);
$this
->drupalPostForm('support_ticket/add/ticket', $edit, t('Save and publish'));
// Get the support_ticket.
$support_ticket_1 = $support_ticket_storage
->load(1);
$this
->assertTrue($support_ticket_1
->isPublished(), 'Support ticket is published');
// Verify the buttons on a support_ticket edit form.
$this
->drupalGet('support_ticket/' . $support_ticket_1
->id() . '/edit');
$this
->assertButtons(array(
t('Save and keep published'),
t('Save and unpublish'),
));
// Save the support_ticket and verify it's still published after clicking
// 'Save and keep published'.
$this
->drupalPostForm(NULL, $edit, t('Save and keep published'));
$support_ticket_storage
->resetCache(array(
1,
));
$support_ticket_1 = $support_ticket_storage
->load(1);
$this
->assertTrue($support_ticket_1
->isPublished(), 'Support ticket is published');
// Save the support_ticket and verify it's unpublished after clicking
// 'Save and unpublish'.
$this
->drupalPostForm('support_ticket/' . $support_ticket_1
->id() . '/edit', $edit, t('Save and unpublish'));
$support_ticket_storage
->resetCache(array(
1,
));
$support_ticket_1 = $support_ticket_storage
->load(1);
$this
->assertFalse($support_ticket_1
->isPublished(), 'Support ticket is unpublished');
// Verify the buttons on an unpublished support_ticket edit screen.
$this
->drupalGet('support_ticket/' . $support_ticket_1
->id() . '/edit');
$this
->assertButtons(array(
t('Save and keep unpublished'),
t('Save and publish'),
));
// Create a support_ticket as a normal user.
$this
->drupalLogout();
$this
->drupalLogin($this->webUser);
// Verify the buttons for a normal user.
$this
->drupalGet('support_ticket/add/ticket');
$this
->assertButtons(array(
t('Save'),
), FALSE);
// Create the support_ticket.
$edit = array(
'title[0][value]' => $this
->randomString(),
);
$this
->drupalPostForm('support_ticket/add/ticket', $edit, t('Save'));
$support_ticket_2 = $support_ticket_storage
->load(2);
$this
->assertTrue($support_ticket_2
->isPublished(), 'Support ticket is published');
// Login as an administrator and unpublish the support_ticket that just
// was created by the normal user.
$this
->drupalLogout();
$this
->drupalLogin($this->adminUser);
$this
->drupalPostForm('support_ticket/' . $support_ticket_2
->id() . '/edit', array(), t('Save and unpublish'));
$support_ticket_storage
->resetCache(array(
2,
));
$support_ticket_2 = $support_ticket_storage
->load(2);
$this
->assertFalse($support_ticket_2
->isPublished(), 'Support ticket is unpublished');
// Login again as the normal user, save the support_ticket and verify
// it's still unpublished.
$this
->drupalLogout();
$this
->drupalLogin($this->webUser);
$this
->drupalPostForm('support_ticket/' . $support_ticket_2
->id() . '/edit', array(), t('Save'));
$support_ticket_storage
->resetCache(array(
2,
));
$support_ticket_2 = $support_ticket_storage
->load(2);
$this
->assertFalse($support_ticket_2
->isPublished(), 'Support ticket is still unpublished');
$this
->drupalLogout();
// Set article content type default to unpublished. This will change the
// the initial order of buttons and/or status of the support_ticket when creating
// a support_ticket.
$fields = \Drupal::entityManager()
->getFieldDefinitions('support_ticket', 'ticket');
$fields['status']
->getConfig('ticket')
->setDefaultValue(FALSE)
->save();
// Verify the buttons on a support_ticket add form for an administrator.
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('support_ticket/add/ticket');
$this
->assertButtons(array(
t('Save as unpublished'),
t('Save and publish'),
));
// Verify the support_ticket is unpublished by default for a normal user.
$this
->drupalLogout();
$this
->drupalLogin($this->webUser);
$edit = array(
'title[0][value]' => $this
->randomString(),
);
$this
->drupalPostForm('support_ticket/add/ticket', $edit, t('Save'));
$support_ticket_3 = $support_ticket_storage
->load(3);
$this
->assertFalse($support_ticket_3
->isPublished(), 'Support ticket is unpublished');
}