Exemplo n.º 1
0
  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp();

    $this->aliasProcessor = $this->getMockBuilder('Drupal\Core\PathProcessor\PathProcessorAlias')
      ->disableOriginalConstructor()
      ->getMock();

    $this->languageManager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
    $this->languageManager->expects($this->any())
      ->method('getCurrentLanguage')
      ->willReturn(new Language(Language::$defaultValues));

    $this->pathValidator = $this->getMock('Drupal\Core\Path\PathValidatorInterface');

    $this->subPathautoSettings = $this->getMock('Drupal\Core\Config\ConfigBase');

    $this->configFactory = $this->getMock('Drupal\Core\Config\ConfigFactoryInterface');
    $this->configFactory->expects($this->any())
      ->method('get')
      ->with('subpathauto.settings')
      ->willReturn($this->subPathautoSettings);

    $this->sut = new PathProcessor($this->aliasProcessor, $this->languageManager, $this->configFactory);
    $this->sut->setPathValidator($this->pathValidator);
  }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->cacheBackend = $this->getMock('Drupal\\Core\\Cache\\CacheBackendInterface');
     $this->getContainerWithCacheBins($this->cacheBackend);
     $configs = array();
     $configs['views.settings']['skip_cache'] = FALSE;
     $this->configFactory = $this->getConfigFactoryStub($configs);
     $this->moduleHandler = $this->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
     $this->languageManager = $this->getMock('Drupal\\Core\\Language\\LanguageManagerInterface');
     $this->languageManager->expects($this->any())->method('getCurrentLanguage')->will($this->returnValue(new Language(array('id' => 'en'))));
     $this->viewsData = new ViewsData($this->cacheBackend, $this->configFactory, $this->moduleHandler, $this->languageManager);
 }
 /**
  * {@inheritdoc}
  */
 public function setup()
 {
     $this->defaultDateTime = $this->getMockBuilder(DrupalDateTime::class)->disableOriginalConstructor()->getMock();
     $language = $this->getMock(LanguageInterface::class);
     $this->languageManager = $this->getMock(LanguageManagerInterface::class);
     $this->languageManager->expects($this->any())->method('getCurrentLanguage')->willReturn($language);
     $this->moduleHandler = $this->getMock(ModuleHandlerInterface::class);
     $this->paymentStatusManager = $this->getMock(PaymentStatusManagerInterface::class);
     $configuration = [];
     $this->pluginId = $this->randomMachineName();
     $this->pluginDefinition = array('label' => $this->randomMachineName());
     $this->sut = $this->getMockBuilder(PaymentStatusBase::class)->setConstructorArgs(array($configuration, $this->pluginId, $this->pluginDefinition, $this->moduleHandler, $this->paymentStatusManager, $this->defaultDateTime))->getMockForAbstractClass();
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->mailManager = $this->getMock('\\Drupal\\Core\\Mail\\MailManagerInterface');
     $this->languageManager = $this->getMock('\\Drupal\\Core\\Language\\LanguageManagerInterface');
     $this->logger = $this->getMock('\\Psr\\Log\\LoggerInterface');
     $this->entityManager = $this->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface');
     $this->userStorage = $this->getMock('\\Drupal\\Core\\Entity\\EntityStorageInterface');
     $this->entityManager->expects($this->any())->method('getStorage')->with('user')->willReturn($this->userStorage);
     $string_translation = $this->getStringTranslationStub();
     $this->contactMailHandler = new MailHandler($this->mailManager, $this->languageManager, $this->logger, $string_translation, $this->entityManager);
     $language = new Language(array('id' => 'en'));
     $this->languageManager->expects($this->any())->method('getDefaultLanguage')->will($this->returnValue($language));
     $this->languageManager->expects($this->any())->method('getCurrentLanguage')->will($this->returnValue($language));
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->id = $this->randomMachineName();
     $values = array('id' => $this->id, 'langcode' => 'en', 'uuid' => '3bb9ee60-bea5-4622-b89b-a63319d10b3a');
     $this->entityTypeId = $this->randomMachineName();
     $this->provider = $this->randomMachineName();
     $this->entityType = $this->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
     $this->entityType->expects($this->any())->method('getProvider')->will($this->returnValue($this->provider));
     $this->entityManager = $this->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface');
     $this->entityManager->expects($this->any())->method('getDefinition')->with($this->entityTypeId)->will($this->returnValue($this->entityType));
     $this->uuid = $this->getMock('\\Drupal\\Component\\Uuid\\UuidInterface');
     $this->languageManager = $this->getMock('\\Drupal\\Core\\Language\\LanguageManagerInterface');
     $this->languageManager->expects($this->any())->method('getLanguage')->with('en')->will($this->returnValue(new Language(array('id' => 'en'))));
     $this->cacheBackend = $this->getMock('Drupal\\Core\\Cache\\CacheBackendInterface');
     $this->typedConfigManager = $this->getMock('Drupal\\Core\\Config\\TypedConfigManagerInterface');
     $container = new ContainerBuilder();
     $container->set('entity.manager', $this->entityManager);
     $container->set('uuid', $this->uuid);
     $container->set('language_manager', $this->languageManager);
     $container->set('cache.test', $this->cacheBackend);
     $container->set('config.typed', $this->typedConfigManager);
     $container->setParameter('cache_bins', array('cache.test' => 'test'));
     \Drupal::setContainer($container);
     $this->entity = $this->getMockForAbstractClass('\\Drupal\\Core\\Config\\Entity\\ConfigEntityBase', array($values, $this->entityTypeId));
 }
