protected function EntityLegalTestTrait::createDocumentVersion in Entity Legal 3.0.x
Same name and namespace in other branches
- 8.2 tests/src/Traits/EntityLegalTestTrait.php \Drupal\Tests\entity_legal\Traits\EntityLegalTestTrait::createDocumentVersion()
- 4.0.x tests/src/Traits/EntityLegalTestTrait.php \Drupal\Tests\entity_legal\Traits\EntityLegalTestTrait::createDocumentVersion()
Creates a document version.
Parameters
\Drupal\entity_legal\EntityLegalDocumentInterface $document: The document to add the version to.
bool $save_as_default: Whether to save the version as the default for the document.
Return value
\Drupal\entity_legal\EntityLegalDocumentVersionInterface The created legal document version.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
\Drupal\Core\Entity\EntityStorageException
9 calls to EntityLegalTestTrait::createDocumentVersion()
- EntityLegalDocumentAcceptanceTest::testSubmissionForm in src/
Tests/ EntityLegalDocumentAcceptanceTest.php - Test that user has the ability to agree to legal documents.
- EntityLegalDocumentVersionTest::testAdminOverviewUi in src/
Tests/ EntityLegalDocumentVersionTest.php - Test the overview page contains a list of entities.
- EntityLegalDocumentVersionTest::testEditForm in src/
Tests/ EntityLegalDocumentVersionTest.php - Test the functionality of the edit form.
- EntityLegalMethodsTest::testMessageMethod in src/
Tests/ EntityLegalMethodsTest.php - Drupal message method test.
- EntityLegalMethodsTest::testPopupMethod in src/
Tests/ EntityLegalMethodsTest.php - JQuery UI dialog method test.
File
- tests/
src/ Traits/ EntityLegalTestTrait.php, line 66
Class
- EntityLegalTestTrait
- Code reusing for Entity Legal tests.
Namespace
Drupal\Tests\entity_legal\TraitsCode
protected function createDocumentVersion(EntityLegalDocumentInterface $document, $save_as_default = FALSE) {
/** @var \Drupal\entity_legal\EntityLegalDocumentVersionInterface $entity */
$entity = \Drupal::entityTypeManager()
->getStorage('entity_legal_document_version')
->create([
'label' => $this
->randomMachineName(),
'name' => $this
->randomMachineName(64),
'document_name' => $document
->id(),
'acceptance_label' => 'I agree to the <a href="[entity_legal_document:url]">document</a>',
'entity_legal_document_text' => [
[
'value' => $this
->randomMachineName(),
],
],
]);
$entity
->save();
if ($save_as_default) {
$document
->setPublishedVersion($entity);
$document
->save();
}
return $entity;
}