/**
  * Test registration types in UI.
  */
 function testRegistrationTypes()
 {
     $web_user = $this->drupalCreateUser(['administer registration types', 'access administration pages']);
     $this->drupalLogin($web_user);
     // Create and delete the testing registration type.
     $this->drupalGet('admin/structure/rng/registration_types/manage/' . $this->registration_type->id());
     $this->registration_type->delete();
     // Administration.
     $this->drupalGet('admin/structure');
     $this->assertLinkByHref(Url::fromRoute('rng.registration_type.overview')->toString());
     $this->drupalGet('admin/structure/rng/registration_types');
     $this->assertRaw('No registration types found.', 'Registration type list is empty');
     $this->assertEqual(0, count(RegistrationType::loadMultiple()));
     // Local action.
     $this->assertLinkByHref(Url::fromRoute('entity.registration_type.add')->toString());
     // Add.
     $edit = ['label' => 'Foobar1', 'id' => 'foobar'];
     $this->drupalPostForm('admin/structure/rng/registration_types/add', $edit, t('Save'));
     $this->assertRaw(t('%label registration type was added.', ['%label' => 'Foobar1']));
     $this->assertEqual(1, count(RegistrationType::loadMultiple()));
     // Registration type list.
     $this->assertUrl(Url::fromRoute('rng.registration_type.overview', [], ['absolute' => TRUE])->toString(), []);
     $this->assertRaw('<td>Foobar1</td>', 'New registration type shows in list.');
     // Edit.
     $edit = ['label' => 'Foobar2'];
     $this->drupalPostForm('admin/structure/rng/registration_types/manage/foobar', $edit, t('Save'));
     $this->assertRaw(t('%label registration type was updated.', ['%label' => 'Foobar2']));
     $registration[0] = $this->createRegistration($this->event, 'foobar');
     $registration[1] = $this->createRegistration($this->event, 'foobar');
     $this->drupalGet('admin/structure/rng/registration_types/manage/foobar/delete');
     $this->assertRaw(\Drupal::translation()->formatPlural(count($registration), 'Unable to delete registration type. It is used by @count registration.', 'Unable to delete registration type. It is used by @count registrations.'));
     $registration[0]->delete();
     $registration[1]->delete();
     // No registrations; delete is allowed.
     $this->drupalGet('admin/structure/rng/registration_types/manage/foobar/delete');
     $this->assertRaw(t('This action cannot be undone.'));
     // Delete.
     $this->drupalPostForm('admin/structure/rng/registration_types/manage/foobar/delete', [], t('Delete'));
     $this->assertRaw(t('Registration type %label was deleted.', ['%label' => 'Foobar2']));
     $this->assertEqual(0, count(RegistrationType::loadMultiple()), 'Registration type entity removed from storage.');
 }
 /**
  * Create and save a registration type entity.
  *
  * @return \Drupal\rng\Entity\RegistrationType
  *   A registration type entity
  */
 function createRegistrationType()
 {
     $registration_type = RegistrationType::create(['id' => 'registration_type_a', 'label' => 'Registration Type A', 'description' => 'Description for registration type a']);
     $registration_type->save();
     return $registration_type;
 }