addContactForm example

// Create and log in administrative user.     $admin_user = $this->drupalCreateUser([
      'access site-wide contact form',
      'administer contact forms',
      'administer users',
      'administer account settings',
      'administer contact_message fields',
    ]);
    $this->drupalLogin($admin_user);
    // Create first valid contact form.     $mail = 'simpletest@example.com';
    $this->addContactForm($id = mb_strtolower($this->randomMachineName(16))$label = $this->randomMachineName(16)implode(',', [$mail]), '', TRUE, 'Your message has been sent.', [
      'send_a_pony' => 1,
    ]);
    $this->assertSession()->pageTextContains('Contact form ' . $label . ' has been added.');

    // Ensure that anonymous can submit site-wide contact form.     user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['access site-wide contact form']);
    $this->drupalLogout();
    $this->drupalGet('contact');
    $this->assertSession()->pageTextContains('Your email address');
    $this->assertSession()->pageTextNotContains('Form');
    $this->submitContact($name = $this->randomMachineName(16)$mail$subject = $this->randomMachineName(16)$id$message = $this->randomMachineName(64));
    
$this->drupalGet('contact');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains('The contact form has not been configured.');
    // Test access personal form via site-wide contact page.     $this->drupalGet('contact/personal');
    $this->assertSession()->statusCodeEquals(403);

    // Add forms.     // Test invalid recipients.     $invalid_recipients = ['invalid', 'invalid@', 'invalid@site.', '@site.', '@site.com'];
    foreach ($invalid_recipients as $invalid_recipient) {
      $this->addContactForm($this->randomMachineName(16)$this->randomMachineName(16)$invalid_recipient, '', FALSE);
      $this->assertSession()->pageTextContains($invalid_recipient . ' is an invalid email address.');
    }

    // Test validation of empty form and recipients fields.     $this->addContactForm('', '', '', '', TRUE);
    $this->assertSession()->pageTextContains('Label field is required.');
    $this->assertSession()->pageTextContains('Machine-readable name field is required.');
    $this->assertSession()->pageTextContains('Recipients field is required.');

    // Test validation of max_length machine name.     $recipients = ['simpletest&@example.com', 'simpletest2@example.com', 'simpletest3@example.com'];
    
Home | Imprint | This part of the site doesn't use cookies.