setModuleHandler example

$entityTypeManager = $this->createMock(EntityTypeManagerInterface::class);
    $entityTypeManager->expects($this->any())
      ->method('getStorage')
      ->with('node')
      ->willReturn($nodeStorage);

    $moduleHandler = $this->createMock(ModuleHandlerInterface::class);
    $moduleHandler->expects($this->any())
      ->method('invokeAll')
      ->willReturn([]);
    $accessControl = new NodeAccessControlHandler($entityType$grants$entityTypeManager);
    $accessControl->setModuleHandler($moduleHandler);

    $access = $accessControl->access($node$operation$account, FALSE);
    $this->assertEquals($assertAccess$access);
  }

  /** * Data provider for revisionOperationsProvider. * * @return array * Data for testing. */
  
    $migration = $this->getMigration();
    $source = new StubSourcePlugin([], '', []$migration);
    $row = new Row();

    $module_handler = $this->prophesize(ModuleHandlerInterface::class);
    $module_handler->invokeAll('migrate_prepare_row', [$row$source$migration])
      ->willReturn([TRUE, TRUE])
      ->shouldBeCalled();
    $module_handler->invokeAll('migrate_' . $migration->id() . '_prepare_row', [$row$source$migration])
      ->willReturn([TRUE, TRUE])
      ->shouldBeCalled();
    $source->setModuleHandler($module_handler->reveal());

    // Ensure we don't log this to the mapping table.     $this->idMap->expects($this->never())
      ->method('saveIdMapping');

    $this->assertTrue($source->prepareRow($row));

    // Track_changes...     $source = new StubSourcePlugin(['track_changes' => TRUE], '', []$migration);
    $row2 = $this->prophesize(Row::class);
    $row2->rehash()
      
->willReturn($this->entityType);

    $this->entityFieldManager
      ->getFieldStorageDefinitions($this->entityType->id())
      ->willReturn($this->fieldDefinitions);

    $this->entityFieldManager
      ->getActiveFieldStorageDefinitions($this->entityType->id())
      ->willReturn($this->fieldDefinitions);

    $this->entityStorage = new SqlContentEntityStorage($this->entityType, $this->connection, $this->entityFieldManager->reveal()$this->cache, $this->languageManager, new MemoryCache()$this->entityTypeBundleInfo, $this->entityTypeManager->reveal());
    $this->entityStorage->setModuleHandler($this->moduleHandler);
  }

  /** * @covers ::doLoadMultiple * @covers ::buildCacheId * @covers ::getFromPersistentCache */
  public function testLoadMultiplePersistentCached() {
    $this->setUpModuleHandlerNoImplementations();

    $key = 'values:' . $this->entityTypeId . ':1';
    
// Finally, use the 'broken' handler.     return $this->createInstance('broken', ['original_configuration' => $item]);
  }

  /** * {@inheritdoc} */
  public function createInstance($plugin_id, array $configuration = []) {
    $instance = parent::createInstance($plugin_id$configuration);
    if ($instance instanceof HandlerBase) {
      $instance->setModuleHandler($this->moduleHandler);
      $instance->setViewsData($this->viewsData);
    }
    return $instance;
  }

  /** * {@inheritdoc} */
  public function getFallbackPluginId($plugin_id, array $configuration = []) {
    return 'broken';
  }

}
$this->languageManager = $this->prophesize(LanguageManagerInterface::class);
    $this->languageManager->getCurrentLanguage()->willReturn(new Language(['id' => 'hu']));

    $this->configFactory = $this->prophesize(ConfigFactoryInterface::class);

    $this->entityQuery = $this->prophesize(QueryInterface::class);
    $entity_query_factory = $this->prophesize(QueryFactoryInterface::class);
    $entity_query_factory->get($entity_type, 'AND')->willReturn($this->entityQuery->reveal());

    $this->entityStorage = new ConfigEntityStorage($entity_type$this->configFactory->reveal()$this->uuidService->reveal()$this->languageManager->reveal()new MemoryCache());
    $this->entityStorage->setModuleHandler($this->moduleHandler->reveal());

    $entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class);
    $entity_type_manager->getDefinition('test_entity_type')->willReturn($entity_type);

    $this->cacheTagsInvalidator = $this->prophesize(CacheTagsInvalidatorInterface::class);

    $typed_config_manager = $this->prophesize(TypedConfigManagerInterface::class);
    $typed_config_manager
      ->getDefinition(Argument::containingString('the_provider.the_config_prefix.'))
      ->willReturn(['mapping' => ['id' => '', 'uuid' => '', 'dependencies' => '']]);

    
