You are here

public function HoneypotFormTest::setUp in Honeypot 8

Same name and namespace in other branches
  1. 2.0.x tests/src/Functional/HoneypotFormTest.php \Drupal\Tests\honeypot\Functional\HoneypotFormTest::setUp()

Overrides BrowserTestBase::setUp

File

tests/src/Functional/HoneypotFormTest.php, line 60

Class

HoneypotFormTest
Test Honeypot spam protection functionality.

Namespace

Drupal\Tests\honeypot\Functional

Code

public function setUp() {

  // Enable modules required for this test.
  parent::setUp();

  // Set up required Honeypot configuration.
  $honeypot_config = \Drupal::configFactory()
    ->getEditable('honeypot.settings');
  $honeypot_config
    ->set('element_name', 'url');

  // Disable time_limit protection.
  $honeypot_config
    ->set('time_limit', 0);

  // Test protecting all forms.
  $honeypot_config
    ->set('protect_all_forms', TRUE);
  $honeypot_config
    ->set('log', FALSE);
  $honeypot_config
    ->save();

  // Set up other required configuration.
  $user_config = \Drupal::configFactory()
    ->getEditable('user.settings');
  $user_config
    ->set('verify_mail', TRUE);
  $user_config
    ->set('register', UserInterface::REGISTER_VISITORS);
  $user_config
    ->save();

  // Create an Article node type.
  if ($this->profile != 'standard') {
    $this
      ->drupalCreateContentType([
      'type' => 'article',
      'name' => 'Article',
    ]);

    // Create comment field on article.
    $this
      ->addDefaultCommentField('node', 'article');
  }

  // Set up admin user.
  $this->adminUser = $this
    ->drupalCreateUser([
    'administer honeypot',
    'bypass honeypot protection',
    'administer content types',
    'administer users',
    'access comments',
    'post comments',
    'skip comment approval',
    'administer comments',
  ]);

  // Set up web user.
  $this->webUser = $this
    ->drupalCreateUser([
    'access comments',
    'post comments',
    'create article content',
    'access site-wide contact form',
  ]);

  // Set up example node.
  $this->node = $this
    ->drupalCreateNode([
    'type' => 'article',
    'comment' => CommentItemInterface::OPEN,
  ]);
}