コード例 #1
0
 /**
  * @covers ::__construct
  * @covers ::getRouteObject
  * @covers ::getCurrentRouteMatch
  * @covers ::getRouteMatch
  */
 public function testGetCurrentRouteObject()
 {
     $request_stack = new RequestStack();
     $request = new Request();
     $request_stack->push($request);
     $current_route_match = new CurrentRouteMatch($request_stack);
     // Before routing.
     $this->assertNull($current_route_match->getRouteObject());
     // After routing.
     $route = new Route('/test-route/{foo}');
     $request->attributes->set(RouteObjectInterface::ROUTE_NAME, 'test_route');
     $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, $route);
     $request->attributes->set('foo', '1');
     $this->assertSame('1', $current_route_match->getParameter('foo'));
     // Immutable for the same request once a route has been matched.
     $request->attributes->set('foo', '2');
     $this->assertSame('1', $current_route_match->getParameter('foo'));
     // Subrequest.
     $subrequest = new Request();
     $subrequest->attributes->set(RouteObjectInterface::ROUTE_NAME, 'test_subrequest_route');
     $subrequest->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/test-subrequest-route/{foo}'));
     $subrequest->attributes->set('foo', '2');
     $request_stack->push($subrequest);
     $this->assertSame('2', $current_route_match->getParameter('foo'));
     // Restored original request.
     $request_stack->pop();
     $this->assertSame('1', $current_route_match->getParameter('foo'));
 }
コード例 #2
0
 protected function setup()
 {
     $this->requestStack = new RequestStack();
     $this->requestStack->push(new Request());
     self::bootKernel();
     $this->formFactory = static::$kernel->getContainer()->get('form.factory');
 }
コード例 #3
0
 public function setUp()
 {
     $this->requestStack = new RequestStack();
     $request = new Request();
     $this->requestStack->push($request);
     $this->session = new Session(new MockArraySessionStorage());
     $request->setSession($this->session);
     $this->dispatcher = new EventDispatcher();
     $translator = new Translator($this->getMock('\\Symfony\\Component\\DependencyInjection\\ContainerInterface'));
     $token = new TokenProvider($this->requestStack, $translator, 'test');
     $this->dispatcher->addSubscriber(new \Thelia\Action\Cart($this->requestStack, $token));
     $this->session->setSessionCart(null);
     $request->setSession($this->session);
     /** @var \Thelia\Action\Cart  cartAction */
     $this->cartAction = new \Thelia\Action\Cart($this->requestStack, new TokenProvider($this->requestStack, $translator, 'baba au rhum'));
     $this->dispatcherNull = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $this->dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface', array(), array(), '', true, true, true, false);
     $this->dispatcher->expects($this->any())->method('dispatch')->will($this->returnCallback(function ($type, $event) {
         if ($type == TheliaEvents::CART_RESTORE_CURRENT) {
             $this->cartAction->restoreCurrentCart($event, null, $this->dispatcher);
         } elseif ($type == TheliaEvents::CART_CREATE_NEW) {
             $this->cartAction->createEmptyCart($event, null, $this->dispatcher);
         }
     }));
 }
コード例 #4
0
ファイル: SessionTest.php プロジェクト: emodric/LegacyBridge
 protected function setUp()
 {
     parent::setUp();
     $this->sessionStorage = $this->getMock('Symfony\\Component\\HttpFoundation\\Session\\Storage\\SessionStorageInterface');
     $this->session = $this->getMock('Symfony\\Component\\HttpFoundation\\Session\\SessionInterface');
     $this->request = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\Request')->setMethods(array('hasPreviousSession'))->getMock();
     $this->requestStack = new RequestStack();
     $this->requestStack->push($this->request);
 }
コード例 #5
0
  public function setUp() {
    $request = new Request();

    $this->requestStack = new RequestStack();
    $this->requestStack->push($request);

    $this->session = $this->getMock('\Symfony\Component\HttpFoundation\Session\SessionInterface');
    $request->setSession($this->session);

    $this->cacheContext = new SessionCacheContext($this->requestStack);
  }
コード例 #6
0
ファイル: Kernel.php プロジェクト: autarky/framework
 protected function innerHandle(Request $request, $type)
 {
     $this->requests->push($request);
     if ($this->eventDispatcher !== null) {
         $event = new GetResponseEvent($this, $request, $type);
         $this->eventDispatcher->dispatch(KernelEvents::REQUEST, $event);
         $response = $event->getResponse() ?: $this->router->dispatch($request);
     } else {
         $response = $this->router->dispatch($request);
     }
     return $this->filterResponse($response, $request, $type);
 }
