Skip to content
Snippets Groups Projects
Commit e1d96b7d authored by dpi's avatar dpi
Browse files

Added event type entity test coverage.

Fixed failing tests, entity_form_mode not set
parent 13b33f6c
No related branches found
No related tags found
No related merge requests found
......@@ -220,9 +220,13 @@ class EventType extends ConfigEntityBase implements EventTypeInterface {
public function getIdentityTypeEntityFormModes() {
$result = [];
foreach ($this->people_types as $people_type) {
$entity_type = $people_type['entity_type'];
$bundle = $people_type['bundle'];
$result[$entity_type][$bundle] = $people_type['entity_form_mode'];
$required_keys = ['entity_type', 'bundle', 'entity_form_mode'];
// Ensure keys exist.
if (count($required_keys) === count(array_intersect_key(array_flip($required_keys), $people_type))) {
$entity_type = $people_type['entity_type'];
$bundle = $people_type['bundle'];
$result[$entity_type][$bundle] = $people_type['entity_form_mode'];
}
}
return $result;
}
......
......@@ -91,7 +91,7 @@ class RngEventMetaTest extends RngKernelTestBase {
public function testRegistrantsMinimumNoDefaultValue() {
$event = EntityTest::create();
$event_meta = $this->eventManager->getMeta($event);
$this->assertSame($this->unlimited, $event_meta->getRegistrantsMinimum(), 'Minimum registrants matches empty bundle default.');
$this->assertSame(1, $event_meta->getRegistrantsMinimum(), 'Minimum registrants matches empty bundle default.');
}
/**
......
<?php
namespace Drupal\Tests\rng\Kernel;
use Drupal\simpletest\UserCreationTrait;
use Drupal\rng\Entity\EventType;
/**
* Tests event type entities.
*
* @group rng
* @coversDefaultClass \Drupal\rng\Entity\EventType
*/
class RngEventTypeEntityTest extends RngKernelTestBase {
/**
* Test getting all identity type form modes.
*
* @covers ::getIdentityTypeEntityFormModes
*/
public function testGetIdentityTypeEntityFormModes() {
$people_type = [
'entity_type' => $this->randomMachineName(),
'bundle' => $this->randomMachineName(),
'entity_form_mode' => $this->randomMachineName(),
];
$values['people_types'][] = $people_type;
$event_type = $this->createEventTypeBase($values);
$result = $event_type->getIdentityTypeEntityFormModes();
$this->assertEquals($people_type['entity_form_mode'], $result[$people_type['entity_type']][$people_type['bundle']]);
}
/**
* Test getting all identity type form modes when no defaults set.
*
* @covers ::getIdentityTypeEntityFormModes
*/
public function testGetIdentityTypeEntityFormModesNoDefaults() {
$values['people_types'][] = [
'entity_type' => $this->randomMachineName(),
'bundle' => $this->randomMachineName(),
];
$event_type = $this->createEventTypeBase($values);
$result = $event_type->getIdentityTypeEntityFormModes();
$this->assertEquals([] , $result);
}
/**
* Test default registrant type defaults.
*
* @covers ::setDefaultRegistrantType
* @covers ::getDefaultRegistrantType
*/
public function testGetDefaultRegistrantType() {
$event_type = $this->createEventTypeBase();
$registrant_type = $this->randomMachineName();
$event_type->setDefaultRegistrantType($registrant_type);
$this->assertEquals($registrant_type, $event_type->getDefaultRegistrantType());
}
/**
* Test getting default registrant type defaults set.
*
* @covers ::getDefaultRegistrantType
*/
public function testGetDefaultRegistrantTypeDefault() {
$event_type = $this->createEventTypeBase();
$result = $event_type->getDefaultRegistrantType();
$this->assertNull($result);
}
/**
* Create a event type with only required info.
*
* @param array $values
* Default values to use when creating the event type.
*
* @return \Drupal\rng\EventTypeInterface
* An new event type entity.
*/
protected function createEventTypeBase($values = []) {
$event_type = EventType::create($values + [
'id' => $this->randomMachineName(),
'label' => $this->randomMachineName(),
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
]);
return $event_type;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment