Browse Source

added Router::nameExists()

fixed

method moved to RouteBuilder

moved test

removed usefull method

fixed empty spaces

fixed empty spaces

added empty line

added empty line
Mirko Pagliai 9 years ago
parent
commit
55b1db4179
2 changed files with 27 additions and 0 deletions
  1. 11 0
      src/Routing/RouteBuilder.php
  2. 16 0
      tests/TestCase/Routing/RouteBuilderTest.php

+ 11 - 0
src/Routing/RouteBuilder.php

@@ -197,6 +197,17 @@ class RouteBuilder
     }
 
     /**
+     * Checks if there is already a route with a given name.
+     *
+     * @param string $name Name.
+     * @return bool
+     */
+    public function nameExists($name)
+    {
+        return array_key_exists($name, $this->_collection->named());
+    }
+
+    /**
      * Get/set the name prefix for this scope.
      *
      * Modifying the name prefix will only change the prefix

+ 16 - 0
tests/TestCase/Routing/RouteBuilderTest.php

@@ -170,6 +170,22 @@ class RouteBuilderTest extends TestCase
     }
 
     /**
+     * Test if a route name already exist
+     *
+     * @return void
+     */
+    public function testNameExists()
+    {
+        $routes = new RouteBuilder($this->collection, '/l', ['prefix' => 'api']);
+
+        $this->assertFalse($routes->nameExists('myRouteName'));
+
+        $routes->connect('myRouteUrl', ['action' => 'index'], ['_name' => 'myRouteName']);
+
+        $this->assertTrue($routes->nameExists('myRouteName'));
+    }
+
+    /**
      * Test extensions being connected to routes.
      *
      * @return void