Example #1
0
 /**
  * {@inheritdoc}
  *
  * @covers ::__construct
  */
 protected function setUp()
 {
     parent::setUp();
     $this->entityType = $this->getMock('Drupal\\Core\\Config\\Entity\\ConfigEntityTypeInterface');
     $this->entityTypeId = 'test_entity_type';
     $this->entityType->expects($this->any())->method('getKey')->will($this->returnValueMap(array(array('id', 'id'), array('uuid', 'uuid'), array('langcode', 'langcode'))));
     $this->entityType->expects($this->any())->method('id')->will($this->returnValue($this->entityTypeId));
     $this->entityType->expects($this->any())->method('getConfigPrefix')->will($this->returnValue('the_config_prefix'));
     $this->entityType->expects($this->any())->method('getClass')->will($this->returnValue(get_class($this->getMockEntity())));
     $this->entityType->expects($this->any())->method('getListCacheTags')->willReturn(array('test_entity_type_list'));
     $this->moduleHandler = $this->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
     $this->uuidService = $this->getMock('Drupal\\Component\\Uuid\\UuidInterface');
     $this->languageManager = $this->getMock('Drupal\\Core\\Language\\LanguageManagerInterface');
     $this->languageManager->expects($this->any())->method('getCurrentLanguage')->willReturn(new Language(array('id' => 'hu')));
     $this->configFactory = $this->getMock('Drupal\\Core\\Config\\ConfigFactoryInterface');
     $this->entityQuery = $this->getMock('Drupal\\Core\\Entity\\Query\\QueryInterface');
     $this->entityStorage = $this->getMockBuilder('Drupal\\Core\\Config\\Entity\\ConfigEntityStorage')->setConstructorArgs(array($this->entityType, $this->configFactory, $this->uuidService, $this->languageManager))->setMethods(array('getQuery'))->getMock();
     $this->entityStorage->expects($this->any())->method('getQuery')->will($this->returnValue($this->entityQuery));
     $this->entityStorage->setModuleHandler($this->moduleHandler);
     $this->entityManager = $this->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface');
     $this->entityManager->expects($this->any())->method('getDefinition')->with('test_entity_type')->will($this->returnValue($this->entityType));
     $this->cacheTagsInvalidator = $this->getMock('Drupal\\Core\\Cache\\CacheTagsInvalidatorInterface');
     $this->typedConfigManager = $this->getMock('Drupal\\Core\\Config\\TypedConfigManagerInterface');
     $this->typedConfigManager->expects($this->any())->method('getDefinition')->will($this->returnValue(array('mapping' => array('id' => '', 'uuid' => '', 'dependencies' => ''))));
     $this->configManager = $this->getMock('Drupal\\Core\\Config\\ConfigManagerInterface');
     $this->cacheContextsManager = $this->getMockBuilder('Drupal\\Core\\Cache\\Context\\CacheContextsManager')->disableOriginalConstructor()->getMock();
     $container = new ContainerBuilder();
     $container->set('entity.manager', $this->entityManager);
     $container->set('config.typed', $this->typedConfigManager);
     $container->set('cache_tags.invalidator', $this->cacheTagsInvalidator);
     $container->set('config.manager', $this->configManager);
     $container->set('language_manager', $this->languageManager);
     $container->set('cache_contexts_manager', $this->cacheContextsManager);
     \Drupal::setContainer($container);
 }
 /**
  * {@inheritdoc}
  *
  * @covers ::__construct()
  */
 protected function setUp()
 {
     parent::setUp();
     $this->entityType = $this->getMock('Drupal\\Core\\Entity\\EntityTypeInterface');
     $this->entityTypeId = 'test_entity_type';
     $this->entityType->expects($this->any())->method('getKey')->will($this->returnValueMap(array(array('id', 'id'), array('uuid', 'uuid'))));
     $this->entityType->expects($this->any())->method('id')->will($this->returnValue($this->entityTypeId));
     $this->entityType->expects($this->any())->method('getConfigPrefix')->will($this->returnValue('the_config_prefix'));
     $this->entityType->expects($this->any())->method('getClass')->will($this->returnValue(get_class($this->getMockEntity())));
     $this->moduleHandler = $this->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
     $this->uuidService = $this->getMock('Drupal\\Component\\Uuid\\UuidInterface');
     $this->languageManager = $this->getMock('Drupal\\Core\\Language\\LanguageManagerInterface');
     $this->languageManager->expects($this->any())->method('getDefaultLanguage')->will($this->returnValue(new Language(array('langcode' => 'en'))));
     $this->configStorage = $this->getConfigStorageStub(array());
     $this->configFactory = $this->getMock('Drupal\\Core\\Config\\ConfigFactoryInterface');
     $this->entityQuery = $this->getMock('Drupal\\Core\\Entity\\Query\\QueryInterface');
     $this->entityStorage = $this->getMockBuilder('Drupal\\Core\\Config\\Entity\\ConfigEntityStorage')->setConstructorArgs(array($this->entityType, $this->configFactory, $this->configStorage, $this->uuidService, $this->languageManager))->setMethods(array('getQuery'))->getMock();
     $this->entityStorage->expects($this->any())->method('getQuery')->will($this->returnValue($this->entityQuery));
     $this->entityStorage->setModuleHandler($this->moduleHandler);
     $this->entityManager = $this->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface');
     $this->entityManager->expects($this->any())->method('getDefinition')->with('test_entity_type')->will($this->returnValue($this->entityType));
     $this->cacheBackend = $this->getMock('Drupal\\Core\\Cache\\CacheBackendInterface');
     $this->typedConfigManager = $this->getMock('Drupal\\Core\\Config\\TypedConfigManagerInterface');
     $this->typedConfigManager->expects($this->any())->method('getDefinition')->will($this->returnValue(array('mapping' => array('id' => '', 'uuid' => '', 'dependencies' => ''))));
     $container = new ContainerBuilder();
     $container->set('entity.manager', $this->entityManager);
     $container->set('config.typed', $this->typedConfigManager);
     $container->set('cache.test', $this->cacheBackend);
     $container->setParameter('cache_bins', array('cache.test' => 'test'));
     \Drupal::setContainer($container);
 }