/**
  * Sets up the fixture.
  *
  * @covers Kunstmaan\PagePartBundle\EventListener\CloneListener::__construct
  */
 protected function setUp()
 {
     $this->em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $this->repo = $this->getMockBuilder(PagePartRefRepository::class)->disableOriginalConstructor()->getMock();
     $this->em->expects($this->any())->method('getRepository')->with($this->equalTo('KunstmaanPagePartBundle:PagePartRef'))->will($this->returnValue($this->repo));
     $this->configurator = new PagePartAdminConfigurator();
     $this->configurator->setContext('main');
     $this->reader = $this->getMock(PagePartConfigurationReaderInterface::class);
     $this->reader->expects($this->any())->method('getPagePartAdminConfigurators')->will($this->returnValue([$this->configurator]));
     $this->reader->expects($this->any())->method('getPagePartContexts')->will($this->returnValue([$this->configurator->getContext()]));
     $this->templateService = $this->getMockBuilder(PageTemplateConfigurationService::class)->disableOriginalConstructor()->getMock();
     $this->object = new CloneListener($this->em, $this->reader, $this->templateService);
 }
 /**
  * This getter returns an array holding info on page part types that can be added to the page.
  * The types are filtererd here, based on the amount of page parts of a certain type that can be added to the page.
  *
  * @return array
  */
 public function getPossiblePagePartTypes()
 {
     $possiblePPTypes = $this->configurator->getPossiblePagePartTypes();
     $result = array();
     // filter page part types that can only be added x times to the page context.
     // to achieve this, provide a 'pagelimit' parameter when adding the pp type in your PagePartAdminConfiguration
     if (!empty($possiblePPTypes)) {
         foreach ($possiblePPTypes as $possibleTypeData) {
             if (array_key_exists('pagelimit', $possibleTypeData)) {
                 $pageLimit = $possibleTypeData['pagelimit'];
                 /** @var PagePartRefRepository $entityRepository */
                 $entityRepository = $this->em->getRepository('KunstmaanPagePartBundle:PagePartRef');
                 $formPPCount = $entityRepository->countPagePartsOfType($this->page, $possibleTypeData['class'], $this->configurator->getContext());
                 if ($formPPCount < $pageLimit) {
                     $result[] = $possibleTypeData;
                 }
             } else {
                 $result[] = $possibleTypeData;
             }
         }
     }
     return $result;
 }