You are here

class EntityTypeBaseFieldTest in Hook Event Dispatcher 3.x

Same name and namespace in other branches
  1. 8.2 modules/core_event_dispatcher/tests/src/Unit/Entity/EntityTypeBaseFieldTest.php \Drupal\Tests\core_event_dispatcher\Unit\Entity\EntityTypeBaseFieldTest

Class EntityTypeTest.

@group core_event_dispatcher

Hierarchy

Expanded class hierarchy of EntityTypeBaseFieldTest

File

modules/core_event_dispatcher/tests/src/Unit/Entity/EntityTypeBaseFieldTest.php, line 19

Namespace

Drupal\Tests\core_event_dispatcher\Unit\Entity
View source
class EntityTypeBaseFieldTest extends TestCase {

  /**
   * The manager.
   *
   * @var \Drupal\Tests\hook_event_dispatcher\Unit\HookEventDispatcherManagerSpy
   */
  private $manager;

  /**
   * {@inheritdoc}
   */
  public function setUp() : void {
    $builder = new ContainerBuilder();
    $this->manager = new HookEventDispatcherManagerSpy();
    $builder
      ->set('hook_event_dispatcher.manager', $this->manager);
    $builder
      ->compile();
    Drupal::setContainer($builder);
  }

  /**
   * Test the EntityBaseFieldInfoEvent.
   */
  public function testEntityBaseFieldInfoEvent() : void {
    $fields = [
      'field_test1' => 'test',
      'field_test2' => 'otherTest',
    ];
    $this->manager
      ->setEventCallbacks([
      HookEventDispatcherInterface::ENTITY_BASE_FIELD_INFO => static function (EntityBaseFieldInfoEvent $event) use ($fields) {
        $event
          ->setFields($fields);
      },
    ]);
    $entityType = $this
      ->createMock(EntityTypeInterface::class);
    $hookFieldInfoResult = core_event_dispatcher_entity_base_field_info($entityType);

    /** @var \Drupal\core_event_dispatcher\Event\Entity\EntityBaseFieldInfoEvent $event */
    $event = $this->manager
      ->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_BASE_FIELD_INFO);
    self::assertSame($entityType, $event
      ->getEntityType());
    self::assertSame($fields, $event
      ->getFields());
    self::assertSame($fields, $hookFieldInfoResult);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityTypeBaseFieldTest::$manager private property The manager.
EntityTypeBaseFieldTest::setUp public function
EntityTypeBaseFieldTest::testEntityBaseFieldInfoEvent public function Test the EntityBaseFieldInfoEvent.