浏览代码

feat(admin): add object name to ajax response for edit

Quentin Somazzi 9 年之前
父节点
当前提交
2e851f061e
共有 2 个文件被更改,包括 8 次插入3 次删除
  1. 3 2
      Controller/CRUDController.php
  2. 5 1
      Tests/Controller/CRUDControllerTest.php

+ 3 - 2
Controller/CRUDController.php

@@ -415,8 +415,9 @@ class CRUDController extends Controller
 
                     if ($this->isXmlHttpRequest($request)) {
                         return $this->renderJson(array(
-                            'result'    => 'ok',
-                            'objectId'  => $this->admin->getNormalizedIdentifier($object),
+                            'result'     => 'ok',
+                            'objectId'   => $this->admin->getNormalizedIdentifier($object),
+                            'objectName' => $this->escapeHtml($this->admin->toString($object)),
                         ), 200, array(), $request);
                     }
 

+ 5 - 1
Tests/Controller/CRUDControllerTest.php

@@ -1538,13 +1538,17 @@ class CRUDControllerTest extends \PHPUnit_Framework_TestCase
             ->with($this->equalTo($object))
             ->will($this->returnValue('foo_normalized'));
 
+        $this->admin->expects($this->once())
+            ->method('toString')
+            ->will($this->returnValue('foo'));
+
         $this->request->setMethod('POST');
         $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
 
         $response = $this->controller->editAction(null, $this->request);
 
         $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
-        $this->assertEquals(json_encode(array('result' => 'ok', 'objectId'  => 'foo_normalized')), $response->getContent());
+        $this->assertEquals(json_encode(array('result' => 'ok', 'objectId'  => 'foo_normalized', 'objectName' => 'foo')), $response->getContent());
         $this->assertEquals(array(), $this->session->getFlashBag()->all());
     }