You are here

function EntityformCRUDTestCase::testCreateEntityformType in Entityform 7

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

File

./entityform.test, line 69

Class

EntityformCRUDTestCase
Test basic CRUD functionality.

Code

function testCreateEntityformType() {
  $this
    ->drupalLogin($this->user_admin);

  // Create Entityform Type test_form
  $this
    ->drupalGet('admin/structure/entityform_types/add');
  $edit['label'] = "Test Form";
  $edit['type'] = 'test_form';
  $edit['data[roles][' . DRUPAL_AUTHENTICATED_RID . ']'] = DRUPAL_AUTHENTICATED_RID;
  $edit['data[instruction_pre][value]'] = "Test Instructions";
  $edit['data[submissions_view]'] = 'entityforms';
  $edit['data[user_submissions_view]'] = 'user_entityforms';
  $this
    ->drupalPost('admin/structure/entityform_types/add', $edit, t('Save entityform type'));
  $this
    ->assertText(t('The Entityform Test Form has been created.'), t('Entityform Type created successfully'));

  // Add a field to test_form
  $field = array(
    'field_name' => 'field_text',
    'type' => 'text',
    'cardinality' => 1,
    'translatable' => FALSE,
  );
  field_create_field($field);
  $instance = array(
    'entity_type' => 'entityform',
    'field_name' => 'field_text',
    'bundle' => 'test_form',
    'label' => 'Test Field',
    'description' => 'Fill out field.',
    'widget' => array(
      'type' => 'text_textfield',
      'weight' => 0,
    ),
  );
  field_create_instance($instance);
  $this
    ->drupalLogout();

  // Check that anonymous user cannot create an entityform_type
  $this
    ->drupalGet('admin/structure/entityform_types/add');
  $this
    ->assertText(t('Access denied'), 'Access has been denied for adding Entityform type.');

  // Check that anonymous cannot submit test_form
  $this
    ->drupalGet('eform/submit/test-form');
  $this
    ->assertText(t('Access denied'), 'Access has been denied for submitting Entityform type.');
  $this
    ->entityformSubmit('test_form', $this->user_low);
  $this
    ->entityformValidatePerms('test_form', $this->user_low);

  //make sure user doesn't access to other user's submisssion
  $this
    ->entityformValidateAccessOthers($this->entityform_submission_count, $this->user_view);

  // Check that authenicated user can submit test_form
  $this
    ->entityformSubmit('test_form', $this->user_view);
  $this
    ->entityformValidatePerms('test_form', $this->user_view);

  //make sure user doesn't access to other user's submisssion
  $this
    ->entityformValidateAccessOthers($this->entityform_submission_count, $this->user_edit);

  // Check that authenicated user can submit test_form
  $this
    ->entityformSubmit('test_form', $this->user_edit);
  $this
    ->entityformValidatePerms('test_form', $this->user_edit);
  $data = array(
    'roles' => array(
      DRUPAL_ANONYMOUS_RID => DRUPAL_ANONYMOUS_RID,
    ),
  );
  $this
    ->updateEntityformType('test_form', NULL, $data);

  // Check that anonymous cannot submit test_form
  $this
    ->drupalGet('eform/submit/test-form');
  $this
    ->assertText(t('Access denied'), 'Access has been denied for normal user for submitting Entityform type.');
  $this
    ->drupalLogout();
  $this
    ->drupalGet('eform/submit/test-form');
  $this
    ->assertText(t('Test Instructions'), 'Anynomous user has access to Test Form.');
  $this
    ->assertText(t('Test Field'), 'field_text exists on Test Form.');

  // Post Test Form
  $edit = array();
  $edit['field_text[und][0][value]'] = 'Test Text';
  $this
    ->drupalPost('eform/submit/test-form', $edit, t(ENTITYFORM_TEST_SUBMIT_TEXT));
  $this
    ->assertText(t(ENTITYFORM_TEST_SUBMISSION_TITLE), 'Anynomous user  can submit.');
}