You are here

public function CreateTest::createAccountPerEntity in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/rest/src/Tests/CreateTest.php \Drupal\rest\Tests\CreateTest::createAccountPerEntity()

Creates user accounts that have the required permissions to create resources via the REST API. The second one has administrative permissions.

Parameters

string $entity_type: Entity type needed to apply user permissions.

Return value

array An array that contains user accounts.

4 calls to CreateTest::createAccountPerEntity()
CreateTest::testCreateComment in core/modules/rest/src/Tests/CreateTest.php
Test comment creation.
CreateTest::testCreateEntityTest in core/modules/rest/src/Tests/CreateTest.php
Tests valid and invalid create requests for 'entity_test' entity type.
CreateTest::testCreateNode in core/modules/rest/src/Tests/CreateTest.php
Tests several valid and invalid create requests for 'node' entity type.
CreateTest::testCreateUser in core/modules/rest/src/Tests/CreateTest.php
Tests several valid and invalid create requests for 'user' entity type.

File

core/modules/rest/src/Tests/CreateTest.php, line 335
Contains \Drupal\rest\Tests\CreateTest.

Class

CreateTest
Tests the creation of resources.

Namespace

Drupal\rest\Tests

Code

public function createAccountPerEntity($entity_type) {
  $accounts = array();

  // Get the necessary user permissions for the current $entity_type creation.
  $permissions = $this
    ->entityPermissions($entity_type, 'create');

  // POST method must be allowed for the current entity type.
  $permissions[] = 'restful post entity:' . $entity_type;

  // Create user without administrative permissions.
  $accounts[] = $this
    ->drupalCreateUser($permissions);

  // Add administrative permissions for nodes and users.
  $permissions[] = 'administer nodes';
  $permissions[] = 'administer users';
  $permissions[] = 'administer comments';

  // Create an administrative user.
  $accounts[] = $this
    ->drupalCreateUser($permissions);
  return $accounts;
}