public function testLoad()
 {
     $collection = $this->getMockBuilder('Sonata\\ClassificationBundle\\Model\\CollectionInterfacer')->setMethods(array('getId'))->disableOriginalConstructor()->getMock();
     $collection->expects($this->any())->method('getId')->will($this->returnValue(23));
     $this->collectionManager->expects($this->any())->method('find')->with($this->equalTo('23'))->will($this->returnValue($collection));
     $block = $this->getMock('Sonata\\BlockBundle\\Model\\BlockInterface');
     $block->expects($this->any())->method('getSetting')->with($this->equalTo('collectionId'))->will($this->returnValue(23));
     $block->expects($this->once())->method('setSetting')->with($this->equalTo('collectionId'), $this->equalTo($collection));
     $blockService = $this->getMockForAbstractClass('Sonata\\ClassificationBundle\\Block\\Service\\AbstractCollectionsBlockService', array('block.service', $this->templating, $this->contextManager, $this->collectionManager, $this->collectionAdmin));
     $blockService->load($block);
 }
 /**
  * @param CollectionInterface|int  $id
  * @param CollectionInterface|null $default
  *
  * @return CollectionInterface
  */
 protected final function getCollection($id, CollectionInterface $default = null)
 {
     if ($id instanceof CollectionInterface) {
         return $id;
     }
     if (is_numeric($id)) {
         return $this->collectionManager->find($id);
     }
     return $default;
 }
 /**
  * Write a collection, this method is used by both POST and PUT action methods
  *
  * @param Request      $request Symfony request
  * @param integer|null $id      A collection identifier
  *
  * @return \FOS\RestBundle\View\View|FormInterface
  */
 protected function handleWriteCollection($request, $id = null)
 {
     $collection = $id ? $this->getCollection($id) : null;
     $form = $this->formFactory->createNamed(null, 'sonata_classification_api_form_collection', $collection, array('csrf_protection' => false));
     FormHelper::removeFields($request->request->all(), $form);
     $form->bind($request);
     if ($form->isValid()) {
         $collection = $form->getData();
         $this->collectionManager->save($collection);
         $view = \FOS\RestBundle\View\View::create($collection);
         $serializationContext = SerializationContext::create();
         $serializationContext->setGroups(array('sonata_api_read'));
         $serializationContext->enableMaxDepthChecks();
         $view->setSerializationContext($serializationContext);
         return $view;
     }
     return $form;
 }