コード例 #7
0
 public function testGetParentRequest()
 {
     $requestStack = new RequestStack();
     $this->assertNull($requestStack->getParentRequest());
     $masterRequest = Request::create('/foo');
     $requestStack->push($masterRequest);
     $this->assertNull($requestStack->getParentRequest());
     $firstSubRequest = Request::create('/bar');
     $requestStack->push($firstSubRequest);
     $this->assertSame($masterRequest, $requestStack->getParentRequest());
     $secondSubRequest = Request::create('/baz');
     $requestStack->push($secondSubRequest);
     $this->assertSame($firstSubRequest, $requestStack->getParentRequest());
 }
コード例 #8
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->keyValue = $this->getMock('Drupal\\Core\\KeyValueStore\\KeyValueStoreExpirableInterface');
     $this->lock = $this->getMock('Drupal\\Core\\Lock\\LockBackendInterface');
     $this->requestStack = new RequestStack();
     $request = Request::createFromGlobals();
     $this->requestStack->push($request);
     $this->tempStore = new SharedTempStore($this->keyValue, $this->lock, $this->owner, $this->requestStack, 604800);
     $this->ownObject = (object) array('data' => 'test_data', 'owner' => $this->owner, 'updated' => (int) $request->server->get('REQUEST_TIME'));
     // Clone the object but change the owner.
     $this->otherObject = clone $this->ownObject;
     $this->otherObject->owner = 2;
 }
コード例 #9
0
 public function testConfigureContextOverride()
 {
     $request = new Request();
     $request->query->set('_wid', 'test_widget_id');
     $request->query->set('_widgetContainer', 'dialog');
     $this->requestStack->push($request);
     $context = new LayoutContext();
     $context['widget_container'] = 'updated_widget';
     $context->data()->set('widget_id', 'updated_id', 'updated_widget_id');
     $this->contextConfigurator->configureContext($context);
     $context->resolve();
     $this->assertEquals('updated_widget', $context['widget_container']);
     $this->assertEquals('updated_id', $context->data()->getIdentifier('widget_id'));
     $this->assertEquals('updated_widget_id', $context->data()->get('widget_id'));
 }
コード例 #10
0
ファイル: RenderElementTest.php プロジェクト: ddrozdik/dmaps
 /**
  * @covers ::preRenderAjaxForm
  */
 public function testPreRenderAjaxFormWithQueryOptions()
 {
     $request = Request::create('/test');
     $request->query->set('foo', 'bar');
     $this->requestStack->push($request);
     $prophecy = $this->prophesize('Drupal\\Core\\Routing\\UrlGeneratorInterface');
     $url = '/test?foo=bar&other=query&ajax_form=1';
     $prophecy->generateFromRoute('<current>', [], ['query' => ['foo' => 'bar', 'other' => 'query', FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]], TRUE)->willReturn((new GeneratedUrl())->setCacheContexts(['route'])->setGeneratedUrl($url));
     $url_generator = $prophecy->reveal();
     $this->container->set('url_generator', $url_generator);
     $element = ['#type' => 'select', '#id' => 'test', '#ajax' => ['wrapper' => 'foo', 'callback' => 'test-callback', 'options' => ['query' => ['other' => 'query']]]];
     $element = RenderElement::preRenderAjaxForm($element);
     $this->assertTrue($element['#ajax_processed']);
     $this->assertEquals($url, $element['#attached']['drupalSettings']['ajax']['test']['url']);
 }