$this->uuidService = $this->createMock('Drupal\Component\Uuid\UuidInterface');
    $this->languageManager = $this->createMock('Drupal\Core\Language\LanguageManagerInterface');
    $language = new Language(['langcode' => 'en']);
    $this->languageManager->expects($this->any())
      ->method('getDefaultLanguage')
      ->willReturn($language);
    $this->languageManager->expects($this->any())
      ->method('getCurrentLanguage')
      ->willReturn($language);

    $this->entityStorage = new KeyValueEntityStorage($this->entityType, $this->keyValueStore, $this->uuidService, $this->languageManager, new MemoryCache());
    $this->entityStorage->setModuleHandler($this->moduleHandler);

    $container = new ContainerBuilder();
    $container->set('entity_field.manager', $this->entityFieldManager);
    $container->set('entity_type.manager', $this->entityTypeManager);
    $container->set('language_manager', $this->languageManager);
    $container->set('cache_tags.invalidator', $this->cacheTagsInvalidator);
    \Drupal::setContainer($container);
  }

  /** * @covers ::create * @covers ::doCreate */

  public function getFormObject($entity_type_id$operation) {
    if (!$class = $this->getDefinition($entity_type_id, TRUE)->getFormClass($operation)) {
      throw new InvalidPluginDefinitionException($entity_type_idsprintf('The "%s" entity type did not specify a "%s" form class.', $entity_type_id$operation));
    }

    $form_object = $this->classResolver->getInstanceFromDefinition($class);

    return $form_object
      ->setStringTranslation($this->stringTranslation)
      ->setModuleHandler($this->moduleHandler)
      ->setEntityTypeManager($this)
      ->setOperation($operation);
  }

  /** * {@inheritdoc} */
  public function getRouteProviders($entity_type_id) {
    if (!isset($this->handlers['route_provider'][$entity_type_id])) {
      $route_provider_classes = $this->getDefinition($entity_type_id, TRUE)->getRouteProviderClasses();

      
$entity_form_display_entity_type->expects($this->any())
      ->method('getConfigPrefix')
      ->willReturn('');

    $this->moduleHandler = $this->createMock(ModuleHandlerInterface::class);
    $this->moduleHandler
      ->expects($this->any())
      ->method('invokeAll')
      ->willReturn([]);

    $storage_access_control_handler = new EntityFormDisplayAccessControlHandler($entity_form_display_entity_type);
    $storage_access_control_handler->setModuleHandler($this->moduleHandler);

    $entity_type_manager = $this->createMock(EntityTypeManagerInterface::class);
    $entity_type_manager
      ->expects($this->any())
      ->method('getStorage')
      ->willReturnMap([
        ['entity_display', $this->createMock(EntityStorageInterface::class)],
      ]);
    $entity_type_manager
      ->expects($this->any())
      ->method('getAccessControlHandler')
      
/** * @covers ::getPluginDependencies * * @dataProvider providerTestPluginDependencies */
  public function testGetPluginDependencies(ProphecyInterface $plugin$definition, array $expected) {
    $test_class = new TestPluginDependency();

    $module_handler = $this->prophesize(ModuleHandlerInterface::class);
    $module_handler->moduleExists('test_module1')->willReturn(TRUE);
    $module_handler->moduleExists('test_theme1')->willReturn(FALSE);
    $test_class->setModuleHandler($module_handler->reveal());

    $theme_handler = $this->prophesize(ThemeHandlerInterface::class);
    $theme_handler->themeExists('test_module1')->willReturn(FALSE);
    $theme_handler->themeExists('test_theme1')->willReturn(TRUE);
    $test_class->setThemeHandler($theme_handler->reveal());

    $plugin->getPluginDefinition()->willReturn($definition);

    $actual = $test_class->getPluginDependencies($plugin->reveal());
    $this->assertEquals($expected$actual);
    $this->assertEmpty($test_class->getDependencies());
  }
$entity_storage = $this->entityTypeManager->getStorage($resource_type->getEntityTypeId());

    $query = $entity_storage->getQuery();

    // Ensure that access checking is performed on the query.     $query->accessCheck(TRUE);

    // Compute and apply an entity query condition from the filter parameter.     if (isset($params[Filter::KEY_NAME]) && $filter = $params[Filter::KEY_NAME]) {
      $query->condition($filter->queryCondition($query));
      TemporaryQueryGuard::setFieldManager($this->fieldManager);
      TemporaryQueryGuard::setModuleHandler(\Drupal::moduleHandler());
      TemporaryQueryGuard::applyAccessControls($filter$query$query_cacheability);
    }

    // Apply any sorts to the entity query.     if (isset($params[Sort::KEY_NAME]) && $sort = $params[Sort::KEY_NAME]) {
      foreach ($sort->fields() as $field) {
        $path = $this->fieldResolver->resolveInternalEntityQueryPath($resource_type$field[Sort::PATH_KEY]);
        $direction = $field[Sort::DIRECTION_KEY] ?? 'ASC';
        $langcode = $field[Sort::LANGUAGE_KEY] ?? NULL;
        $query->sort($path$direction$langcode);
      }
    }
