You are here

public function ApigeeEdgeManagementCliServiceTest::testCreateEdgeRoleForDrupalWhenRoleExistsTestWithForceFlag in Apigee Edge 8

Allow role to get modified w/force option.

File

tests/src/Unit/Command/Util/ApigeeEdgeManagementCliServiceTest.php, line 186

Class

ApigeeEdgeManagementCliServiceTest
Test ApigeeEdgeManagementCliService.

Namespace

Drupal\Tests\apigee_edge\Unit\Command\Util

Code

public function testCreateEdgeRoleForDrupalWhenRoleExistsTestWithForceFlag() {

  // Expected to output error if role does not exist.
  $io = $this
    ->prophesize(StyleInterface::class);
  $io
    ->success(Argument::exact('Connected to Edge org ' . $this->org . '.'))
    ->shouldBeCalledTimes(1);
  $io
    ->text(Argument::containingString('Setting permissions on role ' . $this->roleName . '.'))
    ->shouldBeCalledTimes(1);
  $io
    ->text(Argument::containingString('/'))
    ->shouldBeCalledTimes(12);
  $io
    ->success(Argument::containingString('Role ' . $this->roleName . ' is configured.'))
    ->shouldBeCalledTimes(1);

  // Return organization info.
  $response_org = $this
    ->prophesize(Response::class);
  $response_org
    ->getBody()
    ->shouldBeCalledTimes(1)
    ->willReturn('{ "name": "' . $this->org . '" }');
  $this->httpClient
    ->get(Argument::exact($this->baseUrl . '/o/' . $this->org), Argument::type('array'))
    ->shouldBeCalledTimes(1)
    ->willReturn($response_org
    ->reveal());

  // Return existing role.
  $response_user_role = $this
    ->prophesize(Response::class);
  $response_user_role
    ->getBody()
    ->willReturn('{ "name": "' . $this->roleName . '" }');
  $this->httpClient
    ->get(Argument::exact($this->baseUrl . '/o/' . $this->org . '/userroles/' . $this->roleName), Argument::type('array'))
    ->willReturn($response_user_role
    ->reveal());

  // The role should NOT be created since is already exists.
  $this->httpClient
    ->post(Argument::exact($this->baseUrl . '/o/' . $this->org . '/userroles'), Argument::type('array'))
    ->shouldNotBeCalled();

  // The permissions should be set.
  $this->httpClient
    ->post(Argument::exact($this->baseUrl . '/o/' . $this->org . '/userroles/' . $this->roleName . '/permissions'), Argument::type('array'))
    ->shouldBeCalledTimes(12);
  $apigee_edge_management_cli_service = new ApigeeEdgeManagementCliService($this->httpClient
    ->reveal());
  $apigee_edge_management_cli_service
    ->createEdgeRoleForDrupal($io
    ->reveal(), [
    $this,
    'mockDt',
  ], $this->org, $this->email, $this->password, $this->baseUrl, $this->roleName, TRUE);
}