コード例 #11
0
ファイル: FormTestBase.php プロジェクト: aWEBoLabs/taxi
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->moduleHandler = $this->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
     $this->formCache = $this->getMock('Drupal\\Core\\Form\\FormCacheInterface');
     $this->cache = $this->getMock('Drupal\\Core\\Cache\\CacheBackendInterface');
     $this->urlGenerator = $this->getMock('Drupal\\Core\\Routing\\UrlGeneratorInterface');
     $this->classResolver = $this->getClassResolverStub();
     $this->elementInfo = $this->getMockBuilder('\\Drupal\\Core\\Render\\ElementInfoManagerInterface')->disableOriginalConstructor()->getMock();
     $this->elementInfo->expects($this->any())->method('getInfo')->will($this->returnCallback(array($this, 'getInfo')));
     $this->csrfToken = $this->getMockBuilder('Drupal\\Core\\Access\\CsrfTokenGenerator')->disableOriginalConstructor()->getMock();
     $this->kernel = $this->getMockBuilder('\\Drupal\\Core\\DrupalKernel')->disableOriginalConstructor()->getMock();
     $this->account = $this->getMock('Drupal\\Core\\Session\\AccountInterface');
     $this->themeManager = $this->getMock('Drupal\\Core\\Theme\\ThemeManagerInterface');
     $this->request = new Request();
     $this->eventDispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $this->requestStack = new RequestStack();
     $this->requestStack->push($this->request);
     $this->logger = $this->getMock('Drupal\\Core\\Logger\\LoggerChannelInterface');
     $form_error_handler = $this->getMock('Drupal\\Core\\Form\\FormErrorHandlerInterface');
     $this->formValidator = $this->getMockBuilder('Drupal\\Core\\Form\\FormValidator')->setConstructorArgs([$this->requestStack, $this->getStringTranslationStub(), $this->csrfToken, $this->logger, $form_error_handler])->setMethods(NULL)->getMock();
     $this->formSubmitter = $this->getMockBuilder('Drupal\\Core\\Form\\FormSubmitter')->setConstructorArgs(array($this->requestStack, $this->urlGenerator))->setMethods(array('batchGet', 'drupalInstallationAttempted'))->getMock();
     $this->root = dirname(dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__))));
     $this->formBuilder = new FormBuilder($this->formValidator, $this->formSubmitter, $this->formCache, $this->moduleHandler, $this->eventDispatcher, $this->requestStack, $this->classResolver, $this->elementInfo, $this->themeManager, $this->csrfToken);
 }
コード例 #12
0
 /**
  * {@inheritdoc}
  */
 public function handle(Request $request)
 {
     try {
         $event = new RequestEvent('request', $this);
         $this->stack->push($request);
         $this->events->trigger($event, [$request]);
         if ($event->hasResponse()) {
             $response = $event->getResponse();
         } else {
             $response = $this->handleController();
         }
         return $this->handleResponse($response);
     } catch (\Exception $e) {
         return $this->handleException($e);
     }
 }
コード例 #13
0
 /**
  * @return RequestStack
  */
 private function createRequestStack()
 {
     $request = Request::create('/');
     $requestStack = new RequestStack();
     $requestStack->push($request);
     return $requestStack;
 }
コード例 #14
0
 protected function setUp()
 {
     /**
      * Add the test type to the factory and
      * the form to the container
      */
     $factory = new FormFactoryBuilder();
     $factory->addExtension(new CoreExtension());
     $factory->addType(new TestType());
     /**
      * Construct the container
      */
     $container = new Container();
     $container->set("thelia.form_factory_builder", $factory);
     $container->set("thelia.translator", new Translator($container));
     $container->setParameter("thelia.parser.forms", $definition = array("test_form" => "Thelia\\Tests\\Resources\\Form\\TestForm"));
     $request = new Request();
     $requestStack = new RequestStack();
     $requestStack->push($request);
     $request->setSession(new Session(new MockArraySessionStorage()));
     $container->set("request", $request);
     $container->set("request_stack", $requestStack);
     $container->set("thelia.forms.validator_builder", new ValidatorBuilder());
     $container->set("event_dispatcher", new EventDispatcher());
     $this->factory = new TheliaFormFactory($requestStack, $container, $definition);
 }
