/**
  * Creates an event type config.
  *
  * @param \Drupal\Core\Config\Entity\ConfigEntityInterface
  *   An entity type.
  *
  * @return \Drupal\rng\EventTypeInterface
  *   An event type config.
  */
 function createEventType(ConfigEntityInterface $entity_type)
 {
     $event_type = EventType::create(['label' => 'Event Type A', 'entity_type' => $entity_type->getEntityType()->getBundleOf(), 'bundle' => $entity_type->id(), 'mirror_operation_to_event_manage' => 'update']);
     $event_type->save();
     \Drupal::service('router.builder')->rebuildIfNeeded();
     return $event_type;
 }
 /**
  * Test event types in UI.
  */
 function testEventType()
 {
     $web_user = $this->drupalCreateUser(['administer event types', 'access administration pages']);
     $this->drupalLogin($web_user);
     // Create and delete the testing event type.
     $event_bundle = $this->drupalCreateContentType();
     $event_type = $this->createEventType($event_bundle);
     $this->drupalGet('admin/structure/rng/event_types/manage/' . $event_type->id() . '/edit');
     $event_type->delete();
     $event_bundle->delete();
     // Event types button on admin.
     $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.');
     // No events.
     $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');
     // There are no courier contexts.
     $this->assertEqual(0, count(CourierContext::loadMultiple()), 'There are no courier context entities.');
     // Local action.
     $this->assertLinkByHref(Url::fromRoute('entity.event_type.add')->toString());
     // Add.
     $t_args = ['%label' => 'node.event'];
     $edit = [];
     $this->drupalPostForm('admin/structure/rng/event_types/add', $edit, t('Save'));
     /** @var \Drupal\node\NodeTypeInterface $node_type */
     $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');
     // Courier context created?
     $this->assertTrue(CourierContext::load('rng_registration_node'), 'Courier context entity created for this event type\' entity type.');
     // Event type list.
     $this->assertUrl('admin/structure/rng/event_types', [], 'Browser was redirected to event type list.');
     $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 form.
     $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');
     // Delete form.
     $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.');
     // @todo: ensure conditional on form omits node/existing radios
     // @todo create event type with custom entity
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public static function postDelete(EntityStorageInterface $storage, array $entities)
 {
     parent::postDelete($storage, $entities);
     if ($event_type = reset($entities)) {
         EventType::courierContextCC($event_type->entity_type, 'delete');
     }
     // Rebuild routes and local tasks.
     \Drupal::service('router.builder')->setRebuildNeeded();
     // Rebuild local actions https://github.com/dpi/rng/issues/18
     \Drupal::service('plugin.manager.menu.local_action')->clearCachedDefinitions();
 }