View source
<?php
namespace Drupal\Tests\webform_submission_log\Functional;
use Drupal\Tests\webform\Functional\WebformBrowserTestBase;
use Drupal\Tests\webform_submission_log\Traits\WebformSubmissionLogTrait;
use Drupal\webform\Entity\Webform;
use Drupal\webform\Entity\WebformSubmission;
class WebformSubmissionLogTest extends WebformBrowserTestBase {
use WebformSubmissionLogTrait;
public static $modules = [
'webform',
'webform_submission_log',
];
protected static $testWebforms = [
'test_submission_log',
];
public function testSubmissionLog() {
global $base_path;
$admin_user = $this
->drupalCreateUser([
'administer webform',
'access webform submission log',
]);
$webform = Webform::load('test_submission_log');
$sid_1 = $this
->postSubmission($webform);
$log = $this
->getLastSubmissionLog();
$this
->assertEqual($log->lid, 1);
$this
->assertEqual($log->sid, 1);
$this
->assertEqual($log->uid, 0);
$this
->assertEqual($log->handler_id, '');
$this
->assertEqual($log->operation, 'submission created');
$this
->assertEqual($log->message, '@title created.');
$this
->assertEqual($log->variables, [
'@title' => 'Test: Submission: Logging: Submission #1',
]);
$this
->assertEqual($log->webform_id, 'test_submission_log');
$this
->assertNull($log->entity_type);
$this
->assertNull($log->entity_id);
$sid_2 = $this
->postSubmission($webform, [
'value' => 'Test',
], 'Save Draft');
$log = $this
->getLastSubmissionLog();
$this
->assertEqual($log->lid, 2);
$this
->assertEqual($log->sid, 2);
$this
->assertEqual($log->uid, 0);
$this
->assertEqual($log->handler_id, '');
$this
->assertEqual($log->operation, 'draft created');
$this
->assertEqual($log->message, '@title draft created.');
$this
->assertEqual($log->variables, [
'@title' => 'Test: Submission: Logging: Submission #2',
]);
$this
->assertEqual($log->webform_id, 'test_submission_log');
$this
->assertNull($log->entity_type);
$this
->assertNull($log->entity_id);
$this
->postSubmission($webform, [
'value' => 'Test',
], 'Save Draft');
$log = $this
->getLastSubmissionLog();
$this
->assertEqual($log->lid, 3);
$this
->assertEqual($log->sid, 2);
$this
->assertEqual($log->uid, 0);
$this
->assertEqual($log->handler_id, '');
$this
->assertEqual($log->operation, 'draft updated');
$this
->assertEqual($log->message, '@title draft updated.');
$this
->assertEqual($log->variables, [
'@title' => 'Test: Submission: Logging: Submission #2',
]);
$this
->assertEqual($log->webform_id, 'test_submission_log');
$this
->assertNull($log->entity_type);
$this
->assertNull($log->entity_id);
$this
->postSubmission($webform);
$log = $this
->getLastSubmissionLog();
$this
->assertEqual($log->lid, 4);
$this
->assertEqual($log->sid, 2);
$this
->assertEqual($log->uid, 0);
$this
->assertEqual($log->handler_id, '');
$this
->assertEqual($log->operation, 'submission completed');
$this
->assertEqual($log->message, '@title completed using saved draft.');
$this
->assertEqual($log->variables, [
'@title' => 'Test: Submission: Logging: Submission #2',
]);
$this
->assertEqual($log->webform_id, 'test_submission_log');
$this
->assertNull($log->entity_type);
$this
->assertNull($log->entity_id);
$this
->drupalLogin($admin_user);
$submission_log = $this
->getSubmissionLog();
$log = $submission_log[0];
$this
->assertEqual($log->lid, 6);
$this
->assertEqual($log->uid, $admin_user
->id());
$this
->assertEqual($log->sid, 2);
$this
->assertEqual($log->operation, 'submission converted');
$this
->assertEqual($log->message, '@title converted from anonymous to @user.');
$this
->assertEqual($log->variables, [
'@title' => 'Test: Submission: Logging: Submission #2',
'@user' => $admin_user
->label(),
]);
$log = $submission_log[1];
$this
->assertEqual($log->lid, 5);
$this
->assertEqual($log->uid, $admin_user
->id());
$this
->assertEqual($log->sid, 1);
$this
->assertEqual($log->operation, 'submission converted');
$this
->assertEqual($log->message, '@title converted from anonymous to @user.');
$this
->assertEqual($log->variables, [
'@title' => 'Test: Submission: Logging: Submission #1',
'@user' => $admin_user
->label(),
]);
$this
->drupalPostForm("admin/structure/webform/manage/test_submission_log/submission/{$sid_2}/edit", [], 'Save');
$log = $this
->getLastSubmissionLog();
$this
->assertEqual($log->lid, 7);
$this
->assertEqual($log->sid, 2);
$this
->assertEqual($log->uid, $admin_user
->id());
$this
->assertEqual($log->handler_id, '');
$this
->assertEqual($log->webform_id, 'test_submission_log');
$this
->assertNull($log->entity_type);
$this
->assertNull($log->entity_id);
$this
->drupalPostForm("admin/structure/webform/manage/test_submission_log/submission/{$sid_1}/delete", [], 'Delete');
$this
->drupalPostForm("admin/structure/webform/manage/test_submission_log/submission/{$sid_2}/delete", [], 'Delete');
$log = $this
->getLastSubmissionLog();
$this
->assertFalse($log);
$this
->drupalGet('/admin/structure/webform/submissions/log');
$this
->assertRaw('No log messages available.');
$this
->drupalGet('/admin/structure/webform/manage/test_submission_log/results/log');
$this
->assertRaw('No log messages available.');
$sid_3 = $this
->postSubmission($webform);
WebformSubmission::load($sid_3);
$this
->drupalGet('/admin/structure/webform/submissions/log');
$this
->assertNoRaw('No log messages available.');
$this
->assertRaw('<a href="' . $base_path . 'admin/structure/webform/manage/test_submission_log/results/log">Test: Submission: Logging</a>');
$this
->assertRaw('<a href="' . $base_path . 'admin/structure/webform/manage/test_submission_log/submission/3/log">3</a></td>');
$this
->assertRaw('Test: Submission: Logging: Submission #3 created.');
$this
->drupalGet('/admin/structure/webform/manage/test_submission_log/results/log');
$this
->assertNoRaw('No log messages available.');
$this
->assertNoRaw('<a href="' . $base_path . 'admin/structure/webform/manage/test_submission_log/results/log">Test: Submission: Logging</a>');
$this
->assertRaw('<a href="' . $base_path . 'admin/structure/webform/manage/test_submission_log/submission/3/log">3</a></td>');
$this
->assertRaw('Test: Submission: Logging: Submission #3 created.');
}
}