コード例 #1
0
 /**
  * Sets up the entity type manager to be tested.
  *
  * @param \Drupal\Core\Entity\EntityTypeInterface[]|\Prophecy\Prophecy\ProphecyInterface[] $definitions
  *   (optional) An array of entity type definitions.
  */
 protected function setUpEntityTypeDefinitions($definitions = [])
 {
     $class = $this->getMockClass(EntityInterface::class);
     foreach ($definitions as $key => $entity_type) {
         // \Drupal\Core\Entity\EntityTypeInterface::getLinkTemplates() is called
         // by \Drupal\Core\Entity\EntityManager::processDefinition() so it must
         // always be mocked.
         $entity_type->getLinkTemplates()->willReturn([]);
         // Give the entity type a legitimate class to return.
         $entity_type->getClass()->willReturn($class);
         $definitions[$key] = $entity_type->reveal();
     }
     $this->entityTypeManager->getDefinition(Argument::cetera())->will(function ($args) use($definitions) {
         $entity_type_id = $args[0];
         $exception_on_invalid = $args[1];
         if (isset($definitions[$entity_type_id])) {
             return $definitions[$entity_type_id];
         } elseif (!$exception_on_invalid) {
             return NULL;
         } else {
             throw new PluginNotFoundException($entity_type_id);
         }
     });
     $this->entityTypeManager->getDefinitions()->willReturn($definitions);
 }
コード例 #2
0
 /**
  * @covers ::getAddFormRoute
  * @dataProvider providerTestGetAddFormRoute
  */
 public function testGetAddFormRoute(Route $expected = NULL, EntityTypeInterface $entity_type, EntityTypeInterface $bundle_entity_type = NULL, FieldStorageDefinitionInterface $field_storage_definition = NULL)
 {
     if ($bundle_entity_type) {
         $this->entityTypeManager->getDefinition('the_bundle_entity_type_id')->willReturn($bundle_entity_type);
         if ($field_storage_definition) {
             $this->entityFieldManager->getFieldStorageDefinitions('the_bundle_entity_type_id')->willReturn(['id' => $field_storage_definition]);
         }
     }
     $route = $this->routeProvider->getAddFormRoute($entity_type);
     $this->assertEquals($expected, $route);
 }