class TextSummaryTest
Same name in this branch
- 11.x core/modules/text/tests/src/Kernel/TextSummaryTest.php \Drupal\Tests\text\Kernel\TextSummaryTest
Same name and namespace in other branches
- 10 core/modules/text/tests/src/Kernel/TextSummaryTest.php \Drupal\Tests\text\Kernel\TextSummaryTest
- 9 core/modules/text/tests/src/Kernel/TextSummaryTest.php \Drupal\Tests\text\Kernel\TextSummaryTest
- 8.9.x core/modules/text/tests/src/Kernel/TextSummaryTest.php \Drupal\Tests\text\Kernel\TextSummaryTest
- main core/modules/text/tests/src/Kernel/TextSummaryTest.php \Drupal\Tests\text\Kernel\TextSummaryTest
Tests text_summary() with different strings and lengths.
Attributes
#[Group('text_with_summary')]
#[IgnoreDeprecations]
#[RunTestsInSeparateProcesses]
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\BrowserHtmlDebugTrait, \Drupal\Tests\HttpKernelUiHelperTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\text_with_summary\Kernel\TextSummaryTest uses \Drupal\Tests\user\Traits\UserCreationTrait extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of TextSummaryTest
File
-
core/
modules/ text_with_summary/ tests/ src/ Kernel/ TextSummaryTest.php, line 20
Namespace
Drupal\Tests\text_with_summary\KernelView source
class TextSummaryTest extends KernelTestBase {
use UserCreationTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'system',
'user',
'filter',
'text_with_summary',
'text',
'field',
'entity_test',
];
/**
* Tests required summary.
*/
public function testRequiredSummary() : void {
$this->installEntitySchema('user');
$this->installEntitySchema('entity_test');
$this->setUpCurrentUser();
$field_definition = FieldStorageConfig::create([
'field_name' => 'test_text_with_summary',
'type' => 'text_with_summary',
'entity_type' => 'entity_test',
'cardinality' => 1,
'settings' => [
'max_length' => 200,
],
]);
$field_definition->save();
$instance = FieldConfig::create([
'field_name' => 'test_text_with_summary',
'label' => 'A text field',
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
'settings' => [
'text_processing' => TRUE,
'display_summary' => TRUE,
'required_summary' => TRUE,
],
]);
$instance->save();
EntityFormDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
'status' => TRUE,
])->setComponent('test_text_with_summary', [
'type' => 'text_textarea_with_summary',
'settings' => [
'summary_rows' => 2,
'show_summary' => TRUE,
],
])
->save();
// Check the required summary.
$entity = EntityTest::create([
'name' => $this->randomMachineName(),
'type' => 'entity_test',
'test_text_with_summary' => [
'value' => $this->randomMachineName(),
],
]);
$form = \Drupal::service('entity.form_builder')->getForm($entity);
$this->assertNotEmpty($form['test_text_with_summary']['widget'][0]['summary'], 'Summary field is shown');
$this->assertNotEmpty($form['test_text_with_summary']['widget'][0]['summary']['#required'], 'Summary field is required');
// Test validation.
/** @var \Symfony\Component\Validator\ConstraintViolation[] $violations */
$violations = $entity->validate();
$this->assertCount(1, $violations);
$this->assertEquals('test_text_with_summary.0.summary', $violations[0]->getPropertyPath());
$this->assertEquals('The summary field is required for A text field', $violations[0]->getMessage());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.