public function testReorder()
 {
     $fieldDescription1 = $this->getFieldDescriptionMock('fooName1', 'fooLabel1');
     $fieldDescription2 = $this->getFieldDescriptionMock('fooName2', 'fooLabel2');
     $fieldDescription3 = $this->getFieldDescriptionMock('fooName3', 'fooLabel3');
     $fieldDescription4 = $this->getFieldDescriptionMock('fooName4', 'fooLabel4');
     $this->listMapper->add($fieldDescription1);
     $this->listMapper->add($fieldDescription2);
     $this->listMapper->add($fieldDescription3);
     $this->listMapper->add($fieldDescription4);
     $this->assertEquals(array('fooName1' => $fieldDescription1, 'fooName2' => $fieldDescription2, 'fooName3' => $fieldDescription3, 'fooName4' => $fieldDescription4), $this->fieldDescriptionCollection->getElements());
     $this->listMapper->reorder(array('fooName3', 'fooName2', 'fooName1', 'fooName4'));
     // print_r is used to compare order of items in associative arrays
     $this->assertEquals(print_r(array('fooName3' => $fieldDescription3, 'fooName2' => $fieldDescription2, 'fooName1' => $fieldDescription1, 'fooName4' => $fieldDescription4), true), print_r($this->fieldDescriptionCollection->getElements(), true));
 }
 public function testReorderListWithBatchField()
 {
     $collection = new FieldDescriptionCollection();
     $fieldDescription = $this->getMock('Sonata\\AdminBundle\\Admin\\FieldDescriptionInterface');
     $fieldDescription->expects($this->once())->method('getName')->will($this->returnValue('title'));
     $collection->add($fieldDescription);
     $fieldDescription = $this->getMock('Sonata\\AdminBundle\\Admin\\FieldDescriptionInterface');
     $fieldDescription->expects($this->once())->method('getName')->will($this->returnValue('position'));
     $collection->add($fieldDescription);
     $fieldDescription = $this->getMock('Sonata\\AdminBundle\\Admin\\FieldDescriptionInterface');
     $fieldDescription->expects($this->once())->method('getName')->will($this->returnValue('batch'));
     $collection->add($fieldDescription);
     $newOrder = array('position', 'title');
     $collection->reorder($newOrder);
     array_unshift($newOrder, 'batch');
     $actualElements = array_keys($collection->getElements());
     $this->assertSame($newOrder, $actualElements, 'the order is wrong');
 }
 public function testMethods()
 {
     $collection = new FieldDescriptionCollection();
     $fieldDescription = $this->getMock('Sonata\\AdminBundle\\Admin\\FieldDescriptionInterface');
     $fieldDescription->expects($this->once())->method('getName')->will($this->returnValue('title'));
     $collection->add($fieldDescription);
     $fieldDescription = $this->getMock('Sonata\\AdminBundle\\Admin\\FieldDescriptionInterface');
     $fieldDescription->expects($this->once())->method('getName')->will($this->returnValue('position'));
     $collection->add($fieldDescription);
     $this->assertFalse($collection->has('foo'));
     $this->assertFalse(isset($collection['foo']));
     $this->assertTrue($collection->has('title'));
     $this->assertTrue(isset($collection['title']));
     $this->assertCount(2, $collection->getElements());
     $this->assertCount(2, $collection);
     $this->isInstanceOf('Sonata\\AdminBundle\\Admin\\FieldDescriptionInterface', $collection['title']);
     $this->isInstanceOf('Sonata\\AdminBundle\\Admin\\FieldDescriptionInterface', $collection->get('title'));
     $collection->remove('title');
     $this->assertFalse($collection->has('title'));
     unset($collection['position']);
     $this->assertCount(0, $collection->getElements());
     $this->assertCount(0, $collection);
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public final function keys()
 {
     return array_keys($this->list->getElements());
 }