You are here

public function MaillogTestCase::testDeletePageSecurity in Maillog / Mail Developer 7

Confirm that the 'delete' pages are not able to delete messages.

File

tests/MaillogTestCase.test, line 207
Unit-ish tests for the Maillog module.

Class

MaillogTestCase
All unit tests for the module.

Code

public function testDeletePageSecurity() {

  // Send some test emails.
  $this
    ->sendTestEmail();
  $this
    ->sendTestEmail();

  // Load the message log data to confirm the records were created.
  $messages = $this
    ->getAllMaillogEntries();
  $this
    ->assertEqual(count($messages), 2, 'Two messages are in the maillog.');

  // Log in as the admin.
  $this
    ->loginAdminUser();

  // Load the 'delete' path for one of the items..
  $this
    ->drupalGet('admin/reports/maillog/delete/' . $messages[0]['id']);
  $this
    ->assertResponse(200);

  // Confirm the page is a confirmation page.
  $this
    ->assertText('Delete Maillog record?');
  $this
    ->assertText('Message details');
  $this
    ->assertText('This action cannot be undone.');
  $this
    ->assertFieldByName('subject');
  $this
    ->assertFieldByName('to');
  $this
    ->assertFieldByName('op', 'Confirm');
  $this
    ->assertLink('Cancel');

  // Confirm that just loading the delete page doesn't delete anything.
  $messages = $this
    ->getAllMaillogEntries();
  $this
    ->assertEqual(count($messages), 2, 'There are still two messages in the maillog.');

  // Follow the 'delete' action.
  $this
    ->drupalPost(NULL, array(), 'Confirm');
  $this
    ->assertResponse(200);

  // Confirm that only one message is left.
  $messages = $this
    ->getAllMaillogEntries();
  $this
    ->assertTrue(count($messages) === 1, 'There is now only one message in the maillog.');
}