Exemplo n.º 6
0
 /**
  * Tests buildTree with simple menu_name and no parameters.
  */
 public function testBuildTreeWithoutParameters()
 {
     $language = new Language(array('id' => 'en'));
     $this->languageManager->expects($this->any())->method('getCurrentLanguage')->will($this->returnValue($language));
     // Setup query and the query result.
     $query = $this->getMock('Drupal\\Core\\Entity\\Query\\QueryInterface');
     $this->entityQueryFactory->expects($this->once())->method('get')->with('menu_link')->will($this->returnValue($query));
     $query->expects($this->once())->method('condition')->with('menu_name', 'test_menu');
     $query->expects($this->once())->method('execute')->will($this->returnValue(array(1, 2, 3)));
     $storage = $this->getMock('Drupal\\Core\\Entity\\EntityStorageInterface');
     $base = array('access' => TRUE, 'weight' => 0, 'title' => 'title');
     $menu_link = $base + array('mlid' => 1, 'p1' => 3, 'p2' => 2, 'p3' => 1);
     $links[1] = $menu_link;
     $menu_link = $base + array('mlid' => 3, 'p1' => 3, 'depth' => 1);
     $links[3] = $menu_link;
     $menu_link = $base + array('mlid' => 2, 'p1' => 3, 'p2' => 2, 'depth' => 2);
     $links[2] = $menu_link;
     $storage->expects($this->once())->method('loadMultiple')->with(array(1, 2, 3))->will($this->returnValue($links));
     $this->menuTree->setStorage($storage);
     // Ensure that static/non static caching works.
     // First setup no working caching.
     $this->cacheBackend->expects($this->at(0))->method('get')->with('links:test_menu:tree-data:en:35786c7117b4e38d0f169239752ce71158266ae2f6e4aa230fbbb87bd699c0e3')->will($this->returnValue(FALSE));
     $this->cacheBackend->expects($this->at(1))->method('set')->with('links:test_menu:tree-data:en:35786c7117b4e38d0f169239752ce71158266ae2f6e4aa230fbbb87bd699c0e3', $this->anything(), Cache::PERMANENT, array('menu' => 'test_menu'));
     // Ensure that the static caching triggered.
     $this->cacheBackend->expects($this->exactly(1))->method('get');
     $this->menuTree->buildTree('test_menu');
     $this->menuTree->buildTree('test_menu');
 }
 /**
  * {@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->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('getDefaultLanguage')->will($this->returnValue(new Language(array('langcode' => 'en'))));
     $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->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);
 }
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     $this->id = 1;
     $values = array('id' => $this->id, 'langcode' => 'en', 'uuid' => '3bb9ee60-bea5-4622-b89b-a63319d10b3a');
     $this->entityTypeId = $this->randomName();
     $this->bundle = $this->randomName();
     $this->entityType = $this->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
     $this->entityType->expects($this->any())->method('getKeys')->will($this->returnValue(array('id' => 'id', 'uuid' => 'uuid')));
     $this->entityManager = $this->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface');
     $this->entityManager->expects($this->any())->method('getDefinition')->with($this->entityTypeId)->will($this->returnValue($this->entityType));
     $this->uuid = $this->getMock('\\Drupal\\Component\\Uuid\\UuidInterface');
     $this->typedDataManager = $this->getMockBuilder('\\Drupal\\Core\\TypedData\\TypedDataManager')->disableOriginalConstructor()->getMock();
     $language = new Language(array('id' => 'en'));
     $this->languageManager = $this->getMock('\\Drupal\\Core\\Language\\LanguageManagerInterface');
     $this->languageManager->expects($this->any())->method('getLanguages')->will($this->returnValue(array('en' => $language)));
     $this->languageManager->expects($this->any())->method('getLanguage')->with('en')->will($this->returnValue($language));
     $this->fieldTypePluginManager = $this->getMockBuilder('\\Drupal\\Core\\Field\\FieldTypePluginManager')->disableOriginalConstructor()->getMock();
     $this->fieldTypePluginManager->expects($this->any())->method('getDefaultSettings')->will($this->returnValue(array()));
     $this->fieldTypePluginManager->expects($this->any())->method('getDefaultInstanceSettings')->will($this->returnValue(array()));
     $container = new ContainerBuilder();
     $container->set('entity.manager', $this->entityManager);
     $container->set('uuid', $this->uuid);
     $container->set('typed_data_manager', $this->typedDataManager);
     $container->set('language_manager', $this->languageManager);
     $container->set('plugin.manager.field.field_type', $this->fieldTypePluginManager);
     \Drupal::setContainer($container);
     $this->fieldDefinitions = array('id' => FieldDefinition::create('integer'), 'revision_id' => FieldDefinition::create('integer'));
     $this->entityManager->expects($this->any())->method('getFieldDefinitions')->with($this->entityTypeId, $this->bundle)->will($this->returnValue($this->fieldDefinitions));
     $this->entity = $this->getMockForAbstractClass('\\Drupal\\Core\\Entity\\ContentEntityBase', array($values, $this->entityTypeId, $this->bundle));
 }
Exemplo n.º 9
0
 /**
  * @covers ::getInfo
  */
 public function testGetInfo()
 {
     $token_info = array('types' => array('foo' => array('name' => $this->randomMachineName())));
     $this->language->expects($this->atLeastOnce())->method('getId')->will($this->returnValue($this->randomMachineName()));
     $this->languageManager->expects($this->once())->method('getCurrentLanguage')->with(LanguageInterface::TYPE_CONTENT)->will($this->returnValue($this->language));
     // The persistent cache must only be hit once, after which the info is
     // cached statically.
     $this->cache->expects($this->once())->method('get');
     $this->cache->expects($this->once())->method('set')->with('token_info:' . $this->language->getId(), $token_info);
     $this->moduleHandler->expects($this->once())->method('invokeAll')->with('token_info')->will($this->returnValue($token_info));
     $this->moduleHandler->expects($this->once())->method('alter')->with('token_info', $token_info);
     // Get the information for the first time. The cache should be checked, the
     // hooks invoked, and the info should be set to the cache should.
     $this->token->getInfo();
     // Get the information for the second time. The data must be returned from
     // the static cache, so the persistent cache must not be accessed and the
     // hooks must not be invoked.
     $this->token->getInfo();
 }
Exemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->values = array('id' => 1, 'langcode' => 'en', 'uuid' => '3bb9ee60-bea5-4622-b89b-a63319d10b3a');
     $this->entityTypeId = $this->randomMachineName();
     $this->entityType = $this->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
     $this->entityType->expects($this->any())->method('getListCacheTags')->willReturn(array($this->entityTypeId . '_list'));
     $this->entityManager = $this->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface');
     $this->entityManager->expects($this->any())->method('getDefinition')->with($this->entityTypeId)->will($this->returnValue($this->entityType));
     $this->uuid = $this->getMock('\\Drupal\\Component\\Uuid\\UuidInterface');
     $this->languageManager = $this->getMock('\\Drupal\\Core\\Language\\LanguageManagerInterface');
     $this->languageManager->expects($this->any())->method('getLanguage')->with('en')->will($this->returnValue(new Language(array('id' => 'en'))));
     $this->cacheTagsInvalidator = $this->getMock('Drupal\\Core\\Cache\\CacheTagsInvalidator');
     $container = new ContainerBuilder();
     $container->set('entity.manager', $this->entityManager);
     $container->set('uuid', $this->uuid);
     $container->set('language_manager', $this->languageManager);
     $container->set('cache_tags.invalidator', $this->cacheTagsInvalidator);
     \Drupal::setContainer($container);
     $this->entity = $this->getMockForAbstractClass('\\Drupal\\Core\\Entity\\Entity', array($this->values, $this->entityTypeId));
 }
