public function testappendFormFieldElementAction() { $object = new AdminControllerHelper_Foo(); $modelManager = $this->getMock('Sonata\\AdminBundle\\Model\\ModelManagerInterface'); $modelManager->expects($this->once())->method('find')->will($this->returnValue($object)); $mockTheme = $this->getMockBuilder('Symfony\\Component\\Form\\FormView')->disableOriginalConstructor()->getMock(); $admin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface'); $admin->expects($this->once())->method('getModelManager')->will($this->returnValue($modelManager)); $admin->expects($this->once())->method('setRequest'); $admin->expects($this->once())->method('setSubject'); $admin->expects($this->once())->method('getFormTheme')->will($this->returnValue($mockTheme)); $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); $container->expects($this->any())->method('get')->will($this->returnValue($admin)); $mockRenderer = $this->getMockBuilder('Symfony\\Bridge\\Twig\\Form\\TwigRendererInterface')->disableOriginalConstructor()->getMock(); $mockRenderer->expects($this->once())->method('searchAndRenderBlock')->will($this->returnValue(new Response())); $formExtension = $this->getMock('Twig_ExtensionInterface', array('renderListElement', 'initRuntime', 'getTokenParsers', 'getNodeVisitors', 'getFilters', 'getTests', 'getFunctions', 'getOperators', 'getGlobals', 'getName')); $formExtension->expects($this->once())->method('getName')->will($this->returnValue('form')); $formExtension->expects($this->never())->method('searchAndRenderBlock'); $formExtension->expects($this->never())->method('setTheme'); $formExtension->renderer = $mockRenderer; $twig = new Twig(); $twig->addExtension($formExtension); $request = new Request(array('code' => 'sonata.post.admin', 'objectId' => 42, 'field' => 'enabled', 'value' => 1, 'context' => 'list'), array(), array(), array(), array(), array('REQUEST_METHOD' => 'POST')); $pool = new Pool($container, 'title', 'logo'); $pool->setAdminServiceIds(array('sonata.post.admin')); $validator = $this->getMock('Symfony\\Component\\Validator\\ValidatorInterface'); $mockView = $this->getMockBuilder('Symfony\\Component\\Form\\FormView')->disableOriginalConstructor()->getMock(); $mockForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock(); $mockForm->expects($this->once())->method('createView')->will($this->returnValue($mockView)); $helper = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminHelper', array('appendFormFieldElement', 'getChildFormView'), array($pool)); $helper->expects($this->once())->method('appendFormFieldElement')->will($this->returnValue(array($this->getMock('Sonata\\AdminBundle\\Admin\\FieldDescriptionInterface'), $mockForm))); $helper->expects($this->once())->method('getChildFormView')->will($this->returnValue($mockView)); $controller = new HelperController($twig, $pool, $helper, $validator); $response = $controller->appendFormFieldElementAction($request); $this->isInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response); }
public function testappendFormFieldElementAction() { $object = new AdminControllerHelper_Foo(); $modelManager = $this->getMock('Sonata\\AdminBundle\\Model\\ModelManagerInterface'); $modelManager->expects($this->once())->method('find')->will($this->returnValue($object)); $admin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface'); $admin->expects($this->once())->method('getModelManager')->will($this->returnValue($modelManager)); $admin->expects($this->once())->method('setRequest'); $admin->expects($this->once())->method('setSubject'); $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); $container->expects($this->any())->method('get')->will($this->returnValue($admin)); $formExtension = $this->getMock('Twig_ExtensionInterface', array('renderListElement', 'initRuntime', 'getTokenParsers', 'getNodeVisitors', 'getFilters', 'getTests', 'getFunctions', 'getOperators', 'getGlobals', 'getName', 'setTheme', 'renderWidget')); $formExtension->expects($this->once())->method('getName')->will($this->returnValue('form')); $formExtension->expects($this->once())->method('renderWidget')->will($this->returnValue(new Response())); $formExtension->expects($this->once())->method('setTheme'); $twig = new Twig(); $twig->addExtension($formExtension); $request = new Request(array('code' => 'sonata.post.admin', 'objectId' => 42, 'field' => 'enabled', 'value' => 1, 'context' => 'list'), array(), array(), array(), array(), array('REQUEST_METHOD' => 'POST')); $pool = new Pool($container, 'title', 'logo'); $dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface'); $form = new Form('foo', $dispatcher); $helper = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminHelper', array('appendFormFieldElement'), array($pool)); $helper->expects($this->once())->method('appendFormFieldElement')->will($this->returnValue(array($this->getMock('Sonata\\AdminBundle\\Admin\\FieldDescriptionInterface'), $form))); $controller = new HelperController($twig, $pool, $helper); $response = $controller->appendFormFieldElementAction($request); $this->isInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response); }