You are here

entity_legal.version.test in Entity Legal 7.2

Same filename and directory in other branches
  1. 7 tests/entity_legal.version.test

Test for legal document version entity admin ui.

File

tests/entity_legal.version.test
View source
<?php

/**
 * @file
 * Test for legal document version entity admin ui.
 */

/**
 * Simpletest class for document versioning.
 */
class EntityLegalDocumentVersionTestCase extends EntityLegalTestCase {

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return array(
      'name' => 'Legal document version entity',
      'description' => 'Tests admin functionality for the legal document version entity.',
      'group' => 'Entity Legal',
    );
  }

  /**
   * Test the overview page contains a list of entities.
   */
  public function testAdminOverviewUi() {

    // Create a document.
    $document = $this
      ->createDocument();

    // Create 3 documents versions.
    $versions = array();
    for ($i = 0; $i < 3; $i++) {
      $version = $this
        ->createDocumentVersion($document);
      $versions[] = $version;
    }
    $this
      ->drupalLogin($this->adminUser);
    $this
      ->drupalGet('admin/structure/legal/manage/' . $document
      ->identifier());
    foreach ($versions as $version) {
      $this
        ->assertRaw($version
        ->label(), 'Legal document version found on overview page');
      $this
        ->assertLinkByHref('/admin/structure/legal/manage/' . $document
        ->identifier() . '/manage/' . $version
        ->identifier(), 0, 'Edit link for legal document version appears on overview');
    }
  }

  /**
   * Test the functionality of the create form.
   */
  public function testCreateForm() {
    $document = $this
      ->createDocument();
    $test_label = $this
      ->randomName();
    $test_name = $this
      ->randomName();
    $document_text = $this
      ->randomName();
    $acceptance_label = $this
      ->randomName();
    $this
      ->drupalLogin($this->adminUser);
    $this
      ->drupalPost('admin/structure/legal/manage/' . $document
      ->identifier() . '/add', array(
      'label' => $test_label,
      'name' => $test_name,
      'entity_legal_document_text[und][0][value]' => $document_text,
      'acceptance_label' => $acceptance_label,
    ), 'Save');

    // Load a reset version of the entity.
    $created_version = $this
      ->getUncachedEntity(ENTITY_LEGAL_DOCUMENT_VERSION_ENTITY_NAME, $test_name);
    $document = $this
      ->getUncachedEntity(ENTITY_LEGAL_DOCUMENT_ENTITY_NAME, $document
      ->identifier());
    $this
      ->assertTrue(!empty($created_version), 'Document version was successfully created');
    $this
      ->drupalGet('admin/structure/legal/manage/' . $document
      ->identifier());
    $this
      ->assertText($test_label, 'Document version found on document page');
    if ($created_version) {
      $this
        ->assertEqual($test_label, $created_version
        ->label(), 'Label was saved correctly');
      $this
        ->assertEqual($test_name, $created_version
        ->identifier(), 'Name was saved correctly');
      $this
        ->assertEqual($acceptance_label, $created_version->acceptance_label, 'Acceptance label saved correctly');
      $this
        ->assertEqual($document_text, $created_version->entity_legal_document_text[LANGUAGE_NONE][0]['value'], 'Document text is correct');
      $this
        ->assertEqual($document
        ->identifier(), $created_version->document_name, 'Corresponding document is set correctly');
      $this
        ->assertEqual($document->published_version, $created_version
        ->identifier(), 'Published version set on document');
    }
  }

  /**
   * Test the functionality of the edit form.
   */
  public function testEditForm() {
    $document = $this
      ->createDocument();
    $version = $this
      ->createDocumentVersion($document);
    $this
      ->drupalLogin($this->adminUser);
    $this
      ->drupalGet('admin/structure/legal/manage/' . $document
      ->identifier() . '/manage/' . $version
      ->identifier());

    // Test field default values.
    $this
      ->assertFieldByName('label', $version
      ->label(), 'Label is set correctly for version');
    $this
      ->assertFieldByName('entity_legal_document_text[und][0][value]', $version->entity_legal_document_text[LANGUAGE_NONE][0]['value'], 'Document text is set correctly for version');
    $this
      ->assertFieldByName('acceptance_label', $version->acceptance_label, 'Acceptance label is set correctly for version');

    // Test that changing values saves correctly.
    $new_label = $this
      ->randomName();
    $new_text = $this
      ->randomName();
    $new_acceptance_label = $this
      ->randomName();
    $this
      ->drupalPost('admin/structure/legal/manage/' . $document
      ->identifier() . '/manage/' . $version
      ->identifier(), array(
      'label' => $new_label,
      'entity_legal_document_text[und][0][value]' => $new_text,
      'acceptance_label' => $new_acceptance_label,
    ), 'Save');
    $version = $this
      ->getUncachedEntity(ENTITY_LEGAL_DOCUMENT_VERSION_ENTITY_NAME, $version
      ->identifier());
    $this
      ->assertEqual($new_label, $version
      ->label(), 'Label was saved correctly');
    $this
      ->assertEqual($new_text, $version->entity_legal_document_text[LANGUAGE_NONE][0]['value'], 'Document tex was saved correctly');
    $this
      ->assertEqual($new_acceptance_label, $version->acceptance_label, 'Acceptance label was saved correctly');
  }

}

Classes

Namesort descending Description
EntityLegalDocumentVersionTestCase Simpletest class for document versioning.