Exemplo n.º 11
0
 /**
  * Tests for the Entity::toLink() method
  *
  * @covers ::toLink
  *
  * @dataProvider providerTestLink
  */
 public function testToLink($entity_label, $link_text, $expected_text, $link_rel = 'canonical', array $link_options = [])
 {
     $language = new Language(['id' => 'es']);
     $link_options += ['language' => $language];
     $this->languageManager->expects($this->any())->method('getLanguage')->with('es')->willReturn($language);
     $route_name_map = ['canonical' => 'entity.test_entity_type.canonical', 'edit-form' => 'entity.test_entity_type.edit_form'];
     $route_name = $route_name_map[$link_rel];
     $entity_id = 'test_entity_id';
     $entity_type_id = 'test_entity_type';
     $expected = '<a href="/test_entity_type/test_entity_id">' . $expected_text . '</a>';
     $entity_type = $this->getMock('Drupal\\Core\\Entity\\EntityTypeInterface');
     $entity_type->expects($this->once())->method('getLinkTemplates')->willReturn($route_name_map);
     $entity_type->expects($this->any())->method('getKey')->willReturnMap([['label', 'label'], ['langcode', 'langcode']]);
     $this->entityManager->expects($this->any())->method('getDefinition')->with($entity_type_id)->will($this->returnValue($entity_type));
     /** @var \Drupal\Core\Entity\Entity $entity */
     $entity = $this->getMockForAbstractClass('Drupal\\Core\\Entity\\Entity', [['id' => $entity_id, 'label' => $entity_label, 'langcode' => 'es'], $entity_type_id]);
     $expected_link = Link::createFromRoute($expected_text, $route_name, [$entity_type_id => $entity_id], ['entity_type' => $entity_type_id, 'entity' => $entity] + $link_options);
     $result_link = $entity->toLink($link_text, $link_rel, $link_options);
     $this->assertEquals($expected_link, $result_link);
 }
Exemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->libraryDiscovery = $this->getMockBuilder('Drupal\\Core\\Asset\\LibraryDiscovery')->disableOriginalConstructor()->getMock();
     $this->libraryDependencyResolver = $this->getMock('\\Drupal\\Core\\Asset\\LibraryDependencyResolverInterface');
     $this->libraryDependencyResolver->expects($this->any())->method('getLibrariesWithDependencies')->willReturnArgument(0);
     $this->moduleHandler = $this->getMock('\\Drupal\\Core\\Extension\\ModuleHandlerInterface');
     $this->themeManager = $this->getMock('\\Drupal\\Core\\Theme\\ThemeManagerInterface');
     $active_theme = $this->getMockBuilder('\\Drupal\\Core\\Theme\\ActiveTheme')->disableOriginalConstructor()->getMock();
     $active_theme->expects($this->any())->method('getName')->willReturn('bartik');
     $this->themeManager->expects($this->any())->method('getActiveTheme')->willReturn($active_theme);
     $this->languageManager = $this->getMock('\\Drupal\\Core\\Language\\LanguageManagerInterface');
     $english = $this->getMock('\\Drupal\\Core\\Language\\LanguageInterface');
     $english->expects($this->any())->method('getId')->willReturn('en');
     $japanese = $this->getMock('\\Drupal\\Core\\Language\\LanguageInterface');
     $japanese->expects($this->any())->method('getId')->willReturn('jp');
     $this->languageManager = $this->getMock('\\Drupal\\Core\\Language\\LanguageManagerInterface');
     $this->languageManager->expects($this->any())->method('getCurrentLanguage')->will($this->onConsecutiveCalls($english, $english, $japanese, $japanese));
     $this->cache = new TestMemoryBackend('llama');
     $this->assetResolver = new AssetResolver($this->libraryDiscovery, $this->libraryDependencyResolver, $this->moduleHandler, $this->themeManager, $this->languageManager, $this->cache);
 }
Exemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->entityType = $this->getMock('Drupal\\Core\\Entity\\ContentEntityTypeInterface');
     $this->entityType->expects($this->any())->method('id')->will($this->returnValue($this->entityTypeId));
     $this->container = new ContainerBuilder();
     \Drupal::setContainer($this->container);
     $this->entityManager = $this->getMock('Drupal\\Core\\Entity\\EntityManagerInterface');
     $this->moduleHandler = $this->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
     $this->cache = $this->getMock('Drupal\\Core\\Cache\\CacheBackendInterface');
     $this->languageManager = $this->getMock('Drupal\\Core\\Language\\LanguageManagerInterface');
     $this->languageManager->expects($this->any())->method('getDefaultLanguage')->will($this->returnValue(new Language(array('langcode' => 'en'))));
     $this->connection = $this->getMockBuilder('Drupal\\Core\\Database\\Connection')->disableOriginalConstructor()->getMock();
 }
Exemplo n.º 14
0
 /**
  * @covers ::getExtraFields
  */
 function testgetExtraFields()
 {
     $this->setUpEntityManager();
     $entity_type_id = $this->randomMachineName();
     $bundle = $this->randomMachineName();
     $language_code = 'en';
     $hook_bundle_extra_fields = array($entity_type_id => array($bundle => array('form' => array('foo_extra_field' => array('label' => 'Foo')))));
     $processed_hook_bundle_extra_fields = $hook_bundle_extra_fields;
     $processed_hook_bundle_extra_fields[$entity_type_id][$bundle] += array('display' => array());
     $cache_id = 'entity_bundle_extra_fields:' . $entity_type_id . ':' . $bundle . ':' . $language_code;
     $language = new Language(array('id' => $language_code));
     $this->languageManager->expects($this->once())->method('getCurrentLanguage')->will($this->returnValue($language));
     $this->cacheBackend->expects($this->once())->method('get')->with($cache_id);
     $this->moduleHandler->expects($this->once())->method('invokeAll')->with('entity_extra_field_info')->will($this->returnValue($hook_bundle_extra_fields));
     $this->moduleHandler->expects($this->once())->method('alter')->with('entity_extra_field_info', $hook_bundle_extra_fields);
     $this->cacheBackend->expects($this->once())->method('set')->with($cache_id, $processed_hook_bundle_extra_fields[$entity_type_id][$bundle]);
     $this->assertSame($processed_hook_bundle_extra_fields[$entity_type_id][$bundle], $this->entityManager->getExtraFields($entity_type_id, $bundle));
 }
 /**
  * Prepares the key value entity storage.
  *
  * @covers ::__construct()
  *
  * @param string $uuid_key
  *   (optional) The entity key used for the UUID. Defaults to 'uuid'.
  */
 protected function setUpKeyValueEntityStorage($uuid_key = 'uuid')
 {
     $this->entityType->expects($this->atLeastOnce())->method('getKey')->will($this->returnValueMap(array(array('id', 'id'), array('uuid', $uuid_key))));
     $this->entityType->expects($this->atLeastOnce())->method('id')->will($this->returnValue('test_entity_type'));
     $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->keyValueStore = $this->getMock('Drupal\\Core\\KeyValueStore\\KeyValueStoreInterface');
     $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->entityStorage = new KeyValueEntityStorage($this->entityType, $this->keyValueStore, $this->uuidService, $this->languageManager);
     $this->entityStorage->setModuleHandler($this->moduleHandler);
     $container = new ContainerBuilder();
     $container->set('entity.manager', $this->entityManager);
     $container->set('language_manager', $this->languageManager);
     $container->set('cache.test', $this->cacheBackend);
     $container->setParameter('cache_bins', array('cache.test' => 'test'));
     \Drupal::setContainer($container);
 }
