You are here

protected function FreelinkingPrepopulateTest::setUp in Freelinking 4.0.x

Same name in this branch
  1. 4.0.x modules/freelinking_prepopulate/tests/src/Functional/FreelinkingPrepopulateTest.php \Drupal\Tests\freelinking_prepopulate\Functional\FreelinkingPrepopulateTest::setUp()
  2. 4.0.x modules/freelinking_prepopulate/tests/src/Unit/Plugin/freelinking/FreelinkingPrepopulateTest.php \Drupal\Tests\freelinking_prepopulate\Unit\Plugin\freelinking\FreelinkingPrepopulateTest::setUp()
Same name and namespace in other branches
  1. 8.3 modules/freelinking_prepopulate/tests/src/Functional/FreelinkingPrepopulateTest.php \Drupal\Tests\freelinking_prepopulate\Functional\FreelinkingPrepopulateTest::setUp()

Overrides FreelinkingBrowserTestBase::setUp

File

modules/freelinking_prepopulate/tests/src/Functional/FreelinkingPrepopulateTest.php, line 37

Class

FreelinkingPrepopulateTest
Tests embedded prepopulate links.

Namespace

Drupal\Tests\freelinking_prepopulate\Functional

Code

protected function setUp() : void {
  parent::setUp();

  // Creates a content type to act as default prepopulate content type.
  $this
    ->createContentType([
    'name' => 'Person',
    'type' => 'person',
  ]);
  $vocabulary = $this
    ->createVocabulary();

  // Creates a basic text field.
  FieldStorageConfig::create([
    'field_name' => 'field_basic',
    'entity_type' => 'node',
    'type' => 'text',
  ])
    ->save();
  FieldConfig::create([
    'field_name' => 'field_basic',
    'entity_type' => 'node',
    'bundle' => 'person',
    'label' => 'Basic',
  ])
    ->save();

  // Creates a taxonomy_term entity_reference field.
  FieldStorageConfig::create([
    'field_name' => 'field_tags',
    'entity_type' => 'node',
    'type' => 'entity_reference',
    'settings' => [
      'target_type' => 'taxonomy_term',
    ],
  ])
    ->save();
  FieldConfig::create([
    'field_name' => 'field_tags',
    'entity_type' => 'node',
    'bundle' => 'person',
    'label' => $vocabulary
      ->label(),
    'settings' => [
      'handler' => 'default:taxonomy_term',
      'handler_settings' => [
        'target_bundles' => [
          $vocabulary
            ->id() => $vocabulary
            ->id(),
        ],
        'sort' => [
          'field' => '_none',
        ],
      ],
      'auto_create' => TRUE,
    ],
  ])
    ->save();
  $formDisplay = EntityFormDisplay::load('node.person.default');
  $formDisplay
    ->setComponent('field_basic', [
    'type' => 'string_textfield',
  ]);
  $formDisplay
    ->setComponent('field_tags', [
    'type' => 'entity_reference_autocomplete_tags',
  ]);
  $formDisplay
    ->save();
  $prefix = 'filters[freelinking][settings][plugins][freelinking_prepopulate]';
  $filter_settings = [
    'filters[freelinking][status]' => 1,
    'filters[freelinking][weight]' => 0,
    $prefix . '[enabled]' => 1,
    $prefix . '[settings][failover]' => 'error',
    $prefix . '[settings][default_node_type]' => 'person',
    'filters[filter_url][weight]' => 1,
    'filters[filter_html][weight]' => 2,
    'filters[filter_autop][weight]' => 3,
    'filters[filter_htmlcorrector][weight]' => 4,
  ];
  $this
    ->updateFilterSettings('plain_text', $filter_settings);
}