public function testAttributesRendering()
 {
     $extension = new DatagridExtension();
     self::assertEquals('', $extension->datagridAttributes([]));
     self::assertEquals(' id="1"', $extension->datagridAttributes(['id' => 1]));
     self::assertEquals(' id="1" foo="bar"', $extension->datagridAttributes(['id' => 1, 'foo' => 'bar']));
 }
 public function testDatagridColumnCellRenderBlock()
 {
     $datagrid = $this->createDatagrid('grid');
     $datagrid->setData([['title' => 'This is value 1']]);
     $view = $datagrid->createView();
     $cellView = $view[0]['title'];
     $template = $this->prophesize('\\Twig_Template');
     $template->getParent([])->willReturn(false);
     $template->hasBlock('datagrid_grid_column_name_title_cell')->willReturn(false)->shouldBeCalled();
     $template->hasBlock('datagrid_grid_column_type_text_cell')->willReturn(false)->shouldBeCalled();
     $template->hasBlock('datagrid_column_name_title_cell')->willReturn(false)->shouldBeCalled();
     $template->hasBlock('datagrid_column_type_text_cell')->willReturn(false)->shouldBeCalled();
     $template->hasBlock('datagrid_grid_column_cell')->willReturn(false)->shouldBeCalled();
     $template->hasBlock('datagrid_column_cell')->willReturn(true)->shouldBeCalled();
     $template->displayBlock('datagrid_column_cell', ['cell' => $cellView, 'row_index' => 0, 'datagrid_name' => 'grid', 'translation_domain' => null, 'vars' => ['row' => 0], 'global_var' => 'global_value'])->willReturn(true);
     $this->extension->setBaseTheme($template->reveal());
     $this->extension->datagridColumnCell($cellView);
 }
 /**
  * This test case is realistic in collection rows where each
  * row contains the same data.
  *
  * This is most common use-case, showing more rows
  * on the page is likely to hit memory limits (for the data set itself).
  * And more rows will give display problems.
  *
  * @group benchmark
  */
 public function testGenerateViewWith100RowsAnd10Columns()
 {
     $this->setMaxRunningTime(1);
     $datagrid = $this->factory->createDatagridBuilder('test');
     $datagrid->add('id', NumberType::class, ['data_provider' => function ($data) {
         return $data['id'];
     }]);
     $datagrid->add('name', TextType::class, ['data_provider' => function ($data) {
         return $data['name'];
     }]);
     $datagrid->add('email', TextType::class, ['data_provider' => function ($data) {
         return $data['email'];
     }]);
     $datagrid->add('regdate', DateTimeType::class, ['data_provider' => function ($data) {
         return $data['regdate'];
     }]);
     $datagrid->add('lastModified', DateTimeType::class, ['data_provider' => function ($data) {
         return $data['lastModified'];
     }]);
     $datagrid->add('status', TextType::class, ['label' => 'last_modified', 'data_provider' => function ($data) {
         return $data['lastModified'];
     }, 'value_format' => function ($value) {
         return $value === 1 ? 'active' : 'deactivated';
     }]);
     $datagrid->add('group', TextType::class);
     $datagrid->add('actions', CompoundColumnType::class, ['label' => 'Actions', 'columns' => ['modify' => $this->factory->createColumn('modify', ActionType::class, ['label' => 'Modify', 'data_provider' => function ($data) {
         return ['id' => $data['id']];
     }, 'uri_scheme' => 'entity/{id}/modify']), 'delete' => $this->factory->createColumn('delete', ActionType::class, ['label' => 'Delete', 'data_provider' => function ($data) {
         return ['id' => $data['id']];
     }, 'uri_scheme' => 'entity/{id}/delete'])]]);
     $data = [];
     for ($i = 0; $i < 100; ++$i) {
         $data[] = ['id' => $i, 'name' => 'Who', 'email' => '*****@*****.**', 'regdate' => new \DateTime(), 'lastModified' => new \DateTime(), 'status' => mt_rand(0, 1), 'group' => 'Default'];
     }
     $datagrid = $datagrid->getDatagrid();
     $datagrid->setData($data);
     $this->extension->datagrid($datagrid->createView());
     $this->assertTrue(true);
 }