コード例 #1
0
 /**
  * @dataProvider getRenderListElementTests
  */
 public function testRenderListElement($expected, $type, $value, array $options)
 {
     $this->admin->expects($this->any())->method('getTemplate')->will($this->returnValue('SonataAdminBundle:CRUD:base_list_field.html.twig'));
     $this->fieldDescription->expects($this->any())->method('getValue')->will($this->returnValue($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 'string':
                 return 'SonataAdminBundle:CRUD:list_string.html.twig';
             case 'boolean':
                 return 'SonataAdminBundle:CRUD:list_boolean.html.twig';
             case 'datetime':
                 return 'SonataAdminBundle:CRUD:list_datetime.html.twig';
             case 'date':
                 return 'SonataAdminBundle:CRUD:list_date.html.twig';
             case 'time':
                 return 'SonataAdminBundle:CRUD:list_time.html.twig';
             case 'currency':
                 return 'SonataAdminBundle:CRUD:list_currency.html.twig';
             case 'percent':
                 return 'SonataAdminBundle:CRUD:list_percent.html.twig';
             case 'choice':
                 return 'SonataAdminBundle:CRUD:list_choice.html.twig';
             case 'array':
                 return 'SonataAdminBundle:CRUD:list_array.html.twig';
             case 'trans':
                 return 'SonataAdminBundle:CRUD:list_trans.html.twig';
             case 'url':
                 return 'SonataAdminBundle:CRUD:list_url.html.twig';
             case 'nonexistent':
                 // template doesn`t exist
                 return 'SonataAdminBundle:CRUD:list_nonexistent_template.html.twig';
             default:
                 return false;
         }
     }));
     $this->assertEquals($expected, trim(preg_replace('/\\s+/', ' ', $this->twigExtension->renderListElement($this->object, $this->fieldDescription))));
 }
コード例 #2
0
 /**
  * @expectedException        Twig_Error_Loader
  * @expectedExceptionMessage Unable to find template "base_list_nonexistent_field.html.twig"
  */
 public function testRenderListElementErrorLoadingTemplate()
 {
     $this->admin->expects($this->once())->method('getTemplate')->with($this->equalTo('base_list_field'))->will($this->returnValue('SonataAdminBundle:CRUD:base_list_nonexistent_field.html.twig'));
     $this->fieldDescription->expects($this->once())->method('getTemplate')->will($this->returnValue('SonataAdminBundle:CRUD:list_nonexistent_template.html.twig'));
     $this->twigExtension->renderListElement($this->environment, $this->object, $this->fieldDescription);
 }