Exemplo n.º 1
0
 /**
  * @dataProvider getBuildPagerWithPage2Tests
  */
 public function testBuildPagerWithPage2($page, $perPage)
 {
     $this->pager->expects($this->once())->method('setMaxPerPage')->with($this->equalTo('50'))->will($this->returnValue(null));
     $this->pager->expects($this->once())->method('setPage')->with($this->equalTo('3'))->will($this->returnValue(null));
     $this->datagrid = new Datagrid($this->query, $this->columns, $this->pager, $this->formBuilder, array());
     $this->datagrid->setValue('_per_page', null, $perPage);
     $this->datagrid->setValue('_page', null, $page);
     $this->datagrid->buildPager();
     $this->assertSame(array('_per_page' => array('type' => null, 'value' => $perPage), '_page' => array('type' => null, 'value' => $page)), $this->datagrid->getValues());
     $this->assertInstanceOf('Symfony\\Component\\Form\\FormBuilder', $this->formBuilder->get('_sort_by'));
     $this->assertInstanceOf('Symfony\\Component\\Form\\FormBuilder', $this->formBuilder->get('_sort_order'));
     $this->assertInstanceOf('Symfony\\Component\\Form\\FormBuilder', $this->formBuilder->get('_page'));
     $this->assertInstanceOf('Symfony\\Component\\Form\\FormBuilder', $this->formBuilder->get('_per_page'));
 }
 public function testReorder()
 {
     $fieldDescription1 = $this->getFieldDescriptionMock('fooName1', 'fooLabel1');
     $fieldDescription2 = $this->getFieldDescriptionMock('fooName2', 'fooLabel2');
     $fieldDescription3 = $this->getFieldDescriptionMock('fooName3', 'fooLabel3');
     $fieldDescription4 = $this->getFieldDescriptionMock('fooName4', 'fooLabel4');
     $this->datagridMapper->add($fieldDescription1, null, array('field_name' => 'fooFilterName1'));
     $this->datagridMapper->add($fieldDescription2, null, array('field_name' => 'fooFilterName2'));
     $this->datagridMapper->add($fieldDescription3, null, array('field_name' => 'fooFilterName3'));
     $this->datagridMapper->add($fieldDescription4, null, array('field_name' => 'fooFilterName4'));
     $this->assertSame(array('fooName1', 'fooName2', 'fooName3', 'fooName4'), array_keys($this->datagrid->getFilters()));
     $this->datagridMapper->reorder(array('fooName3', 'fooName2', 'fooName1', 'fooName4'));
     $this->assertSame(array('fooName3', 'fooName2', 'fooName1', 'fooName4'), array_keys($this->datagrid->getFilters()));
 }
Exemplo n.º 3
0
 public function testBuildPagerWithSortBy()
 {
     $sortBy = $this->getMock('Sonata\\AdminBundle\\Admin\\FieldDescriptionInterface');
     $sortBy->expects($this->once())->method('isSortable')->will($this->returnValue(true));
     $this->datagrid = new Datagrid($this->query, $this->columns, $this->pager, $this->formBuilder, array('_sort_by' => $sortBy));
     $filter = $this->getMock('Sonata\\AdminBundle\\Filter\\FilterInterface');
     $filter->expects($this->once())->method('getName')->will($this->returnValue('foo'));
     $filter->expects($this->any())->method('getFormName')->will($this->returnValue('fooFormName'));
     $filter->expects($this->any())->method('isActive')->will($this->returnValue(false));
     $filter->expects($this->any())->method('getRenderSettings')->will($this->returnValue(array('foo', array('bar' => 'baz'))));
     $this->datagrid->addFilter($filter);
     $this->datagrid->buildPager();
     $this->assertEquals(array('_sort_by' => $sortBy, 'foo' => null), $this->datagrid->getValues());
     $this->assertInstanceOf('Symfony\\Component\\Form\\FormBuilder', $this->formBuilder->get('fooFormName'));
     $this->assertEquals(array('bar' => 'baz'), $this->formBuilder->get('fooFormName')->getOptions());
     $this->assertInstanceOf('Symfony\\Component\\Form\\FormBuilder', $this->formBuilder->get('_sort_by'));
     $this->assertInstanceOf('Symfony\\Component\\Form\\FormBuilder', $this->formBuilder->get('_sort_order'));
     $this->assertInstanceOf('Symfony\\Component\\Form\\FormBuilder', $this->formBuilder->get('_page'));
     $this->assertInstanceOf('Symfony\\Component\\Form\\FormBuilder', $this->formBuilder->get('_per_page'));
 }