setUpEntityTypeDefinitions example


    $this->entityTypeManager->getDefinitions()->willReturn($definitions);

  }

  /** * Tests the clearCachedBundles() method. * * @covers ::clearCachedBundles */
  public function testClearCachedBundles() {
    $this->setUpEntityTypeDefinitions();

    $this->typedDataManager->clearCachedDefinitions()->shouldBeCalled();

    $this->cacheTagsInvalidator->invalidateTags(['entity_bundles'])->shouldBeCalled();

    $this->entityTypeBundleInfo->clearCachedBundles();
  }

  /** * Tests the getBundleInfo() method. * * @covers ::getBundleInfo * * @dataProvider providerTestGetBundleInfo */

  public function testHasHandler($entity_type_id$expected) {
    $apple = $this->prophesize(EntityTypeInterface::class);
    $apple->hasHandlerClass('storage')->willReturn(TRUE);

    $banana = $this->prophesize(EntityTypeInterface::class);
    $banana->hasHandlerClass('storage')->willReturn(FALSE);

    $this->setUpEntityTypeDefinitions([
      'apple' => $apple,
      'banana' => $banana,
    ]);

    $entity_type = $this->entityTypeManager->hasHandler($entity_type_id, 'storage');
    $this->assertSame($expected$entity_type);
  }

  /** * Provides test data for testHasHandler(). * * @return array * Test data. */

    $entity_class::$bundleFieldDefinitions = [];

    if (!$custom_invoke_all) {
      $this->moduleHandler->invokeAllWith(Argument::cetera(), Argument::cetera());
    }

    // Mock the base field definition override.     $override_entity_type = $this->prophesize(EntityTypeInterface::class);

    $this->entityType = $this->prophesize(EntityTypeInterface::class);
    $this->setUpEntityTypeDefinitions(['test_entity_type' => $this->entityType, 'base_field_override' => $override_entity_type]);

    $storage = $this->prophesize(EntityStorageInterface::class);
    $storage->loadMultiple(Argument::type('array'))->willReturn([]);

    // By default, make the storage entity class lookup return the     // EntityTypeManagerTestEntity class     $storage->getEntityClass(NULL)->willReturn(EntityTypeManagerTestEntity::class);
    $storage->getEntityClass(Argument::type('string'))->willReturn(EntityTypeManagerTestEntity::class);
    // When using the "test_entity_bundle_class" bundle, return the     // EntityTypeManagerTestEntityBundle class     $storage->getEntityClass('test_entity_bundle_class')->willReturn(EntityTypeManagerTestEntityBundle::class);

    

  public function testGetEntityTypeLabels() {
    $apple = $this->prophesize(EntityTypeInterface::class);
    $apple->getLabel()->willReturn('Apple');
    $apple->getBundleOf()->willReturn(NULL);

    $banana = $this->prophesize(EntityTypeInterface::class);
    $banana->getLabel()->willReturn('Banana');
    $banana->getBundleOf()->willReturn(NULL);

    $this->setUpEntityTypeDefinitions([
      'apple' => $apple,
      'banana' => $banana,
    ]);

    $expected = [
      'apple' => 'Apple',
      'banana' => 'Banana',
    ];
    $this->assertSame($expected$this->entityTypeRepository->getEntityTypeLabels());
  }

  
Home | Imprint | This part of the site doesn't use cookies.