You are here

public function CaptchaWebTestBase::setUp in CAPTCHA 8

Overrides BrowserTestBase::setUp

1 call to CaptchaWebTestBase::setUp()
CaptchaCacheTest::setUp in tests/src/Functional/CaptchaCacheTest.php
1 method overrides CaptchaWebTestBase::setUp()
CaptchaCacheTest::setUp in tests/src/Functional/CaptchaCacheTest.php

File

tests/src/Functional/CaptchaWebTestBase.php, line 71

Class

CaptchaWebTestBase
Base class for CAPTCHA tests.

Namespace

Drupal\Tests\captcha\Functional

Code

public function setUp() {

  // Load two modules: the captcha module itself and the comment
  // module for testing anonymous comments.
  parent::setUp();
  module_load_include('inc', 'captcha');
  $this
    ->drupalCreateContentType([
    'type' => 'page',
  ]);

  // Create a normal user.
  $permissions = [
    'access comments',
    'post comments',
    'skip comment approval',
    'access content',
    'create page content',
    'edit own page content',
  ];
  $this->normalUser = $this
    ->drupalCreateUser($permissions);

  // Create an admin user.
  $permissions[] = 'administer CAPTCHA settings';
  $permissions[] = 'skip CAPTCHA';
  $permissions[] = 'administer permissions';
  $permissions[] = 'administer content types';
  $this->adminUser = $this
    ->drupalCreateUser($permissions);

  // Open comment for page content type.
  $this
    ->addDefaultCommentField('node', 'page');

  // Put comments on page nodes on a separate page.
  $comment_field = FieldConfig::loadByName('node', 'page', 'comment');
  $comment_field
    ->setSetting('form_location', CommentItemInterface::FORM_SEPARATE_PAGE);
  $comment_field
    ->save();

  /* @var \Drupal\captcha\Entity\CaptchaPoint $captcha_point */
  $captcha_point = \Drupal::entityTypeManager()
    ->getStorage('captcha_point')
    ->load('user_login_form');
  $captcha_point
    ->enable()
    ->save();
  $this
    ->config('captcha.settings')
    ->set('default_challenge', 'captcha/test')
    ->save();
}