You are here

public function EntityLegalDocumentVersionTest::testCreateForm in Entity Legal 3.0.x

Same name and namespace in other branches
  1. 8.2 src/Tests/EntityLegalDocumentVersionTest.php \Drupal\entity_legal\Tests\EntityLegalDocumentVersionTest::testCreateForm()
  2. 4.0.x src/Tests/EntityLegalDocumentVersionTest.php \Drupal\entity_legal\Tests\EntityLegalDocumentVersionTest::testCreateForm()

Test the functionality of the create form.

File

src/Tests/EntityLegalDocumentVersionTest.php, line 38

Class

EntityLegalDocumentVersionTest
Tests admin functionality for the legal document version entity.

Namespace

Drupal\entity_legal\Tests

Code

public function testCreateForm() {
  $document = $this
    ->createDocument();
  $test_label = $this
    ->randomMachineName();
  $document_text = $this
    ->randomMachineName();
  $acceptance_label = $this
    ->randomMachineName();
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalPostForm('admin/structure/legal/manage/' . $document
    ->id() . '/add', [
    'label' => $test_label,
    'entity_legal_document_text[0][value]' => $document_text,
    'acceptance_label' => $acceptance_label,
  ], 'Save');

  // Load a reset version of the entity.

  /** @var \Drupal\entity_legal\EntityLegalDocumentInterface $document */
  $document = $this
    ->getUncachedEntity(ENTITY_LEGAL_DOCUMENT_ENTITY_NAME, $document
    ->id());
  $versions = $document
    ->getAllVersions();

  /** @var \Drupal\entity_legal\EntityLegalDocumentVersionInterface $created_version */
  $created_version = reset($versions);
  $this
    ->assertTrue(!empty($created_version), 'Document version was successfully created');
  $this
    ->drupalGet('admin/structure/legal/manage/' . $document
    ->id());
  $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($acceptance_label, $created_version
      ->get('acceptance_label')->value, 'Acceptance label saved correctly');
    $this
      ->assertEqual($document_text, $created_version
      ->get('entity_legal_document_text')[0]->value, 'Document text is correct');
    $this
      ->assertEqual($document
      ->id(), $created_version
      ->bundle(), 'Corresponding document is set correctly');
    $this
      ->assertEqual($document
      ->getPublishedVersion()
      ->id(), $created_version
      ->id(), 'Published version set on document');
  }
}