Exemplo n.º 16
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->id = 1;
     $values = array('id' => $this->id, 'uuid' => '3bb9ee60-bea5-4622-b89b-a63319d10b3a', 'defaultLangcode' => array(LanguageInterface::LANGCODE_DEFAULT => 'en'));
     $this->entityTypeId = $this->randomMachineName();
     $this->bundle = $this->randomMachineName();
     $this->entityType = $this->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
     $this->entityType->expects($this->any())->method('getKeys')->will($this->returnValue(array('id' => 'id', 'uuid' => 'uuid')));
     $this->entityManager = $this->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface');
     $this->entityManager->expects($this->any())->method('getDefinition')->with($this->entityTypeId)->will($this->returnValue($this->entityType));
     $this->uuid = $this->getMock('\\Drupal\\Component\\Uuid\\UuidInterface');
     $this->typedDataManager = $this->getMockBuilder('\\Drupal\\Core\\TypedData\\TypedDataManager')->disableOriginalConstructor()->getMock();
     $this->typedDataManager->expects($this->any())->method('getDefinition')->with('entity')->will($this->returnValue(['class' => '\\Drupal\\Core\\Entity\\Plugin\\DataType\\EntityAdapter']));
     $this->typedDataManager->expects($this->any())->method('getDefaultConstraints')->willReturn([]);
     $validation_constraint_manager = $this->getMockBuilder('\\Drupal\\Core\\Validation\\ConstraintManager')->disableOriginalConstructor()->getMock();
     $validation_constraint_manager->expects($this->any())->method('create')->willReturn([]);
     $this->typedDataManager->expects($this->any())->method('getValidationConstraintManager')->willReturn($validation_constraint_manager);
     $not_specified = new Language(array('id' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'locked' => TRUE));
     $this->languageManager = $this->getMock('\\Drupal\\Core\\Language\\LanguageManagerInterface');
     $this->languageManager->expects($this->any())->method('getLanguages')->will($this->returnValue(array(LanguageInterface::LANGCODE_NOT_SPECIFIED => $not_specified)));
     $this->languageManager->expects($this->any())->method('getLanguage')->with(LanguageInterface::LANGCODE_NOT_SPECIFIED)->will($this->returnValue($not_specified));
     $this->fieldTypePluginManager = $this->getMockBuilder('\\Drupal\\Core\\Field\\FieldTypePluginManager')->disableOriginalConstructor()->getMock();
     $this->fieldTypePluginManager->expects($this->any())->method('getDefaultStorageSettings')->will($this->returnValue(array()));
     $this->fieldTypePluginManager->expects($this->any())->method('getDefaultFieldSettings')->will($this->returnValue(array()));
     $this->fieldItemList = $this->getMock('\\Drupal\\Core\\Field\\FieldItemListInterface');
     $this->fieldTypePluginManager->expects($this->any())->method('createFieldItemList')->willReturn($this->fieldItemList);
     $container = new ContainerBuilder();
     $container->set('entity.manager', $this->entityManager);
     $container->set('uuid', $this->uuid);
     $container->set('typed_data_manager', $this->typedDataManager);
     $container->set('language_manager', $this->languageManager);
     $container->set('plugin.manager.field.field_type', $this->fieldTypePluginManager);
     \Drupal::setContainer($container);
     $this->fieldDefinitions = array('id' => BaseFieldDefinition::create('integer'), 'revision_id' => BaseFieldDefinition::create('integer'));
     $this->entityManager->expects($this->any())->method('getFieldDefinitions')->with($this->entityTypeId, $this->bundle)->will($this->returnValue($this->fieldDefinitions));
     $this->entity = $this->getMockForAbstractClass('\\Drupal\\Core\\Entity\\ContentEntityBase', array($values, $this->entityTypeId, $this->bundle));
     $this->entityAdapter = EntityAdapter::createFromEntity($this->entity);
 }
