コード例 #1
0
 /**
  * Test listAll static cache.
  */
 public function testListAllStaticCache()
 {
     $prefix = __FUNCTION__;
     $storage = $this->getMock('Drupal\\Core\\Config\\StorageInterface');
     $response = array("{$prefix}." . $this->randomMachineName(), "{$prefix}." . $this->randomMachineName());
     $storage->expects($this->once())->method('listAll')->with($prefix)->will($this->returnValue($response));
     $cache = new NullBackend(__FUNCTION__);
     $cachedStorage = new CachedStorage($storage, $cache);
     $this->assertEquals($response, $cachedStorage->listAll($prefix));
     $this->assertEquals($response, $cachedStorage->listAll($prefix));
 }
コード例 #2
0
 protected function getConfigNames($config_type)
 {
     // For a given entity type, load all entities.
     if ($config_type && $config_type !== 'system.simple') {
         $entity_storage = $this->entityManager->getStorage($config_type);
         foreach ($entity_storage->loadMultiple() as $entity) {
             $entity_id = $entity->id();
             $label = $entity->label() ?: $entity_id;
             $names[$entity_id] = $label;
         }
     } else {
         // Gather the config entity prefixes.
         $config_prefixes = array_map(function ($definition) {
             return $definition->getConfigPrefix() . '.';
         }, $this->definitions);
         // Find all config, and then filter our anything matching a config prefix.
         $names = $this->configStorage->listAll();
         $names = array_combine($names, $names);
         foreach ($names as $config_name) {
             foreach ($config_prefixes as $config_prefix) {
                 if (strpos($config_name, $config_prefix) === 0) {
                     unset($names[$config_name]);
                 }
             }
         }
     }
     return $names;
 }
コード例 #3
0
 /**
  * Test CachedStorage::listAll() persistent cache.
  */
 public function testListAllPrimedPersistentCache()
 {
     $prefix = __FUNCTION__;
     $storage = $this->getMock('Drupal\\Core\\Config\\StorageInterface');
     $storage->expects($this->never())->method('listAll');
     $response = array("{$prefix}." . $this->randomMachineName(), "{$prefix}." . $this->randomMachineName());
     $cache = new MemoryBackend(__FUNCTION__);
     $cache->set('find:' . $prefix, $response);
     $cachedStorage = new CachedStorage($storage, $cache);
     $this->assertEquals($response, $cachedStorage->listAll($prefix));
 }