コード例 #15
0
 /**
  * @covers ::onPageContext
  */
 public function testOnPageContext()
 {
     $collection = new RouteCollection();
     $route_provider = $this->prophesize(RouteProviderInterface::class);
     $route_provider->getRoutesByPattern('/test_route')->willReturn($collection);
     $request = new Request();
     $request_stack = new RequestStack();
     $request_stack->push($request);
     $data_definition = new DataDefinition(['type' => 'entity:user']);
     $typed_data = $this->prophesize(TypedDataInterface::class);
     $this->typedDataManager->getDefaultConstraints($data_definition)->willReturn([]);
     $this->typedDataManager->create($data_definition, 'banana')->willReturn($typed_data->reveal());
     $this->typedDataManager->createDataDefinition('bar')->will(function () use($data_definition) {
         return $data_definition;
     });
     $page = $this->prophesize(PageInterface::class);
     $this->executable->expects($this->once())->method('getPage')->will($this->returnValue($page->reveal()));
     $page->getPath()->willReturn('/test_route');
     $this->executable->expects($this->at(1))->method('addContext')->with('foo', $this->isInstanceOf(Context::class));
     $this->executable->expects($this->at(2))->method('addContext')->with('baz', $this->isInstanceOf(Context::class));
     $collection->add('test_route', new Route('/test_route', [], [], ['parameters' => ['foo' => ['type' => 'bar'], 'baz' => ['type' => 'bop'], 'page' => ['type' => 'entity:page']]]));
     // Set up a request with one of the expected parameters as an attribute.
     $request->attributes->add(['foo' => 'banana']);
     $route_param_context = new RouteParamContext($route_provider->reveal(), $request_stack);
     $route_param_context->onPageContext($this->event);
 }
コード例 #16
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->keyValue = $this->getMock('Drupal\\Core\\KeyValueStore\\KeyValueStoreExpirableInterface');
     $this->lock = $this->getMock('Drupal\\Core\\Lock\\LockBackendInterface');
     $this->currentUser = $this->getMock('Drupal\\Core\\Session\\AccountProxyInterface');
     $this->currentUser->expects($this->any())->method('id')->willReturn(1);
     $this->requestStack = new RequestStack();
     $request = Request::createFromGlobals();
     $this->requestStack->push($request);
     $this->tempStore = new PrivateTempStore($this->keyValue, $this->lock, $this->currentUser, $this->requestStack, 604800);
     $this->ownObject = (object) array('data' => 'test_data', 'owner' => $this->currentUser->id(), 'updated' => (int) $request->server->get('REQUEST_TIME'));
     // Clone the object but change the owner.
     $this->otherObject = clone $this->ownObject;
     $this->otherObject->owner = 2;
 }
コード例 #17
0
 /**
  * Tests the checkNamedRoute with default values.
  *
  * @covers \Drupal\Core\Access\AccessManager::checkNamedRoute()
  */
 public function testCheckNamedRouteWithDefaultValue()
 {
     $this->routeCollection = new RouteCollection();
     $route = new Route('/test-route-1/{value}', array('value' => 'example'), array('_test_access' => 'TRUE'));
     $this->routeCollection->add('test_route_1', $route);
     $this->routeProvider = $this->getMock('Drupal\\Core\\Routing\\RouteProviderInterface');
     $this->routeProvider->expects($this->any())->method('getRouteByName')->with('test_route_1', array())->will($this->returnValue($route));
     $map = array();
     $map[] = array('test_route_1', array('value' => 'example'), '/test-route-1/example');
     $this->urlGenerator = $this->getMock('Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface');
     $this->urlGenerator->expects($this->any())->method('generate')->with('test_route_1', array())->will($this->returnValueMap($map));
     $this->paramConverter = $this->getMock('Drupal\\Core\\ParamConverter\\ParamConverterManagerInterface');
     $this->paramConverter->expects($this->at(0))->method('convert')->with(array('value' => 'example', RouteObjectInterface::ROUTE_OBJECT => $route))->will($this->returnValue(array('value' => 'upcasted_value')));
     $this->argumentsResolver->expects($this->atLeastOnce())->method('getArguments')->will($this->returnCallback(function ($callable, $route, $request, $account) {
         return array($route);
     }));
     $subrequest = Request::create('/test-route-1/example');
     $this->accessManager = new AccessManager($this->routeProvider, $this->urlGenerator, $this->paramConverter, $this->argumentsResolver, $this->requestStack);
     $this->accessManager->setContainer($this->container);
     $this->requestStack->push(new Request());
     $access_check = $this->getMock('Drupal\\Tests\\Core\\Access\\TestAccessCheckInterface');
     $access_check->expects($this->atLeastOnce())->method('applies')->will($this->returnValue(TRUE));
     $access_check->expects($this->atLeastOnce())->method('access')->will($this->returnValue(AccessInterface::KILL));
     $subrequest->attributes->set('value', 'upcasted_value');
     $this->container->set('test_access', $access_check);
     $this->accessManager->addCheckService('test_access', 'access');
     $this->accessManager->setChecks($this->routeCollection);
     $this->assertFalse($this->accessManager->checkNamedRoute('test_route_1', array(), $this->account));
 }
