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 testRegistrantsMinimumNoField() {
$field = FieldConfig::loadByName('entity_test', 'entity_test', EventManagerInterface::FIELD_REGISTRATION_REGISTRANTS_MINIMUM);
$field
->delete();
$event = EntityTest::create();
$event_meta = $this->eventManager
->getMeta($event);
$this
->assertSame(1, $event_meta
->getRegistrantsMinimum(), 'Minimum registrants is "1" when no field exists.');
}
public function testRegistrantsMinimumDefaultValue() {
$field = FieldConfig::loadByName('entity_test', 'entity_test', EventManagerInterface::FIELD_REGISTRATION_REGISTRANTS_MINIMUM);
$field
->setDefaultValue([
[
'value' => 666,
],
])
->save();
$event = EntityTest::create();
$event_meta = $this->eventManager
->getMeta($event);
$this
->assertSame(666, $event_meta
->getRegistrantsMinimum(), 'Minimum registrants matches bundle default value.');
}
public function testRegistrantsMinimumNoDefaultValue() {
$event = EntityTest::create();
$event_meta = $this->eventManager
->getMeta($event);
$this
->assertSame(1, $event_meta
->getRegistrantsMinimum(), 'Minimum registrants matches empty bundle default.');
}
public function testRegistrantsMinimumEventValue() {
$event = EntityTest::create([
EventManagerInterface::FIELD_REGISTRATION_REGISTRANTS_MINIMUM => 555,
]);
$event_meta = $this->eventManager
->getMeta($event);
$this
->assertSame(555, $event_meta
->getRegistrantsMinimum(), 'Minimum registrants matches event field value.');
}
public function testRegistrantsMaximumNoField() {
$field = FieldConfig::loadByName('entity_test', 'entity_test', EventManagerInterface::FIELD_REGISTRATION_REGISTRANTS_MAXIMUM);
$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_REGISTRATION_REGISTRANTS_MAXIMUM);
$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.');
}
public function testRegistrantsMaximumEventValue() {
$event = EntityTest::create([
EventManagerInterface::FIELD_REGISTRATION_REGISTRANTS_MAXIMUM => 555,
]);
$event_meta = $this->eventManager
->getMeta($event);
$this
->assertSame(555, $event_meta
->getRegistrantsMaximum(), 'Maximum registrants matches event field value.');
}
}