protected function setUp()
 {
     $this->environment = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock();
     $this->stateManager = $this->getMockBuilder('Oro\\Bundle\\WindowsBundle\\Manager\\WindowsStateManager')->disableOriginalConstructor()->getMock();
     $this->stateManagerRegistry = $this->getMockBuilder('Oro\\Bundle\\WindowsBundle\\Manager\\WindowsStateManagerRegistry')->disableOriginalConstructor()->getMock();
     $this->stateManagerRegistry->expects($this->any())->method('getManager')->willReturn($this->stateManager);
     $this->requestStateManager = $this->getMockBuilder('Oro\\Bundle\\WindowsBundle\\Manager\\WindowsStateRequestManager')->setMethods(['getData'])->disableOriginalConstructor()->getMock();
     $this->extension = new WindowsExtension($this->stateManagerRegistry, $this->requestStateManager);
 }
 public function testGetManager()
 {
     /** @var \PHPUnit_Framework_MockObject_MockObject|WindowsStateManager $manager */
     $manager = $this->getMockBuilder('Oro\\Bundle\\WindowsBundle\\Manager\\WindowsStateManager')->disableOriginalConstructor()->getMock();
     $this->registry->addManager($manager);
     $this->defaultManager->expects($this->never())->method($this->anything());
     $manager->expects($this->exactly(2))->method('isApplicable')->willReturn(true);
     $this->assertTrue($this->registry->getManager()->isApplicable());
 }
Example #3
0
 /**
  * Renders fragment by window state.
  *
  * @param \Twig_Environment $environment
  * @param AbstractWindowsState $windowState
  *
  * @return string
  */
 public function renderFragment(\Twig_Environment $environment, AbstractWindowsState $windowState)
 {
     $result = '';
     $scheduleDelete = false;
     $windowState->setRenderedSuccessfully(false);
     try {
         $uri = $this->windowsStateRequestManager->getUri($windowState->getData());
         /** @var HttpKernelExtension $httpKernelExtension */
         $httpKernelExtension = $environment->getExtension('http_kernel');
         $result = $httpKernelExtension->renderFragment($uri);
         $windowState->setRenderedSuccessfully(true);
         return $result;
     } catch (NotFoundHttpException $e) {
         $scheduleDelete = true;
     } catch (\InvalidArgumentException $e) {
         $scheduleDelete = true;
     }
     if ($scheduleDelete) {
         try {
             $this->windowsStateManagerRegistry->getManager()->deleteWindowsState($windowState->getId());
         } catch (AccessDeniedException $e) {
             return $result;
         }
     }
     return $result;
 }