コード例 #1
0
 public function testConvertsSimpleXmlElementToObject()
 {
     $xml = new SimpleXMLElement(file_get_contents(__DIR__ . DS . "fixtures" . DS . "routing.xml"));
     $parser = new RoutingParser();
     $routes = $parser->parseRoutes($xml);
     $this->assertTrue(is_array($routes));
     $this->assertCount(2, $routes);
     $this->assertArrayHasKey("foo", $routes);
     $this->assertArrayHasKey("bar", $routes);
     /** @var \TheliaStudio\Parser\Entity\Route $fooRoute */
     $fooRoute = $routes["foo"];
     /** @var \TheliaStudio\Parser\Entity\Route $barRoute */
     $barRoute = $routes["bar"];
     $this->assertInstanceOf("TheliaStudio\\Parser\\Entity\\Route", $fooRoute);
     $this->assertInstanceOf("TheliaStudio\\Parser\\Entity\\Route", $barRoute);
     $this->assertEquals("foo", $fooRoute->getId());
     $this->assertEquals("/a/path", $fooRoute->getPath());
     $this->assertNull($fooRoute->getMethods());
     $this->assertEmpty($fooRoute->getDefaults());
     $this->assertEmpty($fooRoute->getRequirements());
     $this->assertEquals("bar", $barRoute->getId());
     $this->assertEquals("/another/path/{baz}", $barRoute->getPath());
     $this->assertEquals("get", $barRoute->getMethods());
     $this->assertEquals(["_controller" => "A:B:C"], $barRoute->getDefaults());
     $this->assertEquals(["baz" => "\\d+"], $barRoute->getRequirements());
 }
コード例 #2
0
 public function testRouting()
 {
     $xml = new SimpleXMLElement(file_get_contents($this->getStreamPath("Config/routing.xml")));
     $parser = new RoutingParser();
     $generatedRoutes = array_keys($parser->parseRoutes($xml));
     $routes = ["theliastudiotestmodule.configuration.default", "theliastudiotestmodule.configuration.save"];
     sort($routes);
     sort($generatedRoutes);
     $this->assertEquals($routes, $generatedRoutes);
 }
コード例 #3
0
 public function testInsertForms()
 {
     $xml = new SimpleXMLElement(file_get_contents($this->getStreamPath("Config/routing.xml")));
     $parser = new RoutingParser();
     $generatedRoutes = array_keys($parser->parseRoutes($xml));
     $routes = ["theliastudiotestmodule.example_table.list", "theliastudiotestmodule.example_table.create", "theliastudiotestmodule.example_table.view", "theliastudiotestmodule.example_table.edit", "theliastudiotestmodule.example_table.delete", "theliastudiotestmodule.example_table.update_position", "theliastudiotestmodule.example_table.toggle_visibility"];
     sort($routes);
     sort($generatedRoutes);
     $this->assertEquals($routes, $generatedRoutes);
 }
コード例 #4
0
 protected function parseRoutingXml($modulePath)
 {
     $routingData = @file_get_contents($routingPath = $modulePath . "Config" . DS . "routing.xml");
     if (false === $routingData) {
         $routingData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><routes xmlns=\"http://symfony.com/schema/routing\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd\"></routes>";
     }
     $routingParser = new RoutingParser();
     $xml = new SimpleXMLElement($routingData);
     /** @var \TheliaStudio\Parser\Entity\Route[] $routes */
     $routes = $routingParser->parseRoutes($xml);
     return [$xml, $routingPath, $routes];
 }