コード例 #18
0
 protected function getExtensions() : array
 {
     $urlGenerator = $this->prophesize(UrlGeneratorInterface::class);
     $urlGenerator->generate('entity_edit', ['id' => 42], Argument::any())->will(function ($args) {
         return '/entity/' . $args[1]['id'] . '/edit';
     });
     $urlGenerator->generate('entity_edit', ['id' => 42], Argument::any())->will(function ($args) {
         return '/entity/' . $args[1]['id'] . '/edit';
     });
     $urlGenerator->generate('entity_edit', ['id' => 42, 'foo' => 'bar'], Argument::any())->will(function ($args) {
         return '/entity/' . $args[1]['id'] . '/edit?foo=bar';
     });
     $urlGenerator->generate('entity_edit', ['id' => 42, 'username' => 'sheldon'], Argument::any())->will(function ($args) {
         return '/entity/' . $args[1]['id'] . '/edit?foo=bar';
     });
     $urlGenerator->generate('entity_delete', ['id' => 42], Argument::any())->will(function ($args) {
         return '/entity/' . $args[1]['id'] . '/delete';
     });
     $urlGenerator->generate('entity_list', [], Argument::any())->will(function () {
         return '/entity/list';
     });
     $urlGenerator->generate('entity_list', ['filter' => 'something', 'user' => 'sheldon'], Argument::any())->will(function () {
         return '/list/?user=sheldon&filter=something';
     });
     $requestStack = new RequestStack();
     $requestStack->push(Request::create('/datagrid'));
     return [new PreloadedExtension([], [ActionType::class => [new ActionTypeExtension($urlGenerator->reveal(), $requestStack)]])];
 }
コード例 #19
0
 public function register(Container $container)
 {
     $container['request'] = function ($c) {
         return Request::createFromGlobals();
     };
     $container['requestStack'] = function ($c) {
         $stack = new RequestStack();
         $stack->push($c['request']);
         return $stack;
     };
     $container['requestContext'] = function ($c) {
         $rc = new RequestContext();
         $rc->fromRequest($c['request']);
         return $rc;
     };
     $container['resolver'] = function ($c) {
         return new ControllerResolver();
     };
     $container['httpKernel'] = function ($c) {
         return new HttpKernel($c['dispatcher'], $c['resolver'], $c['requestStack']);
     };
     $container['router'] = function ($c) {
         $router = new ChainRouter($c['logger']);
         $router->add($c['staticRouter']);
         $router->add($c['nodeRouter']);
         return $router;
     };
     $container['staticRouter'] = function ($c) {
         return new StaticRouter($c['routeCollection'], ['cache_dir' => (bool) $c['config']['devMode'] ? null : ROADIZ_ROOT . '/cache/routing', 'debug' => (bool) $c['config']['devMode'], 'generator_cache_class' => 'StaticUrlGenerator', 'matcher_cache_class' => 'StaticUrlMatcher'], $c['requestContext'], $c['logger']);
     };
     $container['nodeRouter'] = function ($c) {
         return new NodeRouter($c['em'], ['cache_dir' => (bool) $c['config']['devMode'] ? null : ROADIZ_ROOT . '/cache/routing', 'debug' => (bool) $c['config']['devMode'], 'generator_cache_class' => 'NodeUrlGenerator', 'matcher_cache_class' => 'NodeUrlMatcher'], $c['requestContext'], $c['logger'], $c['stopwatch']);
     };
     $container['urlGenerator'] = function ($c) {
         return $c['staticRouter']->getGenerator();
     };
     $container['httpUtils'] = function ($c) {
         return new HttpUtils($c['router'], $c['router']);
     };
     $container['routeListener'] = function ($c) {
         return new TimedRouteListener($c['router'], $c['requestContext'], null, $c['requestStack'], $c['stopwatch']);
     };
     $container['routeCollection'] = function ($c) {
         if (isset($c['config']['install']) && true === $c['config']['install']) {
             /*
              * Get Install routes
              */
             $installClassname = Kernel::INSTALL_CLASSNAME;
             $installClassname::setupDependencyInjection($c);
             return new InstallRouteCollection($installClassname);
         } else {
             /*
              * Get App routes
              */
             $rCollection = new RoadizRouteCollection($c['backendClass'], $c['frontendThemes'], SettingsBag::get('static_domain_name'), $c['stopwatch']);
             return $rCollection;
         }
     };
     return $container;
 }
