You are here

protected function RequestTestBase::setUp in OpenAPI 8.2

Overrides BrowserTestBase::setUp

File

tests/src/Functional/RequestTestBase.php, line 71

Class

RequestTestBase
Base tests for requests on OpenAPI routes.

Namespace

Drupal\Tests\openapi\Functional

Code

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

  /*
   * @TODO: The below configuration/setup should be shipped as part of the
   * test resources sub module.
   */
  foreach (static::$entityTestBundles['taxonomy_term'] as $bundle) {
    if (!Vocabulary::load($bundle)) {

      // Create a new vocabulary.
      $vocabulary = Vocabulary::create([
        'name' => $bundle,
        'vid' => $bundle,
      ]);
      $vocabulary
        ->save();
    }
  }
  foreach (static::$entityTestBundles['openapi_test_entity'] as $bundle) {
    if (!OpenApiTestEntityType::load($bundle)) {

      // Create a new bundle.
      OpenApiTestEntityType::create([
        'label' => $bundle,
        'id' => $bundle,
      ])
        ->save();
    }
  }
  foreach (array_filter(static::$entityTestBundles) as $entity_type => $bundles) {

    // Add single value and multi value fields.
    FieldStorageConfig::create([
      'entity_type' => $entity_type,
      'field_name' => 'field_test_' . $entity_type,
      'type' => 'text',
    ])
      ->setCardinality(1)
      ->save();
    foreach ($bundles as $bundle) {

      // Add field to each bundle.
      FieldConfig::create([
        'entity_type' => $entity_type,
        'field_name' => 'field_test_' . $entity_type,
        'bundle' => $bundle,
      ])
        ->setLabel('Test field')
        ->setTranslatable(FALSE)
        ->save();
    }
  }
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'access openapi api docs',
    'access content',
  ]));
}