You are here

private function EntityformCRUDTestCase::entityformValidatePerms in Entityform 7.2

Same name and namespace in other branches
  1. 7 entityform.test \EntityformCRUDTestCase::entityformValidatePerms()

Validate permission for user on their own entityform submissions.

For now assume the user has only submitted 1 entityform. The last submission

1 call to EntityformCRUDTestCase::entityformValidatePerms()
EntityformCRUDTestCase::testCreateEntityformType in ./entityform.test

File

./entityform.test, line 190

Class

EntityformCRUDTestCase
Test basic CRUD functionality.

Code

private function entityformValidatePerms($machine_name, $user) {
  $this
    ->drupalLogin($user);
  $can_view = user_access('view own entityform', $user) || user_access('view any entityform', $user);
  $can_edit = user_access('edit own entityform', $user) || user_access('edit any entityform', $user);
  $can_delete = user_access('delete own entityform', $user) || user_access('delete any entityform', $user);
  $form_url = 'eform/submit/' . str_replace('_', '-', $machine_name);
  $this
    ->drupalGet($form_url);
  if ($can_view) {

    // user should be able to see link to own submissions
    $this
      ->assertText(t('View your previous submissions'), 'User can see link to own submissions.');
  }
  else {

    // user should NOT be able to see link to own submissions
    $this
      ->assertNoText(t('View your previous submissions'), 'User can NOT see link to own submissions.');
  }

  // Try to get submission page
  $this
    ->drupalGet('eform/' . str_replace('_', '-', $machine_name) . '/submissions');
  if ($can_view) {
    $this
      ->assertText(t('Your Submissions'), 'Access can view own submissions.');
    $this
      ->assertUniqueText($user->name, 'User only sees 1 submission.');
    if ($can_delete) {
      $this
        ->assertUniqueText(t('delete'), 'User sees delete link');
    }
    else {
      $this
        ->assertNotext(t('delete'), 'User cannot see delete link');
    }
    if ($can_edit) {
      $this
        ->assertUniqueText(t('edit'), 'User sees edit link');
    }
    else {
      $this
        ->assertNotext(t('edit'), 'User cannot see edit link');
    }
  }
  else {
    $this
      ->assertText(t('Access denied'), 'Access has been denied for user to view own submissions.');
  }

  // Try to get Entityform View page
  $this
    ->drupalGet('entityform/' . $this->entityform_submission_count);
  if ($can_view) {
    $this
      ->assertText('submitext-' . $user->name, 'User sees their own submission.');
  }
  else {
    $this
      ->assertText(t('Access denied'), 'Access has been denied for user to view own submission page.');
  }
  $this
    ->drupalGet('entityform/' . $this->entityform_submission_count . '/edit');
  if ($can_edit) {
    $this
      ->assertText(t('Submitted by') . ' ' . $user->name, 'User sees edit own submission.');
  }
  else {
    $this
      ->assertText(t('Access denied'), 'Access has been denied for user to edit own submission page.');
  }
  $this
    ->drupalGet('entityform/' . $this->entityform_submission_count . '/delete');
  if ($can_delete) {
    $this
      ->assertText(t('Are you sure you want to delete'), 'User can see delete for own enityform');
  }
  else {
    $this
      ->assertText(t('Access denied'), 'Access has been denied for user to own submission delete page.');
  }
}