Thomas Rabaix 11 年之前
父節點
當前提交
6fd913e5bf
共有 3 個文件被更改,包括 20 次插入15 次删除
  1. 1 7
      Admin/Admin.php
  2. 15 1
      Admin/AdminInterface.php
  3. 4 7
      Tests/Controller/HelperControllerTest.php

+ 1 - 7
Admin/Admin.php

@@ -1116,13 +1116,7 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
     }
 
     /**
-     * Generates the object url with the given $name
-     *
-     * @param string $name
-     * @param mixed  $object
-     * @param array  $parameters
-     *
-     * @return string return a complete url
+     * {@inheritdoc}
      */
     public function generateObjectUrl($name, $object, array $parameters = array(), $absolute = false)
     {

+ 15 - 1
Admin/AdminInterface.php

@@ -99,11 +99,25 @@ interface AdminInterface
     public function getDatagrid();
 
     /**
+     * Generates the object url with the given $name
+     *
+     * @param string  $name
+     * @param mixed   $object
+     * @param array   $parameters
+     * @param boolean $absolute
+     *
+     * @return string return a complete url
+     */
+    public function generateObjectUrl($name, $object, array $parameters = array(), $absolute = false);
+
+    /**
+     * Generates an url for the given parameters
+     *
      * @param string $name
      * @param array  $parameters
      * @param bool   $absolute
      *
-     * @return string
+     * @return string return a complete url
      */
     public function generateUrl($name, array $parameters = array(), $absolute = false);
 

+ 4 - 7
Tests/Controller/HelperControllerTest.php

@@ -95,17 +95,14 @@ class HelperControllerTest extends \PHPUnit_Framework_TestCase
         $admin->expects($this->once())->method('setUniqid');
         $admin->expects($this->once())->method('getTemplate')->will($this->returnValue($mockTemplate));
         $admin->expects($this->once())->method('getObject')->will($this->returnValue(new AdminControllerHelper_Foo));
-        $admin->expects($this->once())->method('generateUrl')->will($this->returnCallback(function($name, $parameters) {
-            if ($name != 'edit') {
+        $admin->expects($this->once())->method('generateObjectUrl')->will($this->returnCallback(function($type, $object, $parameters = array()) {
+            if ($type != 'edit') {
                 return 'invalid name';
             }
 
-            if (!isset($parameters['id'])) {
-                return 'id parameter not set';
-            }
-
             return '/ok/url';
         }));
+
         $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
         $container->expects($this->any())->method('get')->will($this->returnValue($admin));
 
@@ -114,7 +111,7 @@ class HelperControllerTest extends \PHPUnit_Framework_TestCase
         $twig->expects($this->once())->method('render')
             ->with($mockTemplate)
             ->will($this->returnCallback(function($templateName, $templateParams) {
-                return sprintf('<a href="%s" target="new">%s</a>', $templateParams['url'], $templateParams['description']);
+                return sprintf('<a href="%s" target="new">%s</a>', $templateParams['admin']->generateObjectUrl('edit', $templateParams['object']), $templateParams['description']);
             }));
 
         $request = new Request(array(