You are here

public function ReCaptchaActionListBuilderTest::testListBuilder in reCAPTCHA v3 8

Test case for the recaptcha action list builder.

File

tests/src/Functional/ReCaptchaActionListBuilderTest.php, line 32

Class

ReCaptchaActionListBuilderTest
Class ReCaptchaActionListBuilderTest.

Namespace

Drupal\Tests\recaptcha_v3\Functional

Code

public function testListBuilder() {
  $add_form = Url::fromRoute('entity.recaptcha_v3_action.add_form');
  $collection = Url::fromRoute('entity.recaptcha_v3_action.collection');
  $assert = $this
    ->assertSession();

  // Ensure anonymous access is denied to the add form.
  $this
    ->drupalGet($add_form);
  $assert
    ->statusCodeEquals(403);

  // Ensure anonymous access is denied to the collection form.
  $this
    ->drupalGet($collection);
  $assert
    ->statusCodeEquals(403);

  // Sign in as a captcha administrator.
  $this
    ->drupalLogIn($this
    ->createUser([
    'administer CAPTCHA settings',
  ]));

  // Add an action.
  $this
    ->drupalPostForm($add_form, [
    'label' => 'Test action',
    'id' => 'test_action',
    'threshold' => '.5',
    'challenge' => 'default',
  ], 'Save');

  // Check that the collection contains the new action.
  $this
    ->drupalGet($collection);
  $assert
    ->pageTextContains('Test action');
  $assert
    ->pageTextContains('test_action');
  $assert
    ->pageTextContains('.5');
  $assert
    ->pageTextContains('Default');
}