You are here

function ShoutboxModerateTestCase::testShoutboxModeratedUser in Shoutbox 7

Same name and namespace in other branches
  1. 7.2 shoutbox.test \ShoutboxModerateTestCase::testShoutboxModeratedUser()

Test users who need approval before shouts are accepted.

File

./shoutbox.test, line 408
Shoutbox testing.

Class

ShoutboxModerateTestCase

Code

function testShoutboxModeratedUser() {
  $sb_moded_user = $this
    ->drupalCreateUser(array(
    'access shoutbox',
    'post shouts',
    'edit own shouts',
  ));
  $this
    ->drupalLogin($sb_moded_user);
  $message = $this
    ->randomName(32) . ' ' . $this
    ->randomName(5);
  $edit = array();
  $edit['message'] = $message;
  $this
    ->drupalPost(NULL, $edit, t('Shout'));
  $this
    ->drupalGet('');
  $this
    ->assertText($message, 'Shout appears in block.');
  $this
    ->drupalLogout();
  $this
    ->drupalLogin($this->sb_edit_user);
  $this
    ->drupalGet('');
  $this
    ->assertNoText($message, 'Moderated shout should not appear in block.');
  $this
    ->drupalLogout();

  // Unmoderate the shout.
  $id = $this
    ->getShoutId($message, $sb_moded_user->uid);
  $this
    ->drupalLogin($this->sb_moderator);
  $href = 'shout/' . $id . '/publish';
  $this
    ->assertLinkByHref($href, 0, 'Unmoderate link should exist');
  $urls = $this
    ->xpath('//div[@id=\'shoutbox-body\']/table/tbody//a[contains(@href, :href)]', array(
    ':href' => $href,
  ));
  $url_target = $this
    ->getAbsoluteUrl($urls[0]['href']);
  $this
    ->drupalGet($url_target);
  $this
    ->assertResponse(200, t('User can click publish link.'));
  $this
    ->assertText(t('Are you sure you want to publish this shout?'), 'Confirmation text should exist on page');
  $this
    ->assertText(t('This action cannot be undone.'), 'Cannot be undone text should exist on page');
  $this
    ->assertLink('Cancel', 0, 'Cancel link exists on page.');
  $this
    ->assertFieldById('edit-submit', NULL, 'The submit button exists on the page');
  $this
    ->drupalPost(NULL, array(), t('Confirm'));
  $this
    ->assertText($message, 'Old shout should appear in block.');
  $this
    ->drupalLogout();
  $this
    ->drupalLogin($this->sb_edit_user);
  $this
    ->drupalGet('');
  $this
    ->assertText($message, 'Old shout should appear in block.');
  $this
    ->drupalLogout();
  $this
    ->drupalLogin($sb_moded_user);
  $this
    ->drupalGet('');
  $this
    ->assertText($message, 'Old shout should appear in block.');
  $this
    ->drupalLogout();
}