You are here

public function RngRegistrationEntityTest::testAddIdentity in RNG - Events and Registrations 3.x

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/RngRegistrationEntityTest.php \Drupal\Tests\rng\Kernel\RngRegistrationEntityTest::testAddIdentity()
  2. 8 tests/src/Kernel/RngRegistrationEntityTest.php \Drupal\Tests\rng\Kernel\RngRegistrationEntityTest::testAddIdentity()

Test add identity.

@covers ::addIdentity

File

tests/src/Kernel/RngRegistrationEntityTest.php, line 78

Class

RngRegistrationEntityTest
Tests registration entities.

Namespace

Drupal\Tests\rng\Kernel

Code

public function testAddIdentity() {
  $event = $this
    ->createEvent();
  $registration = Registration::create([
    'type' => $this->registrationType
      ->id(),
  ]);
  $registration
    ->setEvent($event
    ->getEvent());
  $user1 = $this
    ->drupalCreateUser();
  $registration
    ->addIdentity($user1)
    ->save();

  /** @var \Drupal\rng\RegistrantInterface[] $registrants */
  $registrants = Registrant::loadMultiple();
  $this
    ->assertEquals(1, count($registrants), 'There is one registrant');
  $registrant = reset($registrants);
  $this
    ->assertEquals($registration
    ->id(), $registrant
    ->getRegistration()
    ->id(), 'Registrant belongs to registration.');
  $this
    ->assertEquals(get_class($user1), get_class($registrant
    ->getIdentity()), 'Identity class is same');
  $this
    ->assertEquals($user1
    ->getEntityTypeId(), $registrant
    ->getIdentity()
    ->getEntityTypeId(), 'Identity entity type is same');
  $this
    ->assertEquals($user1
    ->id(), $registrant
    ->getIdentity()
    ->id(), 'Identity ID is same');
}