You are here

public function EntityLegalDocumentTestCase::testEditForm in Entity Legal 7

Same name and namespace in other branches
  1. 7.2 tests/entity_legal.document.test \EntityLegalDocumentTestCase::testEditForm()

Test the functionality of the edit form.

File

tests/entity_legal.document.test, line 82
Test file include for legal document.

Class

EntityLegalDocumentTestCase
Simpletest class for legal document entities.

Code

public function testEditForm() {
  $document = $this
    ->createDocument(TRUE, TRUE, array(
    'new_users' => array(
      'require_method' => 'form_inline',
    ),
    'existing_users' => array(
      'require_method' => 'redirect',
    ),
  ));
  $document_uri = $document
    ->uri();
  $alias = array(
    'source' => $document_uri['path'],
    'alias' => $this
      ->randomName(),
  );
  path_save($alias);
  drupal_static_reset();
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet('admin/structure/legal/manage/' . $document
    ->identifier());

  // Test field default values.
  debug(drupal_get_path_alias($document_uri['path']));
  $this
    ->assertFieldByName('label', $document
    ->label(), 'Label is set correctly for document');
  $this
    ->assertFieldByName('settings[new_users][require]', 1, 'Require new users set correctly');
  $this
    ->assertFieldByName('settings[new_users][require_method]', 'form_inline', 'Require existing users set correctly');
  $this
    ->assertFieldByName('settings[existing_users][require]', 1, 'Require existing users set correctly');
  $this
    ->assertFieldByName('settings[existing_users][require_method]', 'redirect', 'Require existing users set correctly');
  $this
    ->assertFieldByName('path[alias]', drupal_get_path_alias($document_uri['path']), 'Path alias field set');

  // Test that changing values saves correctly.
  $new_label = $this
    ->randomName();
  $this
    ->drupalPost('admin/structure/legal/manage/' . $document
    ->identifier(), array(
    'label' => $new_label,
    'settings[new_users][require]' => FALSE,
    'settings[new_users][require_method]' => 'form_link',
    'settings[existing_users][require]' => FALSE,
    'settings[existing_users][require_method]' => 'popup',
    'path[alias]' => '',
  ), 'Save');
  $document = $this
    ->getUncachedEntity(ENTITY_LEGAL_DOCUMENT_ENTITY_NAME, $document
    ->identifier());
  $document_uri = $document
    ->uri();
  drupal_static_reset();
  $this
    ->assertEqual($new_label, $document
    ->label(), 'Label was saved correctly');
  $this
    ->assertEqual(0, $document->require_signup, 'Signup requirement was saved correctly');
  $this
    ->assertEqual(0, $document->require_existing, 'Existing user requirement was saved correctly');
  $this
    ->assertEqual('form_link', $document
    ->getSetting('new_users', 'require_method'), 'Form link method was saved correctly');
  $this
    ->assertEqual('popup', $document
    ->getSetting('existing_users', 'require_method'), 'Popup require method was saved correctly');
  $this
    ->assertEqual($document_uri['path'], drupal_get_path_alias($document_uri['path']), 'Blank path alias reset to entity uri');
}