/** * @dataProvider getRenderViewElementTests */ public function testRenderViewElement($expected, $type, $value, array $options) { $this->admin->expects($this->any())->method('getTemplate')->will($this->returnValue('SonataAdminBundle:CRUD:base_show_field.html.twig')); $this->fieldDescription->expects($this->any())->method('getValue')->will($this->returnCallback(function () use($value) { if ($value instanceof NoValueException) { throw $value; } return $value; })); $this->fieldDescription->expects($this->any())->method('getType')->will($this->returnValue($type)); $this->fieldDescription->expects($this->any())->method('getOptions')->will($this->returnValue($options)); $this->fieldDescription->expects($this->any())->method('getTemplate')->will($this->returnCallback(function () use($type) { switch ($type) { case 'boolean': return 'SonataAdminBundle:CRUD:show_boolean.html.twig'; case 'datetime': return 'SonataAdminBundle:CRUD:show_datetime.html.twig'; case 'date': return 'SonataAdminBundle:CRUD:show_date.html.twig'; case 'time': return 'SonataAdminBundle:CRUD:show_time.html.twig'; case 'currency': return 'SonataAdminBundle:CRUD:show_currency.html.twig'; case 'percent': return 'SonataAdminBundle:CRUD:show_percent.html.twig'; case 'email': return 'SonataAdminBundle:CRUD:show_email.html.twig'; case 'choice': return 'SonataAdminBundle:CRUD:show_choice.html.twig'; case 'array': return 'SonataAdminBundle:CRUD:show_array.html.twig'; case 'trans': return 'SonataAdminBundle:CRUD:show_trans.html.twig'; case 'url': return 'SonataAdminBundle:CRUD:show_url.html.twig'; case 'html': return 'SonataAdminBundle:CRUD:show_html.html.twig'; default: return false; } })); $this->assertSame($expected, trim(preg_replace('/\\s+/', ' ', $this->twigExtension->renderViewElement($this->environment, $this->fieldDescription, $this->object)))); }