You are here

trait ParagraphsSetsFunctionalTestTrait in Paragraphs Sets 8.2

Contains functions common to functional paragraphs sets tests.

Hierarchy

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\Traits
View 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

Namesort descending Modifiers Type Description Overrides
ParagraphsSetsFunctionalTestTrait::addNodeType public function Create a node entity bundle (content type).
ParagraphsSetsFunctionalTestTrait::addParagraphRefFieldInNodeType public function Create a paragraph reference field in a given node bundle.
ParagraphsSetsFunctionalTestTrait::addParagraphSet public function Create a paragraphs set.
ParagraphsSetsFunctionalTestTrait::addTextFieldInParagraphType public function Create a text field in a given paragraph bundle.
ParagraphsTestBaseTrait::$workflow protected property The workflow entity.
ParagraphsTestBaseTrait::addFieldtoParagraphType protected function Adds a field to a given paragraph type.
ParagraphsTestBaseTrait::addParagraphedContentType protected function Adds a content type with a Paragraphs field.
ParagraphsTestBaseTrait::addParagraphsField protected function Adds a Paragraphs field to a given entity type.
ParagraphsTestBaseTrait::addParagraphsType protected function Adds a Paragraphs type.
ParagraphsTestBaseTrait::addParagraphsTypeIcon protected function Adds an icon to a paragraphs type.
ParagraphsTestBaseTrait::createEditorialWorkflow protected function Creates a workflow entity.
ParagraphsTestBaseTrait::setParagraphsWidgetSettings protected function Sets some of the settings of a paragraphs field widget.
TestFileCreationTrait::$generatedTestFiles protected property Whether the files were copied to the test files directory.
TestFileCreationTrait::compareFiles protected function Compares two files based on size and file name.
TestFileCreationTrait::generateFile public static function Generates a test file.
TestFileCreationTrait::getTestFiles protected function Gets a list of files that can be used in tests.