Exemplo n.º 17
0
 /**
  * Tests locale lookups with fallback.
  *
  * Note that context is irrelevant here. It is not used but it is required.
  *
  * @covers ::resolveCacheMiss
  *
  * @dataProvider resolveCacheMissWithFallbackProvider
  */
 public function testResolveCacheMissWithFallback($langcode, $string, $context, $expected)
 {
     // These are fake words!
     $translations = array('en' => array('test' => 'test', 'fake' => 'fake', 'missing pl' => 'missing pl', 'missing cs' => 'missing cs', 'missing both' => 'missing both'), 'pl' => array('test' => 'test po polsku', 'fake' => 'ściema', 'missing cs' => 'zaginiony czech'), 'cs' => array('test' => 'test v české', 'fake' => 'falešný', 'missing pl' => 'chybějící pl'));
     $this->storage->expects($this->any())->method('findTranslation')->will($this->returnCallback(function ($argument) use($translations) {
         if (isset($translations[$argument['language']][$argument['source']])) {
             return (object) array('translation' => $translations[$argument['language']][$argument['source']]);
         }
         return TRUE;
     }));
     $this->languageManager->expects($this->any())->method('getFallbackCandidates')->will($this->returnCallback(function (array $context = array()) {
         switch ($context['langcode']) {
             case 'pl':
                 return array('cs', 'en');
             case 'cs':
                 return array('en');
             default:
                 return array();
         }
     }));
     $this->cache->expects($this->once())->method('get')->with('locale:' . $langcode . ':' . $context . ':anonymous', FALSE);
     $locale_lookup = new LocaleLookup($langcode, $context, $this->storage, $this->cache, $this->lock, $this->configFactory, $this->languageManager, $this->requestStack);
     $this->assertSame($expected, $locale_lookup->get($string));
 }
 /**
  * @covers ::isTranslatable
  */
 public function testIsTranslatableForMonolingual()
 {
     $this->languageManager->expects($this->any())->method('isMultilingual')->will($this->returnValue(FALSE));
     $this->assertFalse($this->entity->isTranslatable());
 }
Exemplo n.º 19
0
 /**
  * @covers ::create
  * @covers ::doCreate
  */
 public function testCreateWithExplicitLanguage()
 {
     $this->languageManager->expects($this->any())->method('getLanguage')->with('en')->willReturn(new Language(array('id' => 'en')));
     $entity = $this->entityStorage->create(array('id' => 'foo', 'langcode' => 'en'));
     $this->assertSame('en', $entity->language()->getId());
 }
Exemplo n.º 20
0
 /**
  * Sets up the current language.
  *
  * @return \Drupal\Core\Language\LanguageInterface
  *   The current language object.
  */
 protected function setUpCurrentLanguage()
 {
     $language = new Language(array('id' => 'en'));
     $this->languageManager->expects($this->any())->method('getCurrentLanguage')->with(LanguageInterface::TYPE_URL)->will($this->returnValue($language));
     return $language;
 }