You are here

function MessageUiPermissions::testMessageUiPermissions in Message UI 7

Test message_access use case.

File

./message_ui.test, line 43

Class

MessageUiPermissions
Testing the message access use case.

Code

function testMessageUiPermissions() {

  // verify the user can't create the message.
  $this
    ->drupalLogin($this->user);
  $this
    ->drupalGet('admin/content/message/create/foo');
  $this
    ->assertResponse(403, t("The user can't create message."));

  // Create the message.
  $this
    ->grantMessageUiPermission('create');
  $this
    ->drupalPost('admin/content/message/create/foo', array(), t('Create'));

  // Verify the user now can see the text.
  $this
    ->grantMessageUiPermission('view');
  $this
    ->drupalGet('message/1');
  $this
    ->assertResponse(200, "The user can't view message.");

  // Verify can't edit the message.
  $this
    ->drupalGet('message/1/edit');
  $this
    ->assertResponse(403, "The user can't edit message.");

  // Grant permission to the user.
  $this
    ->grantMessageUiPermission('edit');
  $this
    ->drupalGet('message/1/edit');
  $this
    ->assertResponse(200, "The user can't edit message.");

  // Verify the user can't delete the message.
  $this
    ->drupalGet('message/1/delete');
  $this
    ->assertResponse(403, "The user can't delete the message");

  // Grant the permission to the user.
  $this
    ->grantMessageUiPermission('delete');
  $this
    ->drupalPost('message/1/delete', array(), t('Delete'));

  // The user did not have the permission to the overview page - verify access
  // denied.
  $this
    ->assertResponse(403, t("The user can't access the over view page."));
  user_role_grant_permissions($this->rid, array(
    'administer message types',
  ));
  $this
    ->drupalGet('admin/content/message');
  $this
    ->assertResponse(200, "The user can access the over view page.");

  // Create a new user with the bypass access permission and verify the bypass.
  $this
    ->drupalLogout();
  $user = $this
    ->drupalCreateUser(array(
    'bypass message access control',
  ));

  // Verify the user can by pass the message access control.
  $this
    ->drupalLogin($user);
  $this
    ->drupalGet('admin/content/message/create/foo');
  $this
    ->assertResponse(200, 'The user can bypass the message access control.');
}