Esempio n. 1
0
 public function testRender()
 {
     $windowStateFoo = $this->createWindowState(['cleanUrl' => 'foo']);
     $windowStateBar = $this->createWindowState(['cleanUrl' => 'foo']);
     $windowStates = [$windowStateFoo, $windowStateBar];
     $this->stateManager->expects($this->once())->method('getWindowsStates')->will($this->returnValue($windowStates));
     $expectedOutput = 'RENDERED';
     $this->environment->expects($this->once())->method('render')->with('OroWindowsBundle::states.html.twig', ['windowStates' => [$windowStateFoo, $windowStateBar]])->will($this->returnValue($expectedOutput));
     $this->assertEquals($expectedOutput, $this->extension->render($this->environment));
     // no need to render twice
     $this->assertEquals('', $this->extension->render($this->environment));
 }
 /**
  * @dataProvider renderDataProvider
  * @param string $widgetUrl
  * @param string $widgetType
  * @param string $expectedWidgetUrl
  */
 public function testRender($widgetUrl, $widgetType, $expectedWidgetUrl)
 {
     $user = $this->getMock('stdClass');
     $token = $this->getMockBuilder('stdClass')->setMethods(array('getUser'))->getMock();
     $token->expects($this->once())->method('getUser')->will($this->returnValue($user));
     $this->securityContext->expects($this->once())->method('getToken')->will($this->returnValue($token));
     $normalStateData = array('cleanUrl' => $widgetUrl, 'type' => $widgetType);
     $normalState = $this->getStateMock(1, $normalStateData);
     $badState = $this->getStateMock(2, null);
     $states = array($normalState, $badState);
     $repository = $this->getMock('Doctrine\\Common\\Persistence\\ObjectRepository');
     $repository->expects($this->once())->method('findBy')->with(array('user' => $user))->will($this->returnValue($states));
     $this->em->expects($this->once())->method('getRepository')->with('OroWindowsBundle:WindowsState')->will($this->returnValue($repository));
     $this->em->expects($this->once())->method('remove')->with($badState);
     $this->em->expects($this->once())->method('flush');
     $output = 'RENDERED';
     $expectedStates = array('cleanUrl' => $expectedWidgetUrl, 'type' => $widgetType);
     $this->environment->expects($this->once())->method('render')->with("OroWindowsBundle::states.html.twig", array("states" => array(1 => $expectedStates)))->will($this->returnValue($output));
     $this->assertEquals($output, $this->extension->render($this->environment));
 }
Esempio n. 3
0
 public function testRenderWithoutToken()
 {
     $this->securityContext->expects($this->once())->method('getToken')->will($this->returnValue(null));
     $this->entityManager->expects($this->never())->method($this->anything());
     $this->assertEquals('', $this->extension->render($this->environment));
 }