You are here

function ShoutboxModerateTestCase::testShoutboxModerateForm in Shoutbox 7.2

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

Test that we can moderate a shout.

File

./shoutbox.test, line 337
Shoutbox testing.

Class

ShoutboxModerateTestCase

Code

function testShoutboxModerateForm() {
  $shout_ids = $this
    ->getAllShoutIds();
  $this
    ->drupalGet('');
  $href = '';
  $message = '';

  // Make sure the moderate links are available for each shout.
  foreach ($shout_ids as $id) {
    $href = 'shout/' . $id . '/unpublish';
    $message = $this
      ->getMessage($id);
    $this
      ->assertLinkByHref($href, 0, 'Moderate 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 unpublish link.'));
  $this
    ->assertText(t('Are you sure you want to unpublish 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
    ->assertNoText($message, 'Old shout should not appear in block.');
  $this
    ->drupalLogout();
  $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();
}