RngEventMetaTest.php in RNG - Events and Registrations 8.2
File
tests/src/Kernel/RngEventMetaTest.php
View source
<?php
namespace Drupal\Tests\rng\Kernel;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\rng\EventManagerInterface;
use Drupal\rng\EventMetaInterface;
use Drupal\field\Entity\FieldConfig;
class RngEventMetaTest extends RngKernelTestBase {
public static $modules = [
'system',
'entity_test',
];
protected $eventManager;
protected $eventType;
protected $unlimited;
protected function setUp() {
parent::setUp();
$this->eventManager = $this->container
->get('rng.event_manager');
$this->eventType = $this
->createEventType('entity_test', 'entity_test');
$this->unlimited = EventMetaInterface::CAPACITY_UNLIMITED;
$this
->installEntitySchema('entity_test');
}
public function testRegistrantsMaximumNoField() {
$field = FieldConfig::loadByName('entity_test', 'entity_test', EventManagerInterface::FIELD_REGISTRANTS_CAPACITY);
$field
->delete();
$event = EntityTest::create();
$event_meta = $this->eventManager
->getMeta($event);
$this
->assertSame($this->unlimited, $event_meta
->getRegistrantsMaximum(), 'Maximum registrants is unlimited when no field exists.');
}
public function testRegistrantsMaximumDefaultValue() {
$field = FieldConfig::loadByName('entity_test', 'entity_test', EventManagerInterface::FIELD_REGISTRANTS_CAPACITY);
$field
->setDefaultValue([
[
'value' => 666,
],
])
->save();
$event = EntityTest::create();
$event_meta = $this->eventManager
->getMeta($event);
$this
->assertSame(666, $event_meta
->getRegistrantsMaximum(), 'Maximum registrants matches bundle default value.');
}
public function testRegistrantsMaximumNoDefaultValue() {
$event = EntityTest::create();
$event_meta = $this->eventManager
->getMeta($event);
$this
->assertSame($this->unlimited, $event_meta
->getRegistrantsMaximum(), 'Maximum registrants matches empty bundle default.');
}
}