RequestStack example

$this->setMockContainerService('queue', $queue);

    $this->assertNotNull(\Drupal::queue('test_queue', TRUE));
  }

  /** * Tests the testRequestStack() method. * * @covers ::requestStack */
  public function testRequestStack() {
    $request_stack = new RequestStack();
    $this->setMockContainerService('request_stack', $request_stack);

    $this->assertSame($request_stack, \Drupal::requestStack());
  }

  /** * Tests the keyValue() method. * * @covers ::keyValue */
  public function testKeyValue() {
    
$this->assertLessThanOrEqual(new \DateTimeImmutable('now', new \DateTimeZone('UTC'))new \DateTimeImmutable($response->headers->get('Expires')));
    }

    public function testGetSessionIsCalledOnce()
    {
        $session = $this->createMock(Session::class);
        $session->expects($this->exactly(1))->method('getName')->willReturn('PHPSESSID');
        $sessionFactory = $this->createMock(SessionFactory::class);
        $sessionFactory->expects($this->once())->method('createSession')->willReturn($session);
        $kernel = $this->createMock(KernelInterface::class);

        $requestStack = new RequestStack();
        $requestStack->push($mainRequest = new Request([][][][][]['HTTPS' => 'on']));

        $container = new Container();
        $container->set('session_factory', $sessionFactory);
        $container->set('request_stack', $requestStack);

        $event = new RequestEvent($kernel$mainRequest, HttpKernelInterface::MAIN_REQUEST);

        $listener = new SessionListener($container);
        $listener->onKernelRequest($event);

        


            $dumper->dump($var);
        };
    }

    private static function getDefaultContextProviders(): array
    {
        $contextProviders = [];

        if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && class_exists(Request::class)) {
            $requestStack = new RequestStack();
            $requestStack->push(Request::createFromGlobals());
            $contextProviders['request'] = new RequestContextProvider($requestStack);
        }

        $fileLinkFormatter = class_exists(FileLinkFormatter::class) ? new FileLinkFormatter(null, $requestStack ?? null) : null;

        return $contextProviders + [
            'cli' => new CliContextProvider(),
            'source' => new SourceContextProvider(null, null, $fileLinkFormatter),
        ];
    }
}
file_get_contents(__DIR__ . '/css_test_files/css_input_with_import.css.optimized.css'),
        file_get_contents(__DIR__ . '/css_test_files/css_subfolder/css_input_with_import.css.optimized.css')
      );
    $mock_theme_manager = $this->createMock(ThemeManagerInterface::class);
    $mock_dependency_resolver = $this->createMock(LibraryDependencyResolverInterface::class);
    $mock_state = $this->createMock(StateInterface::class);
    $mock_file_system = $this->createMock(FileSystemInterface::class);
    $mock_config_factory = $this->createMock(ConfigFactoryInterface::class);
    $mock_file_url_generator = $this->createMock(FileUrlGeneratorInterface::class);
    $mock_time = $this->createMock(TimeInterface::class);
    $mock_language = $this->createMock(LanguageManagerInterface::class);
    $optimizer = new CssCollectionOptimizerLazy($mock_grouper$mock_optimizer$mock_theme_manager$mock_dependency_resolvernew RequestStack()$mock_file_system$mock_config_factory$mock_file_url_generator$mock_time$mock_language$mock_state);
    $gpl_license = [
      'name' => 'GNU-GPL-2.0-or-later',
      'url' => 'https://www.drupal.org/licensing/faq',
      'gpl-compatible' => TRUE,
    ];
    $aggregate = $optimizer->optimizeGroup(
      [
        'items' => [
          'core/modules/system/tests/modules/common_test/common_test_css_import.css' => [
            'type' => 'file',
            'data' => 'core/modules/system/tests/modules/common_test/common_test_css_import.css',
            

  protected $session;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->request = new Request();

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

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

  /** * @covers ::getContext */
  public function testSameContextForSameSession() {
    $this->request->setSession($this->session);
    
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\VarDumper\Dumper\ContextProvider\RequestContextProvider;

/** * @requires function \Symfony\Component\HttpFoundation\RequestStack::__construct */
class RequestContextProviderTest extends TestCase
{
    public function testGetContextOnNullRequest()
    {
        $requestStack = new RequestStack();
        $provider = new RequestContextProvider($requestStack);

        $this->assertNull($provider->getContext());
    }

    public function testGetContextOnRequest()
    {
        $request = Request::create('https://example.org/', 'POST');
        $request->attributes->set('_controller', 'MyControllerClass');

        $requestStack = new RequestStack();
        

class RequestStackLegacyTest extends UnitTestCase {

  /** * Tests deprecation message in our subclassed RequestStack. * * @covers ::getMainRequest */
  public function testGetMainRequestDeprecation() {
    $stack = new RequestStack();

    $this->expectDeprecation('The Drupal\Core\Http\RequestStack is deprecated in drupal:10.0.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3265357');
    $this->assertNull($stack->getMainRequest());
  }

}

  protected $pathProcessor;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->requestStack = new RequestStack();
    $this->pathProcessor = $this->createMock('Drupal\Core\PathProcessor\OutboundPathProcessorInterface');
    $this->unroutedUrlAssembler = new UnroutedUrlAssembler($this->requestStack, $this->pathProcessor);
  }

  /** * @covers ::assemble */
  public function testAssembleWithNeitherExternalNorDomainLocalUri() {
    $this->expectException(\InvalidArgumentException::class);
    $this->unroutedUrlAssembler->assemble('wrong-url');
  }

  
$listener->onKernelResponse(new ResponseEvent($httpKernel$request, HttpKernelInterface::MAIN_REQUEST, new Response()));
        $this->assertEmpty($dispatcher->getListeners());
    }

    protected function runSessionOnKernelResponse($newToken$original = null)
    {
        $session = new Session(new MockArraySessionStorage());
        $request = new Request();
        $request->attributes->set('_security_firewall_run', '_security_session');
        $request->setSession($session);
        $requestStack = new RequestStack();
        $requestStack->push($request);

        if (null !== $original) {
            $session->set('_security_session', $original);
        }

        $factories = ['request_stack' => fn () => $requestStack];
        $tokenStorage = new UsageTrackingTokenStorage(new TokenStorage()new class($factories) implements ContainerInterface {
            use ServiceLocatorTrait;
        });

        

    private const SESSION_NAMESPACE = 'foobar';

    private Session $session;
    private SessionTokenStorage $storage;

    protected function setUp(): void
    {
        $this->session = new Session(new MockArraySessionStorage());
        $request = new Request();
        $request->setSession($this->session);
        $requestStack = new RequestStack();
        $requestStack->push($request);
        $this->storage = new SessionTokenStorage($requestStack, self::SESSION_NAMESPACE);
    }

    public function testStoreTokenInNotStartedSessionStartsTheSession()
    {
        $this->storage->setToken('token_id', 'TOKEN');

        $this->assertTrue($this->session->isStarted());
    }

    
->method('createInstance')
      ->willReturnMap([
        ['default', $values['display']['default']$default_display],
        ['page', $values['display']['page_1']$page_display],
        ['page', $values['display']['page_2']$page_display],
        ['page', $values['display']['page_3']$page_display],
        ['embed', $values['display']['embed']$embed_display],
      ]);

    $container = new ContainerBuilder();
    $user = $this->createMock('Drupal\Core\Session\AccountInterface');
    $request_stack = new RequestStack();
    $request_stack->push(new Request());
    $views_data = $this->getMockBuilder('Drupal\views\ViewsData')
      ->disableOriginalConstructor()
      ->getMock();
    $route_provider = $this->createMock('Drupal\Core\Routing\RouteProviderInterface');
    $executable_factory = new ViewExecutableFactory($user$request_stack$views_data$route_provider);
    $container->set('views.executable', $executable_factory);
    $container->set('plugin.manager.views.display', $display_manager);
    \Drupal::setContainer($container);

    // Setup a view list builder with a mocked buildOperations method,
$context = $this->createMock(RequestStack::class);
        $renderer = new FragmentHandler($context);

        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage('The "inline" renderer does not exist.');

        $renderer->render('/foo');
    }

    public function testGenerateFragmentUri()
    {
        $requestStack = new RequestStack();
        $requestStack->push(Request::create('/'));

        $fragmentHandler = new FragmentHandler($requestStack);
        $fragmentUriGenerator = new FragmentUriGenerator('/_fragment', new UriSigner('s3cr3t')$requestStack);

        $kernelRuntime = new HttpKernelRuntime($fragmentHandler$fragmentUriGenerator);

        $loader = new ArrayLoader([
            'index' => sprintf(<<<TWIG {{ fragment_uri(controller("%s::templateAction", {template: "foo.html.twig"})) }} TWIG
                ,
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", $output);

        ob_start();
        $collector->__destruct();
        $this->assertEmpty(ob_get_clean());
    }

    public function testNullContentTypeWithNoDebugEnv()
    {
        $request = new Request();
        $requestStack = new RequestStack();
        $requestStack->push($request);

        $response = new Response('<html><head></head><body></body></html>');
        $response->headers->set('Content-Type', null);
        $response->headers->set('X-Debug-Token', 'xxxxxxxx');

        $collector = new DumpDataCollector(null, null, null, $requestStack);
        $collector->collect($request$response);

        ob_start();
        $collector->__destruct();
        
$controller->setContainer($container);

        $controller->getParameter('foo');
    }

    public function testForward()
    {
        $request = Request::create('/');
        $request->setLocale('fr');
        $request->setRequestFormat('xml');

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

        $kernel = $this->createMock(HttpKernelInterface::class);
        $kernel->expects($this->once())->method('handle')->willReturnCallback(fn (Request $request) => new Response($request->getRequestFormat().'--'.$request->getLocale()));

        $container = new Container();
        $container->set('request_stack', $requestStack);
        $container->set('http_kernel', $kernel);

        $controller = $this->createController();
        $controller->setContainer($container);

        
/** * The tested memory flood backend. * * @var \Drupal\Core\Flood\MemoryBackend */
  protected $flood;

  protected function setUp(): void {
    parent::setUp();

    $request = new RequestStack();
    $request_mock = $this->getMockBuilder(Request::class)
      ->onlyMethods(['getClientIp'])
      ->getMock();
    $request->push($request_mock);
    $this->flood = new MemoryBackend($request);
  }

  /** * Tests an allowed flood event. */
  public function testAllowedProceeding() {
    
Home | Imprint | This part of the site doesn't use cookies.