You are here

protected function EntityCrudTest::setUp in Lightning API 8

Same name and namespace in other branches
  1. 8.2 modules/api_test/tests/src/Functional/EntityCrudTest.php \Drupal\Tests\api_test\Functional\EntityCrudTest::setUp()

Overrides ApiTestBase::setUp

File

modules/api_test/tests/src/Functional/EntityCrudTest.php, line 30

Class

EntityCrudTest
Tests the ability to Create, Read, and Update config and config entities via the API.

Namespace

Drupal\Tests\api_test\Functional

Code

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

  // Create an admin user that has permission to do everything for testing.

  /** @var \Drupal\user\UserInterface $account */
  $account = User::create([
    'name' => 'api-admin-user',
    'mail' => 'api-admin-user@example.com',
    'pass' => 'admin',
  ]);
  $account
    ->addRole('administrator');
  $account
    ->activate()
    ->save();

  // Create an associated OAuth client to use for testing.
  $client = Consumer::create([
    'label' => 'API Test Admin Client',
    'secret' => 'oursecret',
    'confidential' => 1,
    'user_id' => $account
      ->id(),
    'roles' => 'administrator',
  ]);
  $client
    ->save();

  // Retrieve and store a token to use in the requests.
  $admin_client_options = [
    'form_params' => [
      'grant_type' => 'password',
      'client_id' => $client
        ->uuid(),
      'client_secret' => 'oursecret',
      'username' => $account
        ->getAccountName(),
      'password' => 'admin',
    ],
  ];
  $this->token = $this
    ->getToken($admin_client_options);
}