You are here

public function TestFrameworkKernelTest::testRegisterUser in Apigee Edge 8

Tests a more complex scenario.

Registers a user and fetches the "created" developer from the API mocks.

File

tests/src/Kernel/TestFrameworkKernelTest.php, line 215

Class

TestFrameworkKernelTest
Tests the testing framework for testing offline.

Namespace

Drupal\Tests\apigee_edge\Kernel

Code

public function testRegisterUser() {
  if ($this->integration_enabled) {
    $this
      ->markTestSkipped('Integration enabled, skipping test.');
  }

  // Stack up org response.
  $this
    ->addOrganizationMatchedResponse();

  // Run as anonymous user.
  $this
    ->setUpCurrentUser([
    'uid' => 0,
  ]);
  $test_user = [
    'mail' => $this
      ->randomMachineName() . '@example.com',
    'name' => $this
      ->randomMachineName(),
    'first_name' => $this
      ->getRandomGenerator()
      ->word(16),
    'last_name' => $this
      ->getRandomGenerator()
      ->word(16),
  ];
  $form_data = [
    'mail' => $test_user['mail'],
    'name' => $test_user['name'],
    'first_name[0][value]' => $test_user['first_name'],
    'last_name[0][value]' => $test_user['last_name'],
    'op' => 'Create new account',
    'pass' => $this
      ->getRandomGenerator()
      ->word(8),
  ];
  $account = $this->entityTypeManager
    ->getStorage('user')
    ->create($test_user);
  $formObject = $this->entityTypeManager
    ->getFormObject('user', 'register')
    ->setEntity($account);
  $form_state = new FormState();
  $form_state
    ->setUserInput($form_data);
  $form_state
    ->setValues($form_data);
  $this->stack
    ->queueMockResponse('get_not_found');
  $this
    ->queueDeveloperResponse($account);
  \Drupal::formBuilder()
    ->submitForm($formObject, $form_state);
  $developerStorage = $this->entityTypeManager
    ->getStorage('developer');
  $developerStorage
    ->resetCache([
    $test_user['mail'],
  ]);

  /** @var \Drupal\apigee_edge\Entity\Developer $developer */
  $developer = $developerStorage
    ->load($test_user['mail']);
  $this
    ->assertEqual($developer
    ->getEmail(), $test_user['mail']);

  // Attribute is set by mock twig template.
  $this
    ->assertEqual($developer
    ->getAttributeValue('IS_MOCK_CLIENT'), 1);
}