You are here

function ShoutboxViewTestCase::testShoutboxViewAnon in Shoutbox 7.2

Same name and namespace in other branches
  1. 7 shoutbox.test \ShoutboxViewTestCase::testShoutboxViewAnon()

Test that anonymous users can access shoutbox.

File

./shoutbox.test, line 143
Shoutbox testing.

Class

ShoutboxViewTestCase

Code

function testShoutboxViewAnon() {
  $this
    ->drupalLogout();
  $this
    ->drupalGet('');
  $this
    ->assertNoText(t('Shoutbox'), 'Shoutbox appears in block.');
  $this
    ->assertNoText(t('There are currently no shouts'), 'There should be no shouts');
  $messages = array();
  for ($i = 0; $i < 5; $i++) {
    $sb_edit_user = $this
      ->drupalCreateUser(array(
      'access shoutbox',
      'post shouts',
      'edit own shouts',
      'post shouts without approval',
    ));
    $this
      ->drupalLogin($sb_edit_user);
    $message = $this
      ->randomName(32) . ' ' . $this
      ->randomName(5);
    $edit = array();
    $edit['message'] = $message;
    $this
      ->drupalPost(NULL, $edit, t('Shout'));
    $this
      ->drupalLogout();
    $messages[] = $message;
  }
  user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array(
    'access shoutbox',
  ));
  $this
    ->drupalGet('');
  $this
    ->assertText(t('Shoutbox'), 'Shoutbox appears in block.');

  // Verify that we don't have permission to edit the shoutbox.
  $this
    ->assertText(t('You\'re not permitted to post shouts.'), 'User does not have permission to post a shout.');
  foreach ($messages as $message) {
    $this
      ->assertText($message, 'Message appears in the block.');
  }
}