You are here

function RngRegistrationTypeTest::testRegistrationTypes in RNG - Events and Registrations 8

Same name and namespace in other branches
  1. 8.2 src/Tests/RngRegistrationTypeTest.php \Drupal\rng\Tests\RngRegistrationTypeTest::testRegistrationTypes()
  2. 3.x src/Tests/RngRegistrationTypeTest.php \Drupal\rng\Tests\RngRegistrationTypeTest::testRegistrationTypes()

Test registration types in UI.

File

src/Tests/RngRegistrationTypeTest.php, line 45

Class

RngRegistrationTypeTest
Tests registration types.

Namespace

Drupal\rng\Tests

Code

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.');
}