You are here

function WebformPermissionsTestCase::testWebformSubmitAccess in Webform 6.2

Same name and namespace in other branches
  1. 6.3 tests/permissions.test \WebformPermissionsTestCase::testWebformSubmitAccess()
  2. 7.4 tests/WebformPermissionsTestCase.test \WebformPermissionsTestCase::testWebformSubmitAccess()
  3. 7.3 tests/permissions.test \WebformPermissionsTestCase::testWebformSubmitAccess()

Create a webform node in which authenticated users have access to submit.

File

tests/permissions.test, line 39

Class

WebformPermissionsTestCase

Code

function testWebformSubmitAccess() {
  $this
    ->webformReset();
  $node = $this
    ->testWebformForm();
  $node->webform['roles'] = array(
    2,
  );
  node_save($node);

  // Test that the authenticated user is able to access.
  $this
    ->drupalLogin($this->webform_users['userAccess']);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText($node->body, t('Webform node created and accessible to authenticated users at !url', array(
    '!url' => 'node/' . $node->nid,
  )), t('Webform'));

  // Confirm that the submission has been created.
  $this
    ->drupalPost(NULL, array(), 'Submit');
  $this
    ->assertText($node->webform['confirmation'], t('Confirmation message "@confirmation" received.', array(
    '@confirmation' => $node->webform['confirmation'],
  )), t('Webform'));
  $this
    ->drupalLogout();

  // The anonymous user should not be able to submit.
  $this
    ->drupalGet('node/' . $node->nid);

  // Note: Should be: You must <a href="!login">login</a> or <a href="!register">register</a> to view this form.
  // Something in SimpleTest isn't handling the string correctly.
  $this
    ->assertText(t(' to view this form.', array(
    '!login' => url('user/login'),
    '!register' => url('user/register'),
  )), t('Anonymous user is not allowed to submit form.'), t('Webform'));
  $this
    ->drupalLogout();
}