Example #1
0
 /**
  * {@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);
 }
 /**
  * Prepares the language manager for testing.
  */
 protected function prepareLanguageManager()
 {
     $language_code = $this->randomMachineName(2);
     $language = $this->getMock(LanguageInterface::class);
     $language->expects($this->atLeastOnce())->method('getId')->willReturn($language_code);
     $this->languageManager->expects($this->any())->method('getCurrentLanguage')->with(Language::TYPE_CONTENT)->willReturn($language);
 }
Example #3
0
 /**
  * @covers ::getInfo
  */
 public function testGetInfo()
 {
     $token_info = array('types' => array('foo' => array('name' => $this->randomMachineName())));
     $language = $this->getMock('\\Drupal\\Core\\Language\\Language');
     $language->id = $this->randomMachineName();
     $this->languageManager->expects($this->once())->method('getCurrentLanguage')->with(LanguageInterface::TYPE_CONTENT)->will($this->returnValue($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:' . $language->id, $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();
 }
Example #4
0
 /**
  * @covers ::getExtraFields
  */
 function testgetExtraFields()
 {
     $this->setUpEntityManager();
     $entity_type_id = $this->randomName();
     $bundle = $this->randomName();
     $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();
     $language->id = $language_code;
     $this->languageManager->expects($this->once())->method('getCurrentLanguage')->will($this->returnValue($language));
     $this->cache->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->cache->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));
 }