trait ParagraphsSetsFunctionalTestTrait in Paragraphs Sets 8.2
Contains functions common to functional paragraphs sets tests.
Hierarchy
- trait \Drupal\Tests\paragraphs_sets\Traits\ParagraphsSetsFunctionalTestTrait uses ParagraphsTestBaseTrait
1 file declares its use of ParagraphsSetsFunctionalTestTrait
- ParagraphSetBasicFunctionality.php in tests/
src/ Functional/ ParagraphSetBasicFunctionality.php
File
- tests/
src/ Traits/ ParagraphsSetsFunctionalTestTrait.php, line 12
Namespace
Drupal\Tests\paragraphs_sets\TraitsView source
trait ParagraphsSetsFunctionalTestTrait {
use ParagraphsTestBaseTrait;
/**
* Create a node entity bundle (content type).
*
* @param string $nodeType
* The machine name for the node type.
*/
public function addNodeType(string $nodeType) {
$this
->drupalCreateContentType([
'type' => $nodeType,
'name' => $nodeType,
]);
}
/**
* Create a paragraph reference field in a given node bundle.
*
* @param string $paragraphRefFieldName
* The machine name for the paragraph reference field.
* @param string $nodeType
* The machine name for the node type.
*/
public function addParagraphRefFieldInNodeType(string $paragraphRefFieldName, string $nodeType) {
$this
->addParagraphsField($nodeType, $paragraphRefFieldName, 'node', 'paragraphs');
/** @var \Drupal\Core\Entity\Entity\EntityFormDisplay $formDisplay */
$formDisplay = \Drupal::service('entity_display.repository')
->getFormDisplay('node', $nodeType);
$displaySettings = $formDisplay
->getComponent($paragraphRefFieldName);
$displaySettings['third_party_settings']['paragraphs_sets']['paragraphs_sets']['use_paragraphs_sets'] = 1;
$formDisplay
->setComponent($paragraphRefFieldName, $displaySettings);
$formDisplay
->save();
}
/**
* Create a text field in a given paragraph bundle.
*
* @param string $textFieldName
* The machine name for the text field.
* @param string $paragraphType
* The machine name for the paragraph type.
*/
public function addTextFieldInParagraphType(string $textFieldName, string $paragraphType) {
$this
->addFieldtoParagraphType($paragraphType, $textFieldName, 'string', []);
}
/**
* Create a paragraphs set.
*
* @param string $paragraphSet
* The machine name for the new paragraphs set.
* @param string $config
* Configuration for the new paragraphs set. Defaults to an empty set.
*/
public function addParagraphSet(string $paragraphSet, string $config = 'paragraphs: []') {
$decodedConfig = Yaml::decode($config);
$paragraphsSet = ParagraphsSet::create([
'id' => $paragraphSet,
'label' => $paragraphSet,
'description' => $paragraphSet,
'paragraphs' => $decodedConfig['paragraphs'],
]);
$paragraphsSet
->save();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ParagraphsSetsFunctionalTestTrait:: |
public | function | Create a node entity bundle (content type). | |
ParagraphsSetsFunctionalTestTrait:: |
public | function | Create a paragraph reference field in a given node bundle. | |
ParagraphsSetsFunctionalTestTrait:: |
public | function | Create a paragraphs set. | |
ParagraphsSetsFunctionalTestTrait:: |
public | function | Create a text field in a given paragraph bundle. | |
ParagraphsTestBaseTrait:: |
protected | property | The workflow entity. | |
ParagraphsTestBaseTrait:: |
protected | function | Adds a field to a given paragraph type. | |
ParagraphsTestBaseTrait:: |
protected | function | Adds a content type with a Paragraphs field. | |
ParagraphsTestBaseTrait:: |
protected | function | Adds a Paragraphs field to a given entity type. | |
ParagraphsTestBaseTrait:: |
protected | function | Adds a Paragraphs type. | |
ParagraphsTestBaseTrait:: |
protected | function | Adds an icon to a paragraphs type. | |
ParagraphsTestBaseTrait:: |
protected | function | Creates a workflow entity. | |
ParagraphsTestBaseTrait:: |
protected | function | Sets some of the settings of a paragraphs field widget. | |
TestFileCreationTrait:: |
protected | property | Whether the files were copied to the test files directory. | |
TestFileCreationTrait:: |
protected | function | Compares two files based on size and file name. | |
TestFileCreationTrait:: |
public static | function | Generates a test file. | |
TestFileCreationTrait:: |
protected | function | Gets a list of files that can be used in tests. |