DocumentTest.php in Entity Legal 8.2
File
tests/src/Kernel/DocumentTest.php
View source
<?php
namespace Drupal\Tests\entity_legal\Kernel;
use Drupal\entity_legal\Controller\EntityLegalController;
use Drupal\entity_legal\Entity\EntityLegalDocument;
use Drupal\entity_legal\Entity\EntityLegalDocumentVersion;
use Drupal\KernelTests\KernelTestBase;
class DocumentTest extends KernelTestBase {
public static $modules = [
'entity_legal',
'field',
'system',
'text',
];
public function testTitleCallback() {
$class_resolver = $this->container
->get('class_resolver');
$this
->installConfig([
'entity_legal',
]);
$this
->installEntitySchema(ENTITY_LEGAL_DOCUMENT_VERSION_ENTITY_NAME);
$controller = $class_resolver
->getInstanceFromDefinition(EntityLegalController::class);
$document = EntityLegalDocument::create([
'id' => 'legal_notice',
'label' => 'Legal notice',
]);
$document
->save();
$version = EntityLegalDocumentVersion::create([
'document_name' => $document
->id(),
'label' => 'v1.0.0',
]);
$version
->save();
$document
->setPublishedVersion($version);
$settings = $document
->get('settings');
$title = $controller
->documentPageTitle($document);
$this
->assertEquals('Legal notice', $title);
$settings['title_pattern'] = '[entity_legal_document:label] (version [entity_legal_document:published-version:label])';
$document
->set('settings', $settings)
->save();
$title = $controller
->documentPageTitle($document);
$this
->assertEquals('Legal notice (version v1.0.0)', $title);
}
}