WebformResultsDisabledTest.php in Webform 8.5
File
tests/src/Functional/WebformResultsDisabledTest.php
View source
<?php
namespace Drupal\Tests\webform\Functional;
use Drupal\webform\Entity\Webform;
use Drupal\webform\Entity\WebformSubmission;
class WebformResultsDisabledTest extends WebformBrowserTestBase {
protected static $testWebforms = [
'test_form_results_disabled',
];
public function testSettings() {
$this
->drupalLogin($this->rootUser);
$webform_results_disabled = Webform::load('test_form_results_disabled');
$webform_submission = $this
->postSubmission($webform_results_disabled);
$this
->assertNull($webform_submission, 'Submission not saved to the database.');
$this
->drupalGet('/webform/test_form_results_disabled');
$this
->assertRaw(t('This webform is currently not saving any submitted data.'));
$this
->assertFieldByName('op', 'Submit');
$this
->assertNoRaw(t('Unable to display this webform. Please contact the site administrator.'));
$this
->drupalLogout();
$this
->drupalGet('/webform/test_form_results_disabled');
$this
->assertNoRaw(t('This webform is currently not saving any submitted data.'));
$this
->assertNoFieldByName('op', 'Submit');
$this
->assertRaw(t('Unable to display this webform. Please contact the site administrator.'));
$webform_results_disabled
->setSetting('results_disabled_ignore', TRUE);
$webform_results_disabled
->save();
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('/webform/test_form_results_disabled');
$this
->assertNoRaw(t('This webform is currently not saving any submitted data.'));
$this
->assertNoRaw(t('Unable to display this webform. Please contact the site administrator.'));
$this
->assertFieldByName('op', 'Submit');
$this
->drupalGet('/admin/structure/webform/manage/test_form_results_disabled/results/submissions');
$this
->assertResponse(403);
$this
->drupalLogout();
$this
->drupalGet('/webform/test_form_results_disabled');
$this
->assertNoRaw(t('This webform is currently not saving any submitted data.'));
$this
->assertNoRaw(t('Unable to display this webform. Please contact the site administrator.'));
$this
->assertFieldByName('op', 'Submit');
$webform_results_disabled
->setSetting('results_disabled', FALSE);
$webform_results_disabled
->save();
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('/admin/structure/webform/manage/test_form_results_disabled/results/submissions');
$this
->assertResponse(200);
$sid = $this
->postSubmissionTest($webform_results_disabled);
$webform_submission = WebformSubmission::load($sid);
$this
->drupalGet('/admin/structure/webform/manage/test_form_results_disabled/results/submissions');
$this
->assertNoRaw('This webform is currently not saving any submitted data');
$this
->assertRaw('>' . $webform_submission
->serial() . '<');
$webform_results_disabled
->setSetting('results_disabled', TRUE);
$webform_results_disabled
->save();
$this
->drupalGet('/admin/structure/webform/manage/test_form_results_disabled/results/submissions');
$this
->assertRaw('This webform is currently not saving any submitted data');
$this
->assertRaw('>' . $webform_submission
->serial() . '<');
$webform_submission
->delete();
$this
->drupalGet('/admin/structure/webform/manage/test_form_results_disabled/results/submissions');
$this
->assertResponse(403);
}
}