Beispiel #1
0
 public function testLocalesWithApiRequestWithoutAcceptLanguageHeader()
 {
     $request = $this->createRequestMock();
     $request->headers->expects($this->once())->method('get')->with($this->identicalTo('Accept-Language'))->will($this->returnValue(null));
     $request->expects($this->once())->method('getLocale')->will($this->returnValue($locale = 'en'));
     $this->requestStack->expects($this->once())->method('getMasterRequest')->will($this->returnValue($request));
     $this->parameterResolver->expects($this->once())->method('resolveApi')->will($this->returnValue(true));
     $this->assertSame([$locale], $this->localeContext->getLocales());
 }
 public function testActionWithoutForm()
 {
     $this->parameterResolver->expects($this->once())->method('resolveApi')->will($this->returnValue(false));
     $event = $event = $this->createActionEventMock();
     $event->expects($this->once())->method('getForm')->will($this->returnValue(null));
     $this->parameterResolver->expects($this->once())->method('resolveRedirectRoute')->will($this->returnValue($route = 'route'));
     $event->expects($this->once())->method('setView')->with($this->callback(function (View $view) use($route) {
         return $view->getRoute() === $route && $view->getRouteParameters() === [];
     }));
     $this->subscriber->onAction($event);
 }
Beispiel #3
0
 public function testMessageWithApi()
 {
     $this->parameterResolver->expects($this->once())->method('resolveApi')->will($this->returnValue(true));
     $event = $this->createDomainEventMock();
     $event->expects($this->never())->method('setMessage');
     $this->messageListener->addMessage($event);
 }
 public function testViewWithPagerfanta()
 {
     $this->parameterResolver->expects($this->once())->method('resolveApi')->will($this->returnValue(false));
     $event = $this->createViewEventMock();
     $event->expects($this->once())->method('getView')->will($this->returnValue($view = $this->createViewMock()));
     $view->expects($this->once())->method('getData')->will($this->returnValue($this->createPagerfantaMock()));
     $event->expects($this->once())->method('getResource')->will($this->returnValue($resource = $this->createResourceMock()));
     $resource->expects($this->once())->method('getName')->will($this->returnValue($name = 'name'));
     $view->expects($this->once())->method('setTemplateVar')->with($this->identicalTo($name . 's'));
     $this->subscriber->onView($event);
 }
Beispiel #5
0
 public function testViewWithForms()
 {
     $this->parameterResolver->expects($this->once())->method('resolveApi')->will($this->returnValue(false));
     $event = $this->createViewEventMock();
     $event->expects($this->once())->method('getView')->will($this->returnValue($view = $this->createViewMock()));
     $view->expects($this->once())->method('getData')->will($this->returnValue([$object = new \stdClass(), $form = $this->createFormMock()]));
     $form->expects($this->once())->method('createView')->will($this->returnValue($formView = $this->createFormViewMock()));
     $this->parameterResolver->expects($this->once())->method('resolveThemes')->will($this->returnValue($themes = ['theme']));
     $this->formRenderer->expects($this->once())->method('setTheme')->with($this->identicalTo($formView), $this->identicalTo($themes));
     $view->expects($this->once())->method('setData')->with($this->identicalTo([$object, $formView]));
     $this->subscriber->onView($event);
 }
 public function testActionWithValidFormAndOkStatusCode()
 {
     $this->parameterResolver->expects($this->once())->method('resolveApi')->will($this->returnValue(true));
     $event = $this->createActionEventMock();
     $event->expects($this->once())->method('getForm')->will($this->returnValue($form = $this->createFormMock()));
     $form->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $form->expects($this->once())->method('getData')->will($this->returnValue($data = new \stdClass()));
     $event->expects($this->once())->method('getStatusCode')->will($this->returnValue($statusCode = Response::HTTP_OK));
     $event->expects($this->once())->method('setView')->with($this->callback(function (View $view) use($statusCode, $data) {
         return $view->getStatusCode() === $statusCode && $view->getData() === $data;
     }));
     $this->subscriber->onAction($event);
 }
 public function testViewWithTemplateVar()
 {
     $this->parameterResolver->expects($this->once())->method('resolveApi')->will($this->returnValue(false));
     $event = $this->createViewEventMock();
     $event->expects($this->once())->method('getView')->will($this->returnValue($view = $this->createViewMock()));
     $view->expects($this->once())->method('getData')->will($this->returnValue($data = new \stdClass()));
     $this->parameterResolver->expects($this->once())->method('resolveTemplate')->will($this->returnValue($template = 'template'));
     $view->expects($this->once())->method('setTemplate')->with($this->identicalTo($template))->will($this->returnSelf());
     $event->expects($this->once())->method('getResource')->will($this->returnValue($resource = $this->createResourceMock()));
     $view->expects($this->once())->method('getTemplateVar')->will($this->returnValue($templateVar = 'template_var'));
     $view->expects($this->once())->method('setData')->with($this->identicalTo([$templateVar => $data, 'resource' => $resource]));
     $this->subscriber->onView($event);
 }
 public function testViewFormThemes()
 {
     $this->parameterResolver->expects($this->once())->method('resolveApi')->will($this->returnValue(false));
     $this->parameterResolver->expects($this->once())->method('resolveThemes')->will($this->returnValue($themes = ['theme']));
     $event = $this->createViewEventMock();
     $event->expects($this->once())->method('getView')->will($this->returnValue($view = $this->createViewMock()));
     $view->expects($this->once())->method('getData')->will($this->returnValue(['grid' => $gridView = $this->createGridViewMock(), 'batch_form' => $batchForm = $this->createFormMock()]));
     $batchForm->expects($this->once())->method('createView')->will($this->returnValue($batchFormView = $this->createFormViewMock()));
     $gridView->expects($this->once())->method('setBatchForm')->with($this->identicalTo($batchFormView));
     $gridView->expects($this->once())->method('getForm')->will($this->returnValue($formView = $this->createFormViewMock()));
     $gridView->expects($this->exactly(2))->method('getBatchForm')->willReturnOnConsecutiveCalls(null, $batchFormView);
     $this->formRenderer->expects($this->exactly(2))->method('setTheme')->withConsecutive([$formView, $themes], [$batchFormView, $themes]);
     $view->expects($this->once())->method('setTemplateVar')->with($this->identicalTo('grid'))->will($this->returnSelf());
     $view->expects($this->once())->method('setData')->with($this->identicalTo($gridView));
     $this->subscriber->onView($event);
 }