->method('getId')
      ->willReturn('de');

    $entity = $this->createMock(ContentEntityInterface::class);
    $entity->expects($this->any())
      ->method('language')
      ->willReturn($language);

    $account = $this->createMock(AccountInterface::class);

    $accessControl = new MenuLinkContentAccessControlHandler($entityType$accessManager);
    $accessControl->setModuleHandler($moduleHandler);
    $access = $accessControl->access($entity, 'not-an-op', $account, TRUE);
    $this->assertInstanceOf(AccessResultInterface::class$access);
  }

}
->expects($this->any())
      ->method('getConfigPrefix')
      ->willReturn('node');

    $this->moduleHandler = $this->createMock(ModuleHandlerInterface::class);
    $this->moduleHandler
      ->expects($this->any())
      ->method('invokeAll')
      ->willReturn([]);

    $storage_access_control_handler = new FieldStorageConfigAccessControlHandler($storageType);
    $storage_access_control_handler->setModuleHandler($this->moduleHandler);

    $entity_type_manager = $this->createMock(EntityTypeManagerInterface::class);
    $entity_type_manager
      ->expects($this->any())
      ->method('getDefinition')
      ->willReturnMap([
        ['field_storage_config', TRUE, $storageType],
        ['node', TRUE, $entityType],
      ]);
    $entity_type_manager
      ->expects($this->any())
      
->method('id')
      ->willReturn(2);

    $this->entity = new EntityViewDisplay([
      'targetEntityType' => 'foobar',
      'bundle' => 'bazqux',
      'mode' => 'default',
      'id' => 'foobar.bazqux.default',
      'uuid' => '6f2f259a-f3c7-42ea-bdd5-111ad1f85ed1',
    ], 'entity_display');
    $this->accessControlHandler = new EntityViewDisplayAccessControlHandler($this->entity->getEntityType());
    $this->accessControlHandler->setModuleHandler($this->moduleHandler);
  }

}
'view user email addresses', TRUE],
      ]);
    $this->emailViewer
      ->expects($this->any())
      ->method('id')
      ->willReturn(3);

    $entity_type = $this->createMock('Drupal\Core\Entity\EntityTypeInterface');

    $this->accessControlHandler = new UserAccessControlHandler($entity_type);
    $module_handler = $this->createMock('Drupal\Core\Extension\ModuleHandlerInterface');
    $this->accessControlHandler->setModuleHandler($module_handler);

    $this->items = $this->getMockBuilder('Drupal\Core\Field\FieldItemList')
      ->disableOriginalConstructor()
      ->getMock();
    $this->items
      ->expects($this->any())
      ->method('defaultAccess')
      ->willReturn(AccessResult::allowed());
  }

  /** * Asserts correct field access grants for a field. * * @internal */
parent::setUp();

    $this->entity = new FieldConfig([
      'field_name' => $this->entity->getName(),
      'entity_type' => 'node',
      'fieldStorage' => $this->entity,
      'bundle' => 'test_bundle',
      'field_type' => 'test_field',
    ], 'node');

    $this->accessControlHandler = new FieldConfigAccessControlHandler($this->entity->getEntityType());
    $this->accessControlHandler->setModuleHandler($this->moduleHandler);
  }

  /** * Ensures field config access is working properly. */
  public function testAccess() {
    $this->assertAllowOperations([]$this->anon);
    $this->assertAllowOperations(['view', 'update', 'delete']$this->member);
  }

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