WebformOptionsLimitUserTest.php in Webform 8.5
File
modules/webform_options_limit/tests/src/Functional/WebformOptionsLimitUserTest.php
View source
<?php
namespace Drupal\Tests\webform_options_limit\Functional;
use Drupal\webform\Entity\Webform;
use Drupal\Tests\webform\Functional\WebformBrowserTestBase;
class WebformOptionsLimitUserTest extends WebformBrowserTestBase {
public static $modules = [
'webform',
'webform_options_limit',
'webform_options_limit_test',
];
public function testOptionsLimitUserTest() {
$webform = Webform::load('test_handler_options_limit_user');
$user = $this
->drupalCreateUser();
$this
->drupalLogin($user);
$this
->drupalGet('/webform/test_handler_options_limit_user');
$this
->assertRaw('A [1 remaining]');
$this
->assertRaw('B [2 remaining]');
$this
->assertRaw('C [3 remaining]');
$this
->assertNoRaw('options_limit_user is not available.');
$this
->postSubmission($webform);
$this
->postSubmission($webform);
$this
->postSubmission($webform);
$this
->assertRaw('A [0 remaining]');
$this
->assertRaw('B [0 remaining]');
$this
->assertRaw('C [0 remaining]');
$this
->assertRaw('options_limit_user is not available.');
$user = $this
->drupalCreateUser();
$this
->drupalLogin($user);
$this
->drupalGet('/webform/test_handler_options_limit_user');
$this
->assertRaw('A [1 remaining]');
$this
->assertRaw('B [2 remaining]');
$this
->assertRaw('C [3 remaining]');
$this
->assertNoRaw('options_limit_user is not available.');
$this
->postSubmission($webform);
$this
->postSubmission($webform);
$this
->postSubmission($webform);
$this
->assertRaw('A [0 remaining]');
$this
->assertRaw('B [0 remaining]');
$this
->assertRaw('C [0 remaining]');
$this
->assertRaw('options_limit_user is not available.');
$this
->drupalLogout();
$this
->drupalGet('/webform/test_handler_options_limit_user');
$this
->assertRaw('A [1 remaining]');
$this
->assertRaw('B [2 remaining]');
$this
->assertRaw('C [3 remaining]');
$this
->assertNoRaw('options_limit_user is not available.');
$this
->postSubmission($webform);
$this
->postSubmission($webform);
$this
->postSubmission($webform);
$this
->assertRaw('A [0 remaining]');
$this
->assertRaw('B [0 remaining]');
$this
->assertRaw('C [0 remaining]');
$this
->assertRaw('options_limit_user is not available.');
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('/admin/structure/webform/manage/test_handler_options_limit_user/results/options-limit');
$this
->assertResponse(403);
}
}