You are here

function ShoutboxUserAccessTest::testModerationUserAccess in Shoutbox 6

File

tests/shoutbox_user_access.test, line 158
shoutbox unit test for shoutbox_user_access and shoutbox_is_user_owned

Class

ShoutboxUserAccessTest
@file shoutbox unit test for shoutbox_user_access and shoutbox_is_user_owned

Code

function testModerationUserAccess() {

  // now test moderation
  // create a moderated shout
  $this
    ->drupalLoginUser($this->basic_user);

  // Create an  unmoderated piece of content.
  $shout = array();
  $shout['nick'] = $this
    ->randomName(2, 'shout');
  $shout['message'] = $this
    ->randomName(10, 'shout');
  $shout['url'] = 'http://slashdot.org';
  $this
    ->drupalPost('node', $shout, 'Shout');
  $this
    ->assertWantedRaw(t('Your shout has been submitted for approval by a moderator. Others will not see this shout until it is approved.'));

  // get the shout id
  $sid = $this
    ->_get_shout_id($shout);

  // Try to moderate  it
  $path = 'shoutbox/' . $sid . '/publish';
  $url = url($path, array(
    'absolute' => TRUE,
  ));
  $this
    ->get($url);
  $this
    ->assertResponse(403);

  // logout
  $url = url('logout', array(
    'absolute' => TRUE,
  ));
  $this
    ->get($url);

  // login as moderator
  $this
    ->drupalLoginUser($this->moderator);

  // moderate content
  $path = 'shoutbox/' . $sid . '/publish';
  $url = url($path, array(
    'absolute' => TRUE,
  ));

  // verify confirmation page
  $this
    ->get($url);
  $this
    ->assertText(t('Are you sure you want to publish this shout?'));
  $this
    ->drupalPost($path, NULL, 'Confirm');
  $this
    ->assertText(t('The shout was published.'));

  // now unpublish it
  $path = 'shoutbox/' . $sid . '/unpublish';
  $url = url($path, array(
    'absolute' => TRUE,
  ));

  // verify confirmation page
  $this
    ->get($url);
  $this
    ->assertText(t('Are you sure you want to unpublish this shout?'));
  $this
    ->drupalPost($path, NULL, 'Confirm');
  $this
    ->assertText(t('The shout was unpublished.'));

  // try and edit it
  $path = 'shoutbox/' . $sid . '/edit';
  $url = url($path, array(
    'absolute' => TRUE,
  ));
  $this
    ->get($url);
  $this
    ->assertResponse(403);

  // try and delete it
  $path = 'shoutbox/' . $sid . '/delete';
  $url = url($path, array(
    'absolute' => TRUE,
  ));
  $this
    ->get($url);
  $this
    ->assertResponse(403);

  // delete shout
  $this
    ->cleanup($sid);
}