public function testPersist()
 {
     $route = new Route();
     $root = self::$dm->find(null, self::ROUTE_ROOT);
     $route->setRouteContent($root);
     // this happens to be a referenceable node
     $route->setPosition($root, 'testroute');
     $route->setDefault('x', 'y');
     $route->setRequirement('testreq', 'testregex');
     $route->setOptions(array('test' => 'value'));
     $route->setOption('another', 'value2');
     self::$dm->persist($route);
     self::$dm->flush();
     $this->assertEquals('/testroute', $route->getPattern());
     self::$dm->clear();
     $route = self::$dm->find(null, self::ROUTE_ROOT . '/testroute');
     $this->assertNotNull($route->getRouteContent());
     $this->assertEquals('/testroute', $route->getPattern());
     $this->assertEquals('y', $route->getDefault('x'));
     $defaults = $route->getDefaults();
     $this->assertArrayHasKey('x', $defaults);
     $this->assertEquals('y', $defaults['x']);
     $requirements = $route->getRequirements();
     $this->assertArrayHasKey('testreq', $requirements);
     $this->assertEquals('testregex', $requirements['testreq']);
     $options = $route->getOptions();
     $this->assertArrayHasKey('test', $options);
     $this->assertEquals('value', $options['test']);
     $this->assertArrayHasKey('another', $options);
     $this->assertEquals('value2', $options['another']);
 }
 /**
  * @expectedException \Symfony\Component\Routing\Exception\MethodNotAllowedException
  */
 public function testNotAllowed()
 {
     $root = self::$dm->find(null, self::ROUTE_ROOT);
     // do not set a content here, or we need a valid request and so on...
     $route = new Route();
     $route->setPosition($root, 'notallowed');
     $route->setRequirement('_method', 'GET');
     $route->setDefault(RouteObjectInterface::CONTROLLER_NAME, 'testController');
     self::$dm->persist($route);
     self::$dm->flush();
     self::$router->matchRequest(Request::create('/notallowed', 'POST'));
 }
 protected function updateLocale(Route $doc, $id)
 {
     $matches = array();
     // only update route objects and only if the prefix can match, to allow
     // for more than one listener and more than one route root
     if (!preg_match('#' . $this->idPrefix . '/([^/]+)(/|$)#', $id, $matches)) {
         return;
     }
     if (in_array($matches[1], $this->locales) && !$doc->getDefault('_locale') && !$doc->getRequirement('_locale')) {
         $doc->setDefault('_locale', $matches[1]);
         $doc->setRequirement('_locale', $matches[1]);
     }
 }