View source
<?php
namespace Drupal\rng\Tests;
use Drupal\rng\Entity\EventType;
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');
}
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.event_type.overview')
->toString());
$this
->assertRaw('Manage which entity bundles are designated as events.', 'Button shows in administration.');
$this
->assertEqual(0, count(EventType::loadMultiple()), 'There are no event type entities.');
$this
->drupalGet('admin/structure/rng/event_types');
$this
->assertRaw('No event types found.', 'Event Type list is empty');
$this
->assertEqual(0, count(CourierContext::loadMultiple()), 'There are no courier context entities.');
$this
->assertLinkByHref(Url::fromRoute('entity.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(EventType::loadMultiple()), 'Event type exists in database.');
$this
->assertRaw(t('The content type <a href=":url">%label</a> has been added.', [
'%label' => $node_type
->label(),
':url' => $node_type
->toUrl()
->toString(),
]), 'Node was created for Event Type');
$this
->assertRaw(t('%label event type added.', $t_args), 'Event Type created');
$this
->assertTrue(CourierContext::load('rng_registration_node'), 'Courier context entity created for this event type\' entity type.');
$this
->drupalGet('admin/structure/rng/event_types');
$this
->assertRaw('<td>Content: Event</td>', 'Event Type shows in list');
$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
->assertRaw(t('%label event type updated.', $t_args), 'Event Type edit form saved');
$this
->drupalGet('admin/structure/rng/event_types/manage/node.event/delete');
$this
->assertRaw('Are you sure you want to delete event type node.event?', 'Event Type delete form rendered.');
$this
->drupalPostForm('admin/structure/rng/event_types/manage/node.event/delete', [], t('Delete'));
$this
->assertRaw(t('Event type %label was deleted.', $t_args), 'Event Type delete form saved');
$this
->assertEqual(0, count(EventType::loadMultiple()), 'Event type deleted from database.');
}
}