You are here

function RegistrationStandardTestCase::testHostRegistrationStatus in Entity Registration 7

Same name and namespace in other branches
  1. 8.2 tests/registration.test \RegistrationStandardTestCase::testHostRegistrationStatus()
  2. 7.2 tests/registration.test \RegistrationStandardTestCase::testHostRegistrationStatus()

Check internal status modifiers.

Capacity, opening, and closing dates.

File

tests/registration.test, line 284
Tests for the Registration module

Class

RegistrationStandardTestCase
Creates a registration type Create node entity type ensure registration type exists

Code

function testHostRegistrationStatus() {
  global $user;
  $permissions = array(
    'create ' . $this->registration_type_name . ' registration',
  );
  $this
    ->checkPermissions($permissions, TRUE);
  $basic_user = $this
    ->drupalCreateUser($permissions);
  $permissions = array(
    'administer ' . $this->registration_type_name . ' registration',
  );
  $this
    ->checkPermissions($permissions, TRUE);
  $admin_user = $this
    ->drupalCreateUser($permissions);

  // Start with the basic user.
  $user = $basic_user;
  $this
    ->assertFalse(registration_status($this->host_entity_type, $this->host_entity_id, TRUE), t('Default host entity status is closed.'), 'Registration');
  $this
    ->setHostEntitySettings(array(
    'status' => 1,
    'capacity' => 10,
  ));
  $this
    ->assertTrue(registration_status($this->host_entity_type, $this->host_entity_id, TRUE), t('Host entity main status is opened.'), 'Registration');

  // Fill capacity.
  $registrations = array();
  for ($i = 0; $i < 5; $i++) {
    $registrations[$i] = $this
      ->createRegistration(array(
      'count' => 2,
    ));
  }
  $this
    ->assertFalse(registration_status($this->host_entity_type, $this->host_entity_id, TRUE), t('Host entity status is closed, filled with registrations.'), 'Registration');

  // Unfill capacity by one registration.
  entity_delete('registration', end($registrations)->registration_id);
  $this
    ->assertTrue(registration_status($this->host_entity_type, $this->host_entity_id, TRUE), t('Deleted a registration, capacity now not at maximum.'), 'Registration');

  // Test dates.
  $this
    ->setHostEntitySettings(array(
    'status' => 1,
    'open' => date('Y-m-d H:i:s', time() + 3600),
    'close' => NULL,
  ));
  $this
    ->assertFalse(registration_status($this->host_entity_type, $this->host_entity_id, TRUE), t('Host entity status is closed, open time has not passed.'), 'Registration');
  $this
    ->setHostEntitySettings(array(
    'status' => 1,
    'open' => date('Y-m-d H:i:s', time() - 3600),
    'close' => date('Y-m-d H:i:s', time() + 3600),
  ));
  $this
    ->assertTrue(registration_status($this->host_entity_type, $this->host_entity_id, TRUE), t('Host entity status is open, in between open and closing times.'), 'Registration');
  $this
    ->setHostEntitySettings(array(
    'status' => 1,
    'open' => NULL,
    'close' => date('Y-m-d H:i:s', time() - 3600),
  ));
  $this
    ->assertFalse(registration_status($this->host_entity_type, $this->host_entity_id, TRUE), t('Host entity status is closed, closing time has passed.'), 'Registration');
}