/** * @expectedException \Lug\Component\Grid\Exception\InvalidTypeException * @expectedExceptionMessage The "name" number column type expects a numeric value, got "stdClass". */ public function testRenderWithoutScalar() { $this->propertyAccessor->expects($this->once())->method('getValue')->with($this->identicalTo($data = new \stdClass()), $this->identicalTo($path = 'path_value'))->will($this->returnValue(new \stdClass())); $column = $this->createColumnMock(); $column->expects($this->once())->method('getName')->will($this->returnValue('name')); $this->type->render($data, ['column' => $column, 'path' => $path]); }
public function setUp() { $this->accessor = $this->getMockBuilder('Symfony\\Component\\PropertyAccess\\PropertyAccessorInterface')->getMock(); $this->accessor->expects($this->any())->method('getValue')->will($this->returnCallback(function ($item, $path) { static $i = 0; return array($item, $path, $i++); })); $this->resolver = new PropertyAccessResolver($this->accessor); }
public function testRender() { $this->urlGenerator->expects($this->once())->method('generate')->with($this->identicalTo($route = 'route_value'), $this->identicalTo([$routeParameter = 'route_parameter' => $routeParameterValue = 'route_parameter_value']), $this->identicalTo($routeReferenceType = UrlGeneratorInterface::ABSOLUTE_PATH))->will($this->returnValue($url = 'url_value')); $this->propertyAccessor->expects($this->once())->method('getValue')->with($this->identicalTo($data = new \stdClass()), $this->identicalTo($routeParameter))->will($this->returnValue($routeParameterValue)); $action = $this->createActionMock(); $action->expects($this->once())->method('getLabel')->will($this->returnValue($actionLabel = 'action_label')); $action->expects($this->once())->method('getOption')->with($this->identicalTo('trans_domain'))->will($this->returnValue($actionTransDomain = 'action_trans_domain')); $this->formFactory->expects($this->once())->method('create')->with($this->identicalTo(CsrfProtectionType::class), $this->isNull(), $this->identicalTo(['method' => $method = Request::METHOD_DELETE, 'action' => $url, 'label' => $actionLabel, 'translation_domain' => $actionTransDomain]))->will($this->returnValue($form = $this->createFormMock())); $form->expects($this->once())->method('createView')->will($this->returnValue($view = $this->createFormViewMock())); $this->assertSame($view, $this->type->render($data, ['action' => $action, 'method' => strtolower($method), 'route' => $route, 'route_parameters' => [$routeParameter], 'route_reference_type' => $routeReferenceType])); }
public function testMessageWithLabelPropertyPath() { $event = $this->createDomainEventMock(); $event->expects($this->once())->method('getMessageType')->will($this->returnValue($messageType = 'message_type')); $event->expects($this->once())->method('setMessageType')->with($this->identicalTo($messageType)); $event->expects($this->once())->method('getMessage')->will($this->returnValue(null)); $event->expects($this->once())->method('getAction')->will($this->returnValue($action = 'action')); $event->expects($this->once())->method('getObject')->will($this->returnValue($object = new \stdClass())); $event->expects($this->once())->method('getResource')->will($this->returnValue($resource = $this->createResourceMock())); $resource->expects($this->once())->method('getName')->will($this->returnValue($name = 'name')); $resource->expects($this->once())->method('getLabelPropertyPath')->will($this->returnValue($labelPropertyPath = 'property_path')); $this->propertyAccessor->expects($this->once())->method('getValue')->with($this->identicalTo($object), $this->identicalTo($labelPropertyPath))->will($this->returnValue($property = 'property')); $this->translator->expects($this->once())->method('trans')->with($this->identicalTo('lug.' . $name . '.' . $action . '.' . $messageType), $this->identicalTo(['%' . $name . '%' => $property]))->will($this->returnValue($translation = 'translation')); $event->expects($this->once())->method('setMessage')->with($this->identicalTo($translation)); $this->messageListener->addMessage($event); }
public function testValidateDefaultLocale() { $this->localeProvider->expects($this->once())->method('getDefaultLocale')->will($this->returnValue($locale = $this->createLocaleMock())); $domainEvent = $this->createDomainEventMock(); $domainEvent->expects($this->once())->method('getData')->will($this->returnValue($locale)); $domainEvent->expects($this->once())->method('getResource')->will($this->returnValue($resource = $this->createResourceMock())); $resource->expects($this->exactly(2))->method('getName')->will($this->returnValue($resourceName = 'resource')); $resource->expects($this->once())->method('getLabelPropertyPath')->will($this->returnValue($labelPropertyPath = 'code')); $this->propertyAccessor->expects($this->once())->method('getValue')->with($this->identicalTo($locale), $this->identicalTo($labelPropertyPath))->will($this->returnValue($localeCode = 'code')); $domainEvent->expects($this->once())->method('setStopped')->with($this->identicalTo(true)); $domainEvent->expects($this->once())->method('setStatusCode')->with($this->identicalTo(409)); $domainEvent->expects($this->once())->method('setMessageType')->with($this->identicalTo('error')); $domainEvent->expects($this->once())->method('getAction')->will($this->returnValue('action')); $this->translator->expects($this->once())->method('trans')->with($this->identicalTo('lug.resource.action.default'), $this->identicalTo(['%resource%' => $localeCode]), $this->identicalTo('flashes'))->will($this->returnValue($translation = 'translation')); $domainEvent->expects($this->once())->method('setMessage')->with($this->identicalTo($translation)); $this->localeDomainSubscriber->validateDefaultLocale($domainEvent); }
/** * @expectedException \Lug\Component\Grid\Exception\InvalidTypeException * @expectedExceptionMessage The "name" json column type expects anything except a resource. */ public function testRenderWithResource() { $resource = fopen('php://temp', 'r'); $this->propertyAccessor->expects($this->once())->method('getValue')->with($this->identicalTo($data = new \stdClass()), $this->identicalTo($path = 'path_value'))->will($this->returnValue($resource)); $column = $this->createColumnMock(); $column->expects($this->once())->method('getName')->will($this->returnValue('name')); try { $this->type->render($data, ['column' => $column, 'path' => $path, 'options' => 0, 'depth' => 512]); $this->fail(); } catch (InvalidTypeException $e) { } if (is_resource($resource)) { fclose($resource); } if (isset($e)) { throw $e; } }
public function testResolveRedirectRouteParametersForwardParameters() { $this->requestStack->expects($this->exactly(2))->method('getMasterRequest')->will($this->returnValue($request = $this->createRequestMock())); $request->attributes->expects($this->once())->method('get')->with($this->identicalTo('_lug_redirect_route_parameters'), $this->identicalTo([]))->will($this->returnValue([$parameter = 'id'])); $request->query = $this->createParameterBagMock(); $request->query->expects($this->once())->method('all')->will($this->returnValue($query = ['foo' => 'bar'])); $object = new \stdClass(); $object->{$parameter} = $value = 1; $this->propertyAccessor->expects($this->once())->method('getValue')->with($this->identicalTo($object), $this->identicalTo($parameter))->will($this->returnValue($value)); $this->assertSame(array_merge($query, [$parameter => $value]), $this->parameterResolver->resolveRedirectRouteParameters($object, true)); }
public function testRenderWithNull() { $this->propertyAccessor->expects($this->once())->method('getValue')->with($this->identicalTo($data = new \stdClass()), $this->identicalTo($path = 'path_value'))->will($this->returnValue(null)); $this->renderer->expects($this->never())->method('render'); $this->assertNull($this->type->render($data, ['path' => $path])); }
public function testRender() { $this->propertyAccessor->expects($this->once())->method('getValue')->with($this->identicalTo($data = new \stdClass()), $this->identicalTo($path = 'path_value'))->will($this->returnValue($twigData = 'twig_data')); $this->twig->expects($this->once())->method('render')->with($this->identicalTo($template = 'template'), $this->identicalTo(array_merge($context = ['foo' => 'bar'], ['column' => $column = $this->createColumnMock(), 'data' => $twigData])))->will($this->returnValue($result = 'result')); $this->assertSame($result, $this->type->render($data, ['column' => $column, 'path' => $path, 'template' => $template, 'context' => $context])); }
public function testRender() { $this->urlGenerator->expects($this->once())->method('generate')->with($this->identicalTo($route = 'route_value'), $this->identicalTo([$routeParameter = 'route_parameter' => $routeParameterValue = 'route_parameter_value']), $this->identicalTo($routeReferenceType = UrlGeneratorInterface::ABSOLUTE_PATH))->will($this->returnValue($url = 'url_value')); $this->propertyAccessor->expects($this->once())->method('getValue')->with($this->identicalTo($data = new \stdClass()), $this->identicalTo($routeParameter))->will($this->returnValue($routeParameterValue)); $this->assertSame($url, $this->type->render($data, ['route' => $route, 'route_parameters' => [$routeParameter], 'route_reference_type' => $routeReferenceType])); }