コード例 #20
0
 /**
  * @covers ::getContext
  *
  * @dataProvider providerTestGetContext
  */
 public function testGetContext(array $query_args, $cache_context_parameter, $context) {
   $request_stack = new RequestStack();
   $request = Request::create('/', 'GET', $query_args);
   $request_stack->push($request);
   $cache_context = new QueryArgsCacheContext($request_stack);
   $this->assertSame($cache_context->getContext($cache_context_parameter), $context);
 }
コード例 #21
0
ファイル: Render.php プロジェクト: vigourouxjulien/thelia
 /**
  * @param $params
  * @return mixed|string
  * @throws SmartyPluginException
  */
 public function processRender($params)
 {
     if (null === $params["action"]) {
         throw new SmartyPluginException("You must declare the 'action' parameter in the 'render' smarty function");
     }
     $request = $this->prepareRequest($params);
     $this->requestStack->push($request);
     $controller = $this->controllerResolver->getController($request);
     $controllerParameters = $this->controllerResolver->getArguments($request, $controller);
     $response = call_user_func_array($controller, $controllerParameters);
     $this->requestStack->pop();
     if ($response instanceof Response) {
         return $response->getContent();
     }
     return $response;
 }
コード例 #22
0
 public function testdashboardActionAjaxLayout()
 {
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $pool = new Pool($container, 'title', 'logo.png');
     $pool->setTemplates(array('ajax' => 'ajax.html'));
     $templating = $this->getMock('Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface');
     $request = new Request();
     $request->headers->set('X-Requested-With', 'XMLHttpRequest');
     $requestStack = null;
     if (class_exists('Symfony\\Component\\HttpFoundation\\RequestStack')) {
         $requestStack = new RequestStack();
         $requestStack->push($request);
     }
     $values = array('sonata.admin.pool' => $pool, 'templating' => $templating, 'request' => $request, 'request_stack' => $requestStack);
     $container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use($values) {
         return $values[$id];
     }));
     $container->expects($this->any())->method('getParameter')->will($this->returnCallback(function ($name) {
         if ($name == 'sonata.admin.configuration.dashboard_blocks') {
             return array();
         }
     }));
     $container->expects($this->any())->method('has')->will($this->returnCallback(function ($id) {
         if ($id == 'templating') {
             return true;
         }
         return false;
     }));
     $controller = new CoreController();
     $controller->setContainer($container);
     $response = $controller->dashboardAction($request);
     $this->isInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response);
 }
 /**
  * @dataProvider isActivatedProvider
  */
 public function testIsActivated($url, $record, $expected)
 {
     $requestStack = new RequestStack();
     $requestStack->push(Request::create($url));
     $strategy = new NotFoundActivationStrategy($requestStack, array('^/foo', 'bar'), Logger::WARNING);
     $this->assertEquals($expected, $strategy->isHandlerActivated($record));
 }
