public function WebformOptionsLimitUserTest::testOptionsLimitUserTest in Webform 8.5
Same name and namespace in other branches
- 6.x modules/webform_options_limit/tests/src/Functional/WebformOptionsLimitUserTest.php \Drupal\Tests\webform_options_limit\Functional\WebformOptionsLimitUserTest::testOptionsLimitUserTest()
Test options limit user.
File
- modules/
webform_options_limit/ tests/ src/ Functional/ WebformOptionsLimitUserTest.php, line 27
Class
- WebformOptionsLimitUserTest
- Webform options limit test.
Namespace
Drupal\Tests\webform_options_limit\FunctionalCode
public function testOptionsLimitUserTest() {
$webform = Webform::load('test_handler_options_limit_user');
// Create authenticated user.
$user = $this
->drupalCreateUser();
$this
->drupalLogin($user);
// Check that options limit is not met for authenticated 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.');
// Check that options limit is reached for authenticated user.
$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.');
// Create another authenticated user.
$user = $this
->drupalCreateUser();
$this
->drupalLogin($user);
// Check that options limit is not met for authenticated 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.');
// Check that options limit is reached for authenticated user.
$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.');
// Logout.
// NOTE:
// We are are testing anonymous user last because anonymous
// submission are transfered to authenticated users when they login.
$this
->drupalLogout();
// Check that options limit is not met for anonymous 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.');
// Check that options limit is reached for anonymous user.
$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.');
// Check that Options limit report is not available.
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('/admin/structure/webform/manage/test_handler_options_limit_user/results/options-limit');
$this
->assertResponse(403);
}