View source
<?php
namespace Drupal\rng\Tests;
use Drupal\rng\Entity\RngEventType;
use Drupal\courier\Entity\CourierContext;
use Drupal\node\Entity\NodeType;
use Drupal\Core\Url;
class RngEventTypeTest extends RngWebTestBase {
public static $modules = [
'node',
'field_ui',
'block',
];
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('local_tasks_block');
$this
->drupalPlaceBlock('local_actions_block');
}
public function testEventType() {
$web_user = $this
->drupalCreateUser([
'administer event types',
'access administration pages',
]);
$this
->drupalLogin($web_user);
$event_bundle = $this
->drupalCreateContentType();
$event_type = $this
->createEventType('node', $event_bundle
->id());
$this
->drupalGet('admin/structure/rng/event_types/manage/' . $event_type
->id() . '/edit');
$event_type
->delete();
$event_bundle
->delete();
$this
->drupalGet('admin/structure');
$this
->assertLinkByHref(Url::fromRoute('rng.structure')
->toString());
$this
->assertSession()
->responseContains('Manage registration entity types.');
$this
->drupalGet('admin/structure/rng');
$this
->assertLinkByHref(Url::fromRoute('rng.rng_event_type.overview')
->toString());
$this
->assertSession()
->responseContains('Manage which entity bundles are designated as events.');
$this
->assertEqual(0, count(RngEventType::loadMultiple()), 'There are no event type entities.');
$this
->drupalGet('admin/structure/rng/event_types');
$this
->assertSession()
->responseContains('No event types found.');
$this
->assertEqual(0, count(CourierContext::loadMultiple()), 'There are no courier context entities.');
$this
->assertLinkByHref(Url::fromRoute('entity.rng_event_type.add')
->toString());
$t_args = [
'%label' => 'node.event',
];
$edit = [
'registrants[registrant_type]' => 'registrant',
];
$this
->drupalPostForm('admin/structure/rng/event_types/add', $edit, t('Save'));
$node_type = NodeType::load('event');
$this
->assertEqual(1, count(RngEventType::loadMultiple()), 'Event type exists in database.');
$this
->assertSession()
->responseContains(t('The content type <a href=":url">%label</a> has been added.', [
'%label' => $node_type
->label(),
':url' => $node_type
->toUrl()
->toString(),
]));
$this
->assertSession()
->responseContains(t('%label event type added.', $t_args));
$this
->assertSession()
->assert(CourierContext::load('rng_registration_node'), 'Courier context entity created for this event type\' entity type.');
$this
->drupalGet('admin/structure/rng/event_types');
$this
->assertSession()
->responseContains('<td>Content: Event</td>');
$options = [
'node_type' => 'event',
];
$this
->assertLinkByHref(Url::fromRoute("entity.node.field_ui_fields", $options)
->toString());
$edit = [];
$this
->drupalPostForm('admin/structure/rng/event_types/manage/node.event/edit', $edit, t('Save'));
$this
->assertSession()
->responseContains(t('%label event type updated.', $t_args));
$this
->drupalGet('admin/structure/rng/event_types/manage/node.event/delete');
$this
->assertSession()
->responseContains('Are you sure you want to delete event type node.event?');
$this
->drupalPostForm('admin/structure/rng/event_types/manage/node.event/delete', [], t('Delete'));
$this
->assertSession()
->responseContains(t('Event type %label was deleted.', $t_args));
$this
->assertEqual(0, count(RngEventType::loadMultiple()), 'Event type deleted from database.');
}
}