RngEventSettingsTest.php in RNG - Events and Registrations 8
File
src/Tests/RngEventSettingsTest.php
View source
<?php
namespace Drupal\rng\Tests;
class RngEventSettingsTest extends RngSiteTestBase {
public static $modules = [
'block',
];
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('local_tasks_block');
$this
->drupalPlaceBlock('local_actions_block');
}
public function testEvent() {
$bundle[0] = $this->event_bundle;
$bundle[1] = $this
->drupalCreateContentType();
$bundle[2] = $this
->drupalCreateContentType();
$event_types[0] = $this->event_type;
$event_types[1] = $this
->createEventType('node', $bundle[2]
->id());
\Drupal::service('router.builder')
->rebuildIfNeeded();
$account = $this
->drupalCreateUser([
'edit own ' . $bundle[0]
->id() . ' content',
'edit own ' . $bundle[1]
->id() . ' content',
]);
$this
->drupalLogin($account);
$entity[0] = $this
->createEntity($bundle[0]);
$entity[1] = $this
->createEntity($bundle[1]);
$base_url = 'node/1';
$this
->drupalGet($base_url);
$this
->assertLinkByHref($base_url . '/event');
$this
->drupalGet($base_url . '/event');
$this
->assertResponse(200);
$base_url = 'node/2';
$this
->drupalGet($base_url);
$this
->assertLinkByHref($base_url);
$this
->assertNoLinkByHref($base_url . '/event');
$this
->drupalGet($base_url . '/event');
$this
->assertResponse(403);
foreach ([
403,
404,
] as $code) {
$event_type = array_shift($event_types);
$event_type
->delete();
\Drupal::service('router.builder')
->rebuildIfNeeded();
foreach ([
'node/1',
'node/2',
] as $base_url) {
$this
->drupalGet($base_url . '/event');
$this
->assertResponse($code);
$this
->drupalGet($base_url);
$this
->assertLinkByHref($base_url);
$this
->assertNoLinkByHref($base_url . '/event');
}
}
}
public function testEventSettingsTabs() {
$account = $this
->drupalCreateUser([
'edit own ' . $this->event_bundle
->id() . ' content',
]);
$this
->drupalLogin($account);
$event = $this
->createEntity($this->event_bundle);
$base_url = 'node/1';
$this
->drupalGet($event
->urlInfo());
$this
->assertLinkByHref($base_url . '/event');
$this
->drupalGet('node/1/event');
$this
->assertLink('Settings');
$this
->assertLinkByHref($base_url . '/event/access');
$this
->assertLinkByHref($base_url . '/event/messages');
$this
->assertLinkByHref($base_url . '/event/groups');
}
public function testEventSettings() {
$bundle = $this->event_bundle
->id();
$account = $this
->drupalCreateUser([
'access content',
'edit own ' . $bundle . ' content',
'rng register self',
]);
$this
->drupalLogin($account);
$this
->createEntity($this->event_bundle, [
'uid' => \Drupal::currentUser()
->id(),
]);
$base_url = 'node/1';
$this
->drupalGet($base_url . '');
$this
->assertResponse(200);
$this
->drupalGet($base_url . '/event');
$this
->assertResponse(200);
$this
->assertNoLinkByHref($base_url . '/register');
$this
->drupalGet($base_url . '/register');
$this
->assertResponse(403);
$edit = [
'rng_status[value]' => TRUE,
'rng_registration_type[' . $this->registration_type
->id() . ']' => TRUE,
'rng_capacity[0][unlimited_number][unlimited_number]' => 'limited',
'rng_capacity[0][unlimited_number][number]' => '1',
];
$this
->drupalPostForm($base_url . '/event', $edit, t('Save'));
$this
->assertRaw(t('Event settings updated.'));
$this
->assertLinkByHref($base_url . '/register');
}
}