class RegistrationAPITestCase in Entity Registration 8.2
Same name in this branch
- 8.2 tests/registration.test \RegistrationAPITestCase
- 8.2 src/RegistrationAPITestCase.php \Drupal\registration\RegistrationAPITestCase
Hierarchy
- class \Drupal\registration\RegistrationTestCase extends \Drupal\registration\DrupalWebTestCase
- class \Drupal\registration\RegistrationAPITestCase
Expanded class hierarchy of RegistrationAPITestCase
File
- src/
RegistrationAPITestCase.php, line 4
Namespace
Drupal\registrationView source
class RegistrationAPITestCase extends RegistrationTestCase {
public static function getInfo() {
return array(
'name' => 'Registration API',
'description' => 'Test hooks provided by Registration.',
'group' => 'Registration',
);
}
function setUp() {
parent::setUp(array(
'registration_test_api',
));
$this
->setUpEntity();
}
/**
* Test hook_registration_access().
*/
function testHookAccess() {
$account = $this
->drupalCreateUser();
$crud = array(
'create',
'view',
'update',
'delete',
);
$registration_values = array(
'registrant_id' => $account->uid,
);
// Test hook.
$registration = $this
->createRegistration($registration_values);
$random = $this
->randomString();
$registration->hook_registration_access = $random;
$this
->assertEqual($random, \Drupal::moduleHandler()
->invoke('registration_test_api', 'registration_access', [
'view',
$registration,
$account,
]), t('Manually invoke hook_registration_access()'), 'Registration');
// Default access (none).
foreach ($crud as $op) {
$registration = $this
->createRegistration();
$this
->assertFalse(entity_access($op, 'registration', $registration, $account), t('User cannot @op registration.', array(
'@op' => $op,
)), 'Registration');
}
// Force allow access.
foreach ($crud as $op) {
$registration = $this
->createRegistration($registration_values);
$registration->hook_registration_access = TRUE;
$this
->assertTrue(entity_access($op, 'registration', $registration, $account), t('User can @op registration.', array(
'@op' => $op,
)), 'Registration');
}
}
/**
* Test hook_registration_status().
*/
function testHookStatus() {
// Testing host status, no hook.
$this
->setHostEntitySettings(array(
'status' => 1,
));
$this
->assertTrue(registration_status($this->host_entity_type, $this->host_entity_id, TRUE), t('Host entity status is open.'), 'Registration');
// Host main status is opened, hook closes.
\Drupal::configFactory()
->getEditable('registration.settings')
->set('registration_test_api_registration_status_alter', FALSE)
->save();
$this
->assertFalse(registration_status($this->host_entity_type, $this->host_entity_id, TRUE), t('Host entity status is open, hook overrides'), 'Registration');
// Hook should still be invoked if main status is closed.
$this
->setHostEntitySettings(array(
'status' => 0,
));
\Drupal::configFactory()
->getEditable('registration.settings')
->set('registration_test_api_registration_status_alter', TRUE)
->save();
$this
->assertTrue(registration_status($this->host_entity_type, $this->host_entity_id, TRUE), t('Host entity status is closed, hook overrides.'), 'Registration');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RegistrationAPITestCase:: |
public static | function | ||
RegistrationAPITestCase:: |
function | |||
RegistrationAPITestCase:: |
function | Test hook_registration_access(). | ||
RegistrationAPITestCase:: |
function | Test hook_registration_status(). | ||
RegistrationTestCase:: |
function | Create a Registration programmatically. | ||
RegistrationTestCase:: |
function | |||
RegistrationTestCase:: |
function | Loads a registration from the database, avoiding the cache. | ||
RegistrationTestCase:: |
function | Reset session cache of registration entities. | ||
RegistrationTestCase:: |
function | |||
RegistrationTestCase:: |
function |