예제 #1
0
 /**
  * Tests that route caching works.
  */
 public function testRouteCaching()
 {
     $connection = Database::getConnection();
     $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->pathProcessor, $this->cacheTagsInvalidator, 'test_routes');
     $this->fixtures->createTables($connection);
     $dumper = new MatcherDumper($connection, $this->state, 'test_routes');
     $dumper->addRoutes($this->fixtures->sampleRouteCollection());
     $dumper->addRoutes($this->fixtures->complexRouteCollection());
     $dumper->dump();
     // A simple path.
     $path = '/path/add/one';
     $request = Request::create($path, 'GET');
     $provider->getRouteCollectionForRequest($request);
     $cache = $this->cache->get('route:/path/add/one:');
     $this->assertEqual('/path/add/one', $cache->data['path']);
     $this->assertEqual([], $cache->data['query']);
     $this->assertEqual(3, count($cache->data['routes']));
     // A path with query parameters.
     $path = '/path/add/one?foo=bar';
     $request = Request::create($path, 'GET');
     $provider->getRouteCollectionForRequest($request);
     $cache = $this->cache->get('route:/path/add/one:foo=bar');
     $this->assertEqual('/path/add/one', $cache->data['path']);
     $this->assertEqual(['foo' => 'bar'], $cache->data['query']);
     $this->assertEqual(3, count($cache->data['routes']));
     // A path with placeholders.
     $path = '/path/1/one';
     $request = Request::create($path, 'GET');
     $provider->getRouteCollectionForRequest($request);
     $cache = $this->cache->get('route:/path/1/one:');
     $this->assertEqual('/path/1/one', $cache->data['path']);
     $this->assertEqual([], $cache->data['query']);
     $this->assertEqual(2, count($cache->data['routes']));
     // A path with a path alias.
     /** @var \Drupal\Core\Path\AliasStorageInterface $path_storage */
     $path_storage = \Drupal::service('path.alias_storage');
     $path_storage->save('/path/add/one', '/path/add-one');
     /** @var \Drupal\Core\Path\AliasManagerInterface $alias_manager */
     $alias_manager = \Drupal::service('path.alias_manager');
     $alias_manager->cacheClear();
     $path = '/path/add-one';
     $request = Request::create($path, 'GET');
     $provider->getRouteCollectionForRequest($request);
     $cache = $this->cache->get('route:/path/add-one:');
     $this->assertEqual('/path/add/one', $cache->data['path']);
     $this->assertEqual([], $cache->data['query']);
     $this->assertEqual(3, count($cache->data['routes']));
 }
 /**
  * Test fall through to file storage on a cache miss in CachedStorage::read().
  */
 public function testReadNonExistentFileCacheMiss()
 {
     $name = 'config.does_not_exist';
     $cache = new MemoryBackend(__FUNCTION__);
     $storage = $this->getMock('Drupal\\Core\\Config\\StorageInterface');
     $storage->expects($this->once())->method('read')->with($name)->will($this->returnValue(FALSE));
     $cachedStorage = new CachedStorage($storage, $cache);
     $this->assertFalse($cachedStorage->read($name));
     // Ensure that the a missing file is cached.
     $entry = $cache->get('config.does_not_exist');
     $this->assertFalse($entry->data);
 }