View source
<?php
namespace Drupal\Tests\webform\Functional;
use Drupal\webform\Entity\Webform;
class WebformSubmissionViewsTest extends WebformBrowserTestBase {
protected $defaultTheme = 'classy';
public static $modules = [
'views',
'webform',
];
protected static $testWebforms = [
'test_submission_views',
];
public function testSubmissionViewsAccess() {
$user = $this
->drupalCreateUser([
'administer webform submission',
]);
$this
->drupalLogin($user);
$this
->drupalGet('/admin/structure/webform/manage/test_submission_views/results/submissions');
$this
->assertRaw('view-id-webform_submissions view-display-id-embed_administer');
$this
->drupalGet('/admin/structure/webform/manage/test_submission_views/results/submissions/admin');
$this
->assertResponse(200);
$user = $this
->drupalCreateUser([
'edit any webform submission',
'view any webform submission',
]);
$this
->drupalLogin($user);
$this
->drupalGet('/admin/structure/webform/manage/test_submission_views/results/submissions');
$this
->assertRaw('view-id-webform_submissions view-display-id-embed_manage');
$this
->drupalGet('/admin/structure/webform/manage/test_submission_views/results/submissions/admin');
$this
->assertResponse(403);
$this
->drupalGet('/admin/structure/webform/manage/test_submission_views/results/submissions/not_found');
$this
->assertResponse(404);
$user = $this
->drupalCreateUser([
'view any webform submission',
]);
$this
->drupalLogin($user);
$this
->drupalGet('/admin/structure/webform/manage/test_submission_views/results/submissions');
$this
->assertRaw('view-id-webform_submissions view-display-id-embed_review');
}
public function testSubmissionViews() {
$uid = $this->rootUser
->id();
$this
->drupalLogin($this->rootUser);
\Drupal::configFactory()
->getEditable('webform.settings')
->set('settings.default_submission_views', [
'global' => [
'view' => 'webform_submissions:embed_default',
'title' => 'Global submissions',
'global_routes' => [
'entity.webform_submission.collection',
],
'webform_routes' => [],
'node_routes' => [],
],
'user' => [
'view' => 'webform_submissions:embed_default',
'title' => 'User submissions',
'global_routes' => [
'entity.webform_submission.user',
],
'webform_routes' => [],
'node_routes' => [],
],
])
->save();
$this
->drupalGet('/admin/structure/webform/submissions/manage');
$this
->assertNoRaw('webform-results-table');
$this
->assertRaw('view-id-webform_submissions view-display-id-embed_default');
$this
->drupalGet("/user/{$uid}/submissions");
$this
->assertNoRaw('webform-results-table');
$this
->assertRaw('view-id-webform_submissions view-display-id-embed_default');
\Drupal::configFactory()
->getEditable('webform.settings')
->set('settings.default_submission_views_replace.global_routes', [])
->save();
$this
->drupalGet('/admin/structure/webform/submissions/manage');
$this
->assertRaw('webform-results-table');
$this
->assertNoRaw('view-id-webform_submissions view-display-id-embed_default');
$this
->clickLink('Global submissions');
$this
->assertUrl('/admin/structure/webform/submissions/manage/global');
$this
->assertNoRaw('webform-results-table');
$this
->assertRaw('view-id-webform_submissions view-display-id-embed_default');
$this
->drupalGet("/user/{$uid}/submissions");
$this
->assertRaw('webform-results-table');
$this
->assertNoRaw('view-id-webform_submissions view-display-id-embed_default');
$this
->clickLink('User submissions');
$this
->assertUrl("/user/{$uid}/submissions/user");
$this
->assertNoRaw('webform-results-table');
$this
->assertRaw('view-id-webform_submissions view-display-id-embed_default');
$webform = Webform::load('test_submission_views');
$this
->postSubmission($webform);
$this
->postSubmission($webform);
$this
->postSubmission($webform, [], 'Save Draft');
$this
->postSubmission($webform, [], 'Save Draft');
$this
->drupalGet('/admin/structure/webform/manage/test_submission_views/results/submissions');
$this
->assertNoRaw('webform-results-table');
$this
->assertRaw('view-id-webform_submissions view-display-id-embed_administer');
$this
->drupalGet('/webform/test_submission_views/drafts');
$this
->assertNoRaw('webform-results-table');
$this
->assertRaw('view-id-webform_submissions view-display-id-embed_default');
\Drupal::configFactory()
->getEditable('webform.settings')
->set('settings.default_submission_views_replace.webform_routes', [])
->save();
$this
->drupalGet('/admin/structure/webform/manage/test_submission_views/results/submissions');
$this
->assertRaw('webform-results-table');
$this
->assertNoRaw('view-id-webform_submissions view-display-id-embed_administer');
$this
->clickLink('Administer submissions');
$this
->assertUrl('/admin/structure/webform/manage/test_submission_views/results/submissions/admin');
$this
->assertNoRaw('webform-results-table');
$this
->assertRaw('view-id-webform_submissions view-display-id-embed_administer');
$this
->drupalGet('/webform/test_submission_views/drafts');
$this
->assertRaw('webform-results-table');
$this
->assertNoRaw('view-id-webform_submissions view-display-id-embed_default');
$this
->clickLink('User submissions');
$this
->assertUrl('/webform/test_submission_views/drafts/user');
$this
->assertNoRaw('webform-results-table');
$this
->assertRaw('view-id-webform_submissions view-display-id-embed_default');
}
}