Beispiel #9
0
 public function testBatchWithApiAndDomainException()
 {
     $data = [$object = new \stdClass()];
     $grid = $this->createGridMock();
     $grid->expects($this->once())->method('getResource')->will($this->returnValue($resource = $this->createResourceMock()));
     $resource->expects($this->once())->method('getName')->will($this->returnValue($name = 'name'));
     $this->domainManagerRegistry->expects($this->once())->method('offsetGet')->with($this->identicalTo($name))->will($this->returnValue($domainManager = $this->createDomainManagerMock()));
     $this->parameterResolver->expects($this->once())->method('resolveApi')->will($this->returnValue(true));
     $domainManager->expects($this->once())->method('delete')->with($this->identicalTo($object), $this->isFalse())->will($this->throwException($exception = $this->createDomainExceptionMock()));
     try {
         $this->type->batch($data, ['grid' => $grid]);
         $this->fail();
     } catch (DomainException $e) {
         $this->assertSame($exception, $e);
     }
 }
Beispiel #10
0
 public function testCreateWithApi()
 {
     $this->parameterResolver->expects($this->once())->method('resolveApi')->will($this->returnValue(true));
     $this->symfonyFormFactory->expects($this->once())->method('create')->with($this->identicalTo($type = 'type'), $this->identicalTo($data = 'data'), $this->identicalTo(array_merge($options = ['option'], ['csrf_protection' => false])))->will($this->returnValue($form = 'form'));
     $this->assertSame($form, $this->formFactory->create($type, $data, $options));
 }
 public function testResolveVoter()
 {
     $this->parameterResolver->expects($this->once())->method('resolveVoter')->will($this->returnValue(true));
     $this->assertTrue($this->cachedParameterResolver->resolveVoter());
     $this->assertTrue($this->cachedParameterResolver->resolveVoter());
 }
Beispiel #12
0
 public function testType()
 {
     $this->parameterResolver->expects($this->once())->method('resolveApi')->will($this->returnValue(true));
     $form = $this->formFactory->create(FileType::class);
     $this->assertTrue($form->getConfig()->getOption('base64'));
 }
Beispiel #13
0
 public function testFlashWithApi()
 {
     $this->parameterResolver->expects($this->once())->method('resolveApi')->will($this->returnValue(true));
     $this->session->expects($this->never())->method('getFlashBag');
     $this->flashListener->addFlash($this->createDomainEventMock());
 }
Beispiel #14
0
 public function testType()
 {
     $this->parameterResolver->expects($this->once())->method('resolveApi')->will($this->returnValue(true));
     $form = $this->formFactory->create(CheckboxType::class);
     $this->assertSame(BooleanExtension::TYPE_API, $form->getConfig()->getOption('type'));
 }
 public function testResolveValidationGroups()
 {
     $this->parameterResolver->expects($this->once())->method('resolveValidationGroups')->will($this->returnValue($groups = ['group']));
     $this->assertSame($groups, $this->cachedParameterResolver->resolveValidationGroups());
     $this->assertSame($groups, $this->cachedParameterResolver->resolveValidationGroups());
 }
Beispiel #16
0
 public function testIsGrantedWithVoter()
 {
     $this->parameterResolver->expects($this->once())->method('resolveVoter')->will($this->returnValue(true));
     $this->authorizationChecker->expects($this->once())->method('isGranted')->with($this->identicalTo('lug.' . ($action = 'show')), $this->identicalTo($object = $this->createStdClassMock()))->will($this->returnValue(true));
     $this->assertTrue($this->securityChecker->isGranted($action, $object));
 }
Beispiel #17
0
 public function testFallbackLocaleWithApiRequest()
 {
     $this->parameterResolver->expects($this->once())->method('resolveApi')->will($this->returnValue(true));
     $this->assertNull($this->localeContext->getFallbackLocale());
 }