View source
<?php
namespace Drupal\Tests\webform\Functional;
class WebformListBuilderTest extends WebformBrowserTestBase {
public static $modules = [
'node',
'webform',
'webform_test_submissions',
];
public function testFilter() {
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('/admin/structure/webform');
$this
->assertOptionSelected('edit-category', '');
$this
->assertOptionSelected('edit-state', '');
\Drupal::configFactory()
->getEditable('webform.settings')
->set('form.filter_category', 'Test: Submissions')
->set('form.filter_state', 'open')
->save();
$this
->drupalGet('/admin/structure/webform');
$this
->assertOptionSelected('edit-category', 'Test: Submissions');
$this
->assertOptionSelected('edit-state', 'open');
$this
->drupalGet('/admin/structure/webform', [
'query' => [
'category' => '',
'state' => '',
],
]);
$this
->assertOptionSelected('edit-category', '');
$this
->assertOptionSelected('edit-state', '');
}
public function testBulkOperations() {
$webforms = [
$this
->createWebform([
'id' => 'one',
]),
$this
->createWebform([
'id' => 'two',
]),
$this
->createWebform([
'id' => 'three',
]),
];
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('/admin/structure/webform');
$this
->assertCssSelect('#webform-bulk-form');
$this
->assertCssSelect('#edit-items-one');
$this
->assertCssSelect('#edit-items-two');
$this
->assertCssSelect('#edit-items-three');
$this
->drupalGet('/admin/structure/webform');
$this
->assertCssSelect('option[value="webform_open_action"]');
$this
->assertCssSelect('option[value="webform_close_action"]');
$this
->assertCssSelect('option[value="webform_archive_action"]');
$this
->assertNoCssSelect('option[value="webform_unarchive_action"]');
$this
->assertCssSelect('option[value="webform_delete_action"]');
$this
->drupalGet('/admin/structure/webform', [
'query' => [
'state' => 'archived',
],
]);
$this
->assertNoCssSelect('option[value="webform_open_action"]');
$this
->assertNoCssSelect('option[value="webform_close_action"]');
$this
->assertNoCssSelect('option[value="webform_archive_action"]');
$this
->assertCssSelect('option[value="webform_unarchive_action"]');
$this
->assertCssSelect('option[value="webform_delete_action"]');
\Drupal::configFactory()
->getEditable('webform.settings')
->set('settings.webform_bulk_form', FALSE)
->save();
$this
->drupalGet('/admin/structure/webform');
$this
->assertNoCssSelect('#webform-bulk-form');
\Drupal::configFactory()
->getEditable('webform.settings')
->set('settings.webform_bulk_form', TRUE)
->save();
$this
->assertTrue($webforms[0]
->isOpen());
$edit = [
'action' => 'webform_close_action',
'items[one]' => TRUE,
];
$this
->drupalPostForm('/admin/structure/webform', $edit, 'Apply to selected items', [], 'webform-bulk-form');
$this
->assertRaw('<em class="placeholder">Close webform</em> was applied to 1 item.');
$this
->assertCssSelect('#edit-items-one');
$this
->assertCssSelect('#edit-items-two');
$this
->assertCssSelect('#edit-items-three');
$webforms[0] = $this
->reloadWebform('one');
$this
->assertTrue($webforms[0]
->isClosed());
$edit = [
'action' => 'webform_open_action',
'items[one]' => TRUE,
];
$this
->drupalPostForm('/admin/structure/webform', $edit, 'Apply to selected items', [], 'webform-bulk-form');
$this
->assertRaw('<em class="placeholder">Open webform</em> was applied to 1 item.');
$webforms[0] = $this
->reloadWebform('one');
$this
->assertTrue($webforms[0]
->isOpen());
$edit = [
'action' => 'webform_archive_action',
'items[one]' => TRUE,
];
$this
->drupalPostForm('/admin/structure/webform', $edit, 'Apply to selected items', [], 'webform-bulk-form');
$this
->assertRaw('<em class="placeholder">Archive webform</em> was applied to 1 item.');
$this
->assertNoCssSelect('#edit-items-one');
$webforms[0] = $this
->reloadWebform('one');
$this
->assertTrue($webforms[0]
->isArchived());
$this
->drupalGet('/admin/structure/webform', [
'query' => [
'state' => 'archived',
],
]);
$this
->assertCssSelect('#edit-items-one');
$edit = [
'action' => 'webform_unarchive_action',
'items[one]' => TRUE,
];
$this
->drupalPostForm('/admin/structure/webform', $edit, 'Apply to selected items', [
'query' => [
'state' => 'archived',
],
], 'webform-bulk-form');
$this
->assertRaw('<em class="placeholder">Restore webform</em> was applied to 1 item.');
$webforms[0] = $this
->reloadWebform('one');
$this
->assertFalse($webforms[0]
->isArchived());
$edit = [
'action' => 'webform_delete_action',
'items[one]' => TRUE,
];
$this
->drupalPostForm('/admin/structure/webform', $edit, 'Apply to selected items', [], 'webform-bulk-form');
$edit = [
'confirm_input' => TRUE,
];
$this
->drupalPostForm(NULL, $edit, 'Delete');
$this
->assertRaw('Deleted 1 item.');
$webforms[0] = $this
->reloadWebform('one');
$this
->assertNull($webforms[0]);
}
public function testAccess() {
$assert_session = $this
->assertSession();
$any_webform_user = $this
->createUser([
'access webform overview',
'create webform',
'edit any webform',
'delete any webform',
]);
$this
->drupalLogin($any_webform_user);
$list_path = '/admin/structure/webform';
$this
->drupalGet($list_path);
$assert_session
->linkExists('Test: Submissions');
$assert_session
->linkExists('Results');
$assert_session
->linkExists('Build');
$assert_session
->linkExists('Settings');
$assert_session
->linkExists('View');
$assert_session
->linkExists('Duplicate');
$assert_session
->linkExists('Delete');
$any_webform_submission_user = $this
->createUser([
'access webform overview',
'view any webform submission',
'edit any webform submission',
'delete any webform submission',
]);
$this
->drupalLogin($any_webform_submission_user);
$this
->drupalGet($list_path);
$assert_session
->linkExists('Test: Submissions');
$assert_session
->linkExists('Results');
$assert_session
->linkNotExists('Build');
$assert_session
->linkNotExists('Settings');
$assert_session
->linkExists('View');
$assert_session
->linkNotExists('Duplicate');
$assert_session
->linkNotExists('Delete');
$webform_config = \Drupal::configFactory()
->getEditable('webform.webform.test_submissions');
$settings = $webform_config
->get('settings');
$settings['page'] = FALSE;
$webform_config
->set('settings', $settings)
->save();
$this
->drupalGet($list_path);
$assert_session
->linkNotExists('Test: Submissions');
$assert_session
->responseContains('Test: Submissions');
$this
->assertLinkNotInRow('Test: Submissions', 'View');
$rid = $this
->drupalCreateRole([
'access webform overview',
]);
$special_access_user = $this
->createUser();
$special_access_user
->addRole($rid);
$special_access_user
->save();
$access = $webform_config
->get('access');
$access['view_any']['roles'][] = $rid;
$webform_config
->set('access', $access)
->save();
$this
->drupalLogin($special_access_user);
$this
->drupalGet($list_path);
$assert_session
->responseContains('Test: Submissions');
$assert_session
->linkExists('Results');
}
protected function assertLinkNotInRow($row_text, $link) {
$row = $this
->getSession()
->getPage()
->find('css', sprintf('table tr:contains("%s")', $row_text));
if (!$row) {
throw new \Exception($this
->getSession()
->getDriver(), 'table row', 'value', $row_text);
}
$links = $row
->findAll('named', [
'link',
$link,
]);
$this
->assertEmpty($links, sprintf('Link with label %s found in row %s.', $link, $row_text));
}
}