class TextProcessedTest
Same name and namespace in other branches
- 11.x core/modules/text/tests/src/Unit/TextProcessedTest.php \Drupal\Tests\text\Unit\TextProcessedTest
Tests TextProcessed with AttachmentsInterface.
Attributes
#[CoversClass(TextProcessed::class)]
#[Group('text')]
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\DrupalTestCaseTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\Tests\RandomGeneratorTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\text\Unit\TextProcessedTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of TextProcessedTest
File
-
core/
modules/ text/ tests/ src/ Unit/ TextProcessedTest.php, line 17
Namespace
Drupal\Tests\text\UnitView source
class TextProcessedTest extends UnitTestCase {
/**
* Tests addAttachments() merges attachments correctly.
*/
public function testAttachments() : void {
$definition = $this->createMock(DataDefinitionInterface::class);
$definition->expects($this->atLeastOnce())
->method('getSetting')
->with('text source')
->willReturn('value');
$parent = $this->createStub(TextItem::class);
$parent->method('__get')
->willReturnMap([
[
'value',
'',
],
[
'format',
'basic_html',
],
]);
$parent->method('getLangcode')
->willReturn('en');
$processed = new TextProcessed($definition, 'formatted_text', $parent);
// Set initial attachments.
$processed->setAttachments([
'library' => [
'core/drupal',
],
]);
// Add more attachments.
$result = $processed->addAttachments([
'library' => [
'core/jquery',
],
'drupalSettings' => [
'foo' => 'bar',
],
]);
$this->assertSame($processed, $result);
$attachments = $processed->getAttachments();
$this->assertContains('core/drupal', $attachments['library']);
$this->assertContains('core/jquery', $attachments['library']);
$this->assertSame([
'foo' => 'bar',
], $attachments['drupalSettings']);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.