コード例 #24
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->viewStorage = $this->getMock('Drupal\\Core\\Entity\\EntityStorageInterface');
     $this->executableFactory = $this->getMockBuilder('Drupal\\views\\ViewExecutableFactory')->disableOriginalConstructor()->getMock();
     $this->renderer = $this->getMock('\\Drupal\\Core\\Render\\RendererInterface');
     $this->renderer->expects($this->any())->method('render')->will($this->returnCallback(function (array &$elements) {
         $elements['#attached'] = [];
         return isset($elements['#markup']) ? $elements['#markup'] : '';
     }));
     $this->renderer->expects($this->any())->method('executeInRenderContext')->willReturnCallback(function (RenderContext $context, callable $callable) {
         return $callable();
     });
     $this->currentPath = $this->getMockBuilder('Drupal\\Core\\Path\\CurrentPathStack')->disableOriginalConstructor()->getMock();
     $this->redirectDestination = $this->getMock('\\Drupal\\Core\\Routing\\RedirectDestinationInterface');
     $this->viewAjaxController = new ViewAjaxController($this->viewStorage, $this->executableFactory, $this->renderer, $this->currentPath, $this->redirectDestination);
     $element_info_manager = $this->getMock('\\Drupal\\Core\\Render\\ElementInfoManagerInterface');
     $element_info_manager->expects($this->any())->method('getInfo')->with('markup')->willReturn(['#pre_render' => [[Markup::class, 'ensureMarkupIsSafe']], '#defaults_loaded' => TRUE]);
     $request_stack = new RequestStack();
     $request_stack->push(new Request());
     $args = [$this->getMock('\\Drupal\\Core\\Controller\\ControllerResolverInterface'), $this->getMock('\\Drupal\\Core\\Theme\\ThemeManagerInterface'), $element_info_manager, $this->getMock('\\Drupal\\Core\\Render\\RenderCacheInterface'), $request_stack, ['required_cache_contexts' => ['languages:language_interface', 'theme']]];
     $this->renderer = $this->getMockBuilder('Drupal\\Core\\Render\\Renderer')->setConstructorArgs($args)->setMethods(NULL)->getMock();
     $container = new ContainerBuilder();
     $container->set('renderer', $this->renderer);
     \Drupal::setContainer($container);
 }
 protected function setUp()
 {
     parent::setUp();
     $this->dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $this->router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface');
     $router = $this->router;
     $this->requestStack = new RequestStack();
     /* @var Request $request */
     $request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request');
     $this->requestStack->push($request);
     /* @var EventDispatcherInterface $dispatcher */
     $dispatcher = $this->dispatcher;
     /* @var RouterInterface $router */
     $this->factory = Forms::createFormFactoryBuilder()->addExtensions($this->getExtensions())->addTypeExtension(new ChoiceSelect2TypeExtension($dispatcher, $this->requestStack, $router, $this->getExtensionTypeName(), 10))->addTypeExtension(new BaseChoiceSelect2TypeExtension($this->getExtensionTypeName()))->getFormFactory();
     $this->builder = new FormBuilder(null, null, $dispatcher, $this->factory);
 }
コード例 #26
0
 /**
  * Sets up a request object on the request stack.
  *
  * @param string $method
  *   The HTTP method to use for the request. Defaults to 'GET'.
  */
 protected function setUpRequest($method = 'GET')
 {
     $request = Request::create('/', $method);
     // Ensure that the request time is set as expected.
     $request->server->set('REQUEST_TIME', (int) $_SERVER['REQUEST_TIME']);
     $this->requestStack->push($request);
 }
 protected function setUp()
 {
     parent::setUp();
     \Locale::setDefault('en');
     $this->dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $this->router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface');
     $this->requestStack = new RequestStack();
     /* @var Request $request */
     $request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request');
     $this->requestStack->push($request);
     $this->router->expects($this->any())->method('generate')->will($this->returnCallback(function ($param) {
         return '/' . $param;
     }));
     $this->factory = Forms::createFormFactoryBuilder()->addExtensions($this->getExtensions())->addTypeExtension(new ChoiceSelect2TypeExtension($this->dispatcher, $this->requestStack, $this->router, $this->getExtensionTypeName(), 10))->getFormFactory();
     $this->dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $this->builder = new FormBuilder(null, null, $this->dispatcher, $this->factory);
 }
コード例 #28
0
 public function getRequestStack($request = null)
 {
     $requestStack = new RequestStack();
     if ($request) {
         $requestStack->push($request);
     }
     $this->container->expects($this->once())->method('get')->with('request_stack')->willReturn($requestStack);
 }
コード例 #29
0
 /**
  * Tests the get method.
  *
  * @covers ::get
  */
 public function testGet()
 {
     $request_1 = new Request();
     $request_2 = new Request();
     $this->requestStack->push($request_1);
     $executable = $this->viewExecutableFactory->get($this->view);
     $this->assertInstanceOf('Drupal\\views\\ViewExecutable', $executable);
     $this->assertSame($executable->getRequest(), $request_1);
     $this->assertSame($executable->getUser(), $this->user);
     // Call get() again to ensure a new executable is created with the other
     // request object.
     $this->requestStack->push($request_2);
     $executable = $this->viewExecutableFactory->get($this->view);
     $this->assertInstanceOf('Drupal\\views\\ViewExecutable', $executable);
     $this->assertSame($executable->getRequest(), $request_2);
     $this->assertSame($executable->getUser(), $this->user);
 }
コード例 #30
0
 /**
  * @covers ::getContext
  *
  * @dataProvider providerTestGetContext
  */
 public function testgetContext($original_path, $context)
 {
     $request_stack = new RequestStack();
     $request = Request::create($original_path);
     $request_stack->push($request);
     $cache_context = new PathParentCacheContext($request_stack);
     $this->assertSame($cache_context->getContext(), $context);
 }