RngRegistrationEntityTest.php in RNG - Events and Registrations 3.x
File
tests/src/Kernel/RngRegistrationEntityTest.php
View source
<?php
namespace Drupal\Tests\rng\Kernel;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\rng\Entity\Registrant;
use Drupal\simpletest\UserCreationTrait;
use Drupal\rng\Entity\Registration;
class RngRegistrationEntityTest extends RngKernelTestBase {
use UserCreationTrait {
createUser as drupalCreateUser;
}
public static $modules = [
'system',
'entity_test',
];
protected $eventManager;
protected $registrationType;
protected function setUp() {
parent::setUp();
$this->eventManager = $this->container
->get('rng.event_manager');
$this
->installEntitySchema('entity_test');
$this
->installEntitySchema('registration');
$this
->installEntitySchema('registrant');
$this
->installEntitySchema('rng_rule');
$this
->installEntitySchema('rng_rule_component');
$this
->installEntitySchema('user');
$this
->installConfig('rng');
$this
->installSchema('system', [
'sequences',
]);
$this->registrationType = $this
->createRegistrationType();
$this
->createEventType('entity_test', 'entity_test');
}
public function testSaveRegistrationWithoutEvent() {
$this
->setExpectedException(EntityStorageException::class);
$registration = Registration::create([
'type' => $this->registrationType
->id(),
]);
$registration
->save();
}
public function testAddIdentity() {
$event = $this
->createEvent();
$registration = Registration::create([
'type' => $this->registrationType
->id(),
]);
$registration
->setEvent($event
->getEvent());
$user1 = $this
->drupalCreateUser();
$registration
->addIdentity($user1)
->save();
$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');
}
}