View source
<?php
namespace Drupal\support_ticket\Tests;
class SupportTicketFormButtonsTest extends SupportTicketTestBase {
use AssertButtonsTrait;
protected $webUser;
protected $adminUser;
protected function setUp() {
parent::setUp();
$this->webUser = $this
->drupalCreateUser(array(
'access support tickets',
'create ticket ticket',
'edit own ticket ticket',
));
$this->adminUser = $this
->drupalCreateUser(array(
'access support tickets',
'administer support tickets',
'administer support ticket types',
'view own unpublished support tickets',
));
}
function testSupportTicketFormButtons() {
$support_ticket_storage = $this->container
->get('entity.manager')
->getStorage('support_ticket');
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('support_ticket/add/ticket');
$this
->assertButtons(array(
t('Save and publish'),
t('Save as unpublished'),
));
$edit = array(
'title[0][value]' => $this
->randomString(),
);
$this
->drupalPostForm('support_ticket/add/ticket', $edit, t('Save and publish'));
$support_ticket_1 = $support_ticket_storage
->load(1);
$this
->assertTrue($support_ticket_1
->isPublished(), 'Support ticket is published');
$this
->drupalGet('support_ticket/' . $support_ticket_1
->id() . '/edit');
$this
->assertButtons(array(
t('Save and keep published'),
t('Save and unpublish'),
));
$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');
$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');
$this
->drupalGet('support_ticket/' . $support_ticket_1
->id() . '/edit');
$this
->assertButtons(array(
t('Save and keep unpublished'),
t('Save and publish'),
));
$this
->drupalLogout();
$this
->drupalLogin($this->webUser);
$this
->drupalGet('support_ticket/add/ticket');
$this
->assertButtons(array(
t('Save'),
), FALSE);
$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');
$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');
$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();
$fields = \Drupal::entityManager()
->getFieldDefinitions('support_ticket', 'ticket');
$fields['status']
->getConfig('ticket')
->setDefaultValue(FALSE)
->save();
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('support_ticket/add/ticket');
$this
->assertButtons(array(
t('Save as unpublished'),
t('Save and publish'),
));
$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');
}
}