You are here

protected function EntitySelectWidgetTest::setUp in Commerce Core 8.2

Overrides CommerceBrowserTestBase::setUp

File

tests/src/Functional/EntitySelectWidgetTest.php, line 60

Class

EntitySelectWidgetTest
Tests the Entity select widget.

Namespace

Drupal\Tests\commerce\Functional

Code

protected function setUp() : void {
  parent::setUp();
  $this
    ->drupalCreateContentType([
    'type' => 'article',
    'name' => 'Article',
  ]);
  $field_storage = FieldStorageConfig::create([
    'field_name' => 'stores',
    'entity_type' => 'node',
    'type' => 'entity_reference',
    'settings' => [
      'target_type' => 'commerce_store',
    ],
    'cardinality' => FieldStorageConfig::CARDINALITY_UNLIMITED,
  ]);
  $field_storage
    ->save();
  $field = FieldConfig::create([
    'field_storage' => $field_storage,
    'label' => 'Stores',
    'bundle' => 'article',
    'required' => TRUE,
  ]);
  $field
    ->save();
  $display = commerce_get_entity_display('node', 'article', 'form');
  $display
    ->setComponent('stores', [
    'type' => 'commerce_entity_select',
    'settings' => [
      'autocomplete_threshold' => 2,
    ],
  ])
    ->save();
  $this->referenceField = $field_storage;
  $this->node = $this
    ->createEntity('node', [
    'type' => 'article',
    'title' => $this
      ->randomMachineName(),
  ]);

  // Set the first store.
  $this->stores[] = $this->store;
}