WebformSettingsScheduleTest.php in Webform 8.5
File
tests/src/Functional/Settings/WebformSettingsScheduleTest.php
View source
<?php
namespace Drupal\Tests\webform\Functional\Settings;
use Drupal\webform\Entity\Webform;
use Drupal\Tests\webform\Functional\WebformBrowserTestBase;
use Drupal\webform\WebformInterface;
class WebformSettingsScheduleTest extends WebformBrowserTestBase {
protected static $testWebforms = [
'test_form_opening',
'test_form_closed',
];
public function testSchedule() {
$webform_opening = Webform::load('test_form_opening');
$this
->assertTrue($webform_opening
->isClosed());
$this
->assertTrue($webform_opening
->isOpening());
$this
->drupalGet('/webform/test_form_opening');
$this
->assertNoRaw('This message should not be displayed)');
$this
->assertRaw('This form is opening soon.');
$webform_opening
->setSetting('form_open_message', '');
$webform_opening
->save();
$this
->drupalGet('/webform/test_form_opening');
$this
->assertNoRaw('This form is opening soon.');
$this
->assertRaw('This form has not yet been opened to submissions.');
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('/webform/test_form_opening');
$this
->assertRaw('This message should not be displayed');
$this
->assertNoRaw('This form has not yet been opened to submissions.');
$this
->assertRaw('Only submission administrators are allowed to access this webform and create new submissions.');
$webform_opening
->set('status', WebformInterface::STATUS_OPEN);
$webform_opening
->save();
$this
->assertFalse($webform_opening
->isClosed());
$this
->assertTrue($webform_opening
->isOpen());
$this
->drupalGet('/webform/test_form_opening');
$this
->assertRaw('This message should not be displayed');
$this
->assertNoRaw('This form has not yet been opened to submissions.');
$this
->assertNoRaw('Only submission administrators are allowed to access this webform and create new submissions.');
$webform_closed = Webform::load('test_form_closed');
$this
->drupalLogout();
$this
->assertTrue($webform_closed
->isClosed());
$this
->assertFalse($webform_closed
->isOpen());
$this
->drupalGet('/webform/test_form_closed');
$this
->assertNoRaw('This message should not be displayed)');
$this
->assertRaw('This form is closed.');
$webform_closed
->setSetting('form_close_message', '');
$webform_closed
->save();
$this
->drupalGet('/webform/test_form_closed');
$this
->assertNoRaw('This form is closed.');
$this
->assertRaw('Sorry… This form is closed to new submissions.');
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('/webform/test_form_closed');
$this
->assertRaw('This message should not be displayed');
$this
->assertNoRaw('This form is closed.');
$this
->assertRaw('Only submission administrators are allowed to access this webform and create new submissions.');
$webform_closed
->set('status', WebformInterface::STATUS_OPEN);
$webform_closed
->save();
$this
->assertFalse($webform_closed
->isClosed());
$this
->assertTrue($webform_closed
->isOpen());
$this
->drupalGet('/webform/test_form_closed');
$this
->assertRaw('This message should not be displayed');
$this
->assertNoRaw('This form is closed.');
$this
->assertNoRaw('Only submission administrators are allowed to access this webform and create new submissions.');
}
}