You are here

function ShoutboxUserAccessTest::testAdminUserAccess in Shoutbox 5

Same name and namespace in other branches
  1. 6 tests/shoutbox_user_access.test \ShoutboxUserAccessTest::testAdminUserAccess()

File

tests/shoutbox_user_access.test, line 225
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 testAdminUserAccess() {

  // test admin access
  $this
    ->drupalLoginUser($this->admin_user);

  // Create an unmoderated piece of content.
  $shout = array();
  $shout['nick'] = $this
    ->randomName(2, 'shout');
  $shout['message'] = $this
    ->randomName(10, 'shout');
  $shout['url'] = 'http://ghanaweb.com';
  $this
    ->drupalPostRequest('node', $shout, 'Shout');
  $this
    ->assertWantedRaw(t('Your shout has been submitted.'));
  $this
    ->assertWantedRaw(t($shout['message']));

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

  // moderate content
  $path = 'shoutbox/' . $sid . '/unpublish';

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

  // un moderate it
  $path = 'shoutbox/' . $sid . '/publish';

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

  // try and edit it
  // edit the shout
  $edited_shout = array();
  $edited_shout['shout'] = $this
    ->randomName(10, 'shout');
  $path = 'shoutbox/' . $sid . '/edit';
  $this
    ->drupalPostRequest($path, $edited_shout, 'Update');
  $this
    ->assertWantedRaw(t('The shout has been saved.'));
  $this
    ->assertWantedRaw(t($edited_shout['shout']));

  //delete it

  // delete the shout
  $path = 'shoutbox/' . $sid . '/delete';
  $this
    ->drupalPostRequest($path, NULL, 'Confirm');
  $this
    ->assertWantedRaw(t('Your shout was deleted.'));
  $this
    ->assertNoText(t($edited_shout['shout']));

  // logout
  $url = url('logout', NULL, NULL, TRUE);
  $this
    ->get($url);
  $this
    ->cleanup($sid);

  // create a regular user content
  // Login as basic user to perform initial content creation.
  $this
    ->drupalLoginUser($this->unmoderated_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
    ->drupalPostRequest('node', $shout, 'Shout');
  $this
    ->assertWantedRaw(t('Your shout has been submitted.'));
  $this
    ->assertWantedRaw(t($shout['message']));

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

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

  // login as admin
  $this
    ->drupalLoginUser($this->admin_user);

  // moderate content
  $path = 'shoutbox/' . $sid . '/unpublish';

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

  // un moderate it
  $path = 'shoutbox/' . $sid . '/publish';

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

  // try and edit it
  // edit the shout
  $edited_shout = array();
  $edited_shout['shout'] = $this
    ->randomName(10, 'shout');
  $path = 'shoutbox/' . $sid . '/edit';
  $this
    ->drupalPostRequest($path, $edited_shout, 'Update');
  $this
    ->assertWantedRaw(t('The shout has been saved.'));
  $this
    ->assertWantedRaw(t($edited_shout['shout']));

  //delete it

  // delete the shout
  $path = 'shoutbox/' . $sid . '/delete';
  $this
    ->drupalPostRequest($path, NULL, 'Confirm');
  $this
    ->assertWantedRaw(t('Your shout was deleted.'));
  $this
    ->assertNoText(t($edited_shout['shout']));

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