rng-3.x-dev/tests/src/Kernel/RngEventTypeEntityTest.php
tests/src/Kernel/RngEventTypeEntityTest.php
<?php namespace Drupal\Tests\rng\Kernel; use Drupal\rng\Entity\RngEventType; /** * Tests event type entities. * * @group rng * @coversDefaultClass \Drupal\rng\Entity\RngEventType */ class RngEventTypeEntityTest extends RngKernelTestBase { /** * Tests getting a single identity type form mode. * * @covers ::getIdentityTypeEntityFormMode */ public function testGetIdentityTypeEntityFormMode() { $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->getIdentityTypeEntityFormMode($people_type['entity_type'], $people_type['bundle']); $this->assertEquals($people_type['entity_form_mode'], $result); } /** * Tests getting a single identity type form mode when no defaults set. * * @covers ::getIdentityTypeEntityFormMode */ public function testGetIdentityTypeEntityFormModeNoDefaults() { $people_type = [ 'entity_type' => $this->randomMachineName(), 'bundle' => $this->randomMachineName(), ]; $values['people_types'][] = $people_type; $event_type = $this->createEventTypeBase($values); $result = $event_type->getIdentityTypeEntityFormMode($people_type['entity_type'], $people_type['bundle']); $this->assertEquals('default', $result); } /** * 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 an event type with only required info. * * @param array $values * Default values to use when creating the event type. * * @return \Drupal\rng\Entity\EventTypeInterface * An new event type entity. */ protected function createEventTypeBase(array $values = []) { $event_type = RngEventType::create($values + [ 'id' => $this->randomMachineName(), 'label' => $this->randomMachineName(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', ]); return $event_type; } }