You are here

protected function RequestTest::setUp in OpenAPI 8

Overrides BrowserTestBase::setUp

File

tests/src/Functional/RequestTest.php, line 74

Class

RequestTest
Tests requests 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::ENTITY_TEST_BUNDLES['taxonomy_term'] as $bundle) {
    if (!Vocabulary::load($bundle)) {

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

      // Create a new bundle.
      OpenApiTestEntityType::create([
        'label' => $bundle,
        'id' => $bundle,
      ])
        ->save();
    }
  }
  foreach (array_filter(static::ENTITY_TEST_BUNDLES) 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',
  ]));
}