فهرست منبع

Added the getTemplate method in the admin interface and used it to alter the affected broken test

Thanos Polymeneas 13 سال پیش
والد
کامیت
8b6f7570d8
2فایلهای تغییر یافته به همراه18 افزوده شده و 1 حذف شده
  1. 7 0
      Admin/AdminInterface.php
  2. 11 1
      Tests/Controller/AdminHelperTest.php

+ 7 - 0
Admin/AdminInterface.php

@@ -540,4 +540,11 @@ interface AdminInterface
      * @return void
      */
     function setParent(AdminInterface $admin);
+    
+    /**
+     * @param string $name
+     *
+     * @return null|string
+     */
+    public function getTemplate($name);
 }

+ 11 - 1
Tests/Controller/AdminHelperTest.php

@@ -93,8 +93,11 @@ class AdminHelperTest extends \PHPUnit_Framework_TestCase
 
     public function testgetShortObjectDescriptionActionObject()
     {
+        $mockTemplate = 'AdminHelperTest:mock-short-object-description.html.twig';
+        
         $admin = $this->getMock('Sonata\AdminBundle\Admin\AdminInterface');
         $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') {
@@ -110,7 +113,14 @@ class AdminHelperTest extends \PHPUnit_Framework_TestCase
         $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
         $container->expects($this->any())->method('get')->will($this->returnValue($admin));
 
-        $twig = new Twig;
+        $twig = $this->getMock('Twig_Environment');
+        
+        $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']);
+            }));
+            
         $request = new Request(array(
             'code'     => 'sonata.post.admin',
             'objectId' => 42,