You are here

protected function RngRegistrantRouteTest::setUp in RNG - Events and Registrations 8.2

Same name and namespace in other branches
  1. 8 src/Tests/RngRegistrantRouteTest.php \Drupal\rng\Tests\RngRegistrantRouteTest::setUp()
  2. 3.x src/Tests/RngRegistrantRouteTest.php \Drupal\rng\Tests\RngRegistrantRouteTest::setUp()

Overrides RngWebTestBase::setUp

File

src/Tests/RngRegistrantRouteTest.php, line 54

Class

RngRegistrantRouteTest
Tests registrant routes.

Namespace

Drupal\rng\Tests

Code

protected function setUp() {
  parent::setUp();
  $this
    ->drupalPlaceBlock('page_title_block');
  $this
    ->drupalPlaceBlock('system_breadcrumb_block');
  $this->eventType = $this
    ->createEventType('entity_test', 'entity_test');
  $this->registrationType = $this
    ->createRegistrationType();
  $event_name = $this
    ->randomString();
  $event_meta = $this
    ->createEvent([
    'name' => $event_name,
  ]);
  $registration = $this
    ->createRegistration($event_meta
    ->getEvent(), $this->registrationType
    ->id());
  $user = $this
    ->drupalCreateUser();
  $registration
    ->addIdentity($user)
    ->save();
  $registrant_ids = $registration
    ->getRegistrantIds();
  $registrant_id = reset($registrant_ids);
  $this->registrant = Registrant::load($registrant_id);
  $field_name = Unicode::strtolower($this
    ->randomMachineName());
  FieldStorageConfig::create([
    'field_name' => $field_name,
    'entity_type' => 'registrant',
    'type' => 'string',
  ])
    ->save();
  FieldConfig::create([
    'field_name' => $field_name,
    'entity_type' => 'registrant',
    'bundle' => 'registrant',
  ])
    ->save();
  $form_display = entity_get_form_display('registrant', 'registrant', 'default');
  $form_display
    ->setComponent($field_name, [
    'type' => 'text_textfield',
    'weight' => 1,
  ]);
  $form_display
    ->save();
  $display = entity_get_display('registrant', 'registrant', 'default');
  $display
    ->setComponent($field_name, [
    'type' => 'text_default',
    'weight' => 1,
  ]);
  $display
    ->save();
  $this->registrant->{$field_name} = $this
    ->randomMachineName();
  $this->registrant
    ->save();
  $this->registrantTestField = $field_name;
}