You are here

public function MailUiTest::testVerboseOutput in Maillog / Mail Developer 8

Tests verbose output after send an email.

File

tests/src/Functional/MailUiTest.php, line 113

Class

MailUiTest
Tests the maillog plugin user interface.

Namespace

Drupal\Tests\maillog\Functional

Code

public function testVerboseOutput() {

  // Create a user with valid permissions.
  $account = $this
    ->drupalCreateUser();
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'access user contact forms',
    'access user profiles',
    'view maillog',
  ]));

  // Load the contact form.
  $this
    ->drupalGet('user/' . $account
    ->id() . '/contact');
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Send the message.
  $edit = [
    'subject[0][value]' => 'Test Message',
    'message[0][value]' => 'This is a test.',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Send message');
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Assert the verbose output.
  $this
    ->assertText('A mail has been sent:');
  $this
    ->assertRaw('[To] => ' . $account
    ->getAccountName() . '@example.com');
  $this
    ->assertRaw('[Header] => Array');
  $this
    ->assertRaw('[X-Mailer] => Drupal');
  $this
    ->assertRaw('[Content-Type] => text/plain; charset=UTF-8; format=flowed; delsp=yes');
  $this
    ->assertRaw('[Body] => Hello ' . $account
    ->getAccountName());

  // Set verbose to false.
  $this
    ->config('maillog.settings')
    ->set('verbose', FALSE)
    ->save();

  // Send another message.
  $this
    ->drupalGet('user/' . $account
    ->id() . '/contact');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $edit = [
    'subject[0][value]' => 'Test Message',
    'message[0][value]' => 'This is a test.',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Send message');
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Assert there is no output.
  $this
    ->assertNoText('A mail has been sent:');
  $this
    ->assertNoRaw('[To] => ' . $account
    ->getAccountName() . '@example.com');
  $this
    ->assertNoRaw('[Header] => Array');

  // Tests that users without permission cannot see verbose output.
  $this
    ->config('maillog.settings')
    ->set('verbose', TRUE)
    ->save();
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'access user contact forms',
    'access user profiles',
  ]));
  $this
    ->drupalGet('user/' . $account
    ->id() . '/contact');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $edit = [
    'subject[0][value]' => 'Test Message',
    'message[0][value]' => 'This is a test.',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Send message');
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Assert there is no output.
  $this
    ->assertNoText('A mail has been sent:');
  $this
    ->assertNoRaw('[To] => ' . $account
    ->getAccountName() . '@example.com');
  $this
    ->assertNoRaw('[Header] => Array');
}