InputBag example

$request->attributes->set('foo', '1');
    $route_match = RouteMatch::createFromRequest($request);
    $this->assertSame('test_route', $route_match->getRouteName());
    $this->assertSame($route$route_match->getRouteObject());
    $this->assertSame(['foo' => '1']$route_match->getParameters()->all());
    $this->assertSame([]$route_match->getRawParameters()->all());

    // A routed request with parameter upcasting.     $foo = new \stdClass();
    $foo->value = 1;
    $request->attributes->set('foo', $foo);
    $request->attributes->set('_raw_variables', new InputBag(['foo' => '1']));
    $route_match = RouteMatch::createFromRequest($request);
    $this->assertSame(['foo' => $foo]$route_match->getParameters()->all());
    $this->assertSame(['foo' => '1']$route_match->getRawParameters()->all());
  }

}
$applies_check = new EntityCreateAccessCheck($this->entityTypeManager);

    $route = $this->getMockBuilder('Symfony\Component\Routing\Route')
      ->disableOriginalConstructor()
      ->getMock();
    $route->expects($this->any())
      ->method('getRequirement')
      ->with('_entity_create_access')
      ->willReturn($requirement);

    $raw_variables = new InputBag();
    if ($entity_bundle) {
      $raw_variables->set('bundle_argument', $entity_bundle);
    }

    $route_match = $this->createMock('Drupal\Core\Routing\RouteMatchInterface');
    $route_match->expects($this->any())
      ->method('getRawParameters')
      ->willReturn($raw_variables);

    $account = $this->createMock('Drupal\Core\Session\AccountInterface');
    $this->assertEquals($expected_access_result$applies_check->access($route$route_match$account));
  }


      // Make view links come back to preview.
      // Also override the current path so we get the pager, and make sure the       // Request object gets all of the proper values from $_SERVER.       $request = Request::createFromGlobals();
      $request->attributes->set(RouteObjectInterface::ROUTE_NAME, 'entity.view.preview_form');
      $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, \Drupal::service('router.route_provider')->getRouteByName('entity.view.preview_form'));
      $request->attributes->set('view', $this->storage);
      $request->attributes->set('display_id', $display_id);
      $raw_parameters = new InputBag();
      $raw_parameters->set('view', $this->id());
      $raw_parameters->set('display_id', $display_id);
      $request->attributes->set('_raw_variables', $raw_parameters);

      foreach ($args as $key => $arg) {
        $request->attributes->set('arg_' . $key$arg);
      }
      $request_stack->push($request);

      // Suppress contextual links of entities within the result set during a       // Preview.
$this->setupLocalTaskManager();

    $this->argumentResolver->expects($this->any())
      ->method('getArguments')
      ->willReturn([]);

    $this->routeMatch->expects($this->any())
      ->method('getRouteName')
      ->willReturn('menu_local_task_test_tasks_view');
    $this->routeMatch->expects($this->any())
      ->method('getRawParameters')
      ->willReturn(new InputBag());

    $cacheability = new CacheableMetadata();
    $this->manager->getTasksBuild('menu_local_task_test_tasks_view', $cacheability);

    // Ensure that all cacheability metadata is merged together.     $this->assertEqualsCanonicalizing(['tag.example1', 'tag.example2']$cacheability->getCacheTags());
    $this->assertEqualsCanonicalizing(['context.example1', 'context.example2', 'route', 'user.permissions']$cacheability->getCacheContexts());
  }

  protected function setupFactoryAndLocalTaskPlugins(array $definitions$active_plugin_id) {
    $map = [];
    

  protected function setupRequestMatch(Request $request) {
    $path = $request->getPathInfo();
    $args = explode('/', ltrim($path, '/'));

    $request->attributes->set(RouteObjectInterface::ROUTE_NAME, 'system.db_update');
    $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, $this->getContainer()->get('router.route_provider')->getRouteByName('system.db_update'));
    $op = $args[0] ?: 'info';
    $request->attributes->set('op', $op);
    $request->attributes->set('_raw_variables', new InputBag(['op' => $op]));
  }

  /** * Checks if the current user has rights to access updates page. * * If the current user does not have the rights, an exception is thrown. * * @param \Symfony\Component\HttpFoundation\Request $request * The incoming request. * * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException * Thrown when update.php should not be accessible. */
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
use Symfony\Component\HttpFoundation\InputBag;
use Symfony\Component\HttpFoundation\Tests\Fixtures\FooEnum;

class InputBagTest extends TestCase
{
    use ExpectDeprecationTrait;

    public function testGet()
    {
        $bag = new InputBag(['foo' => 'bar', 'null' => null, 'int' => 1, 'float' => 1.0, 'bool' => false, 'stringable' => new class() implements \Stringable {
            public function __toString(): string
            {
                return 'strval';
            }
        }]);

        $this->assertSame('bar', $bag->get('foo'), '->get() gets the value of a string parameter');
        $this->assertSame('default', $bag->get('unknown', 'default'), '->get() returns second argument as default if a parameter is not defined');
        $this->assertNull($bag->get('null', 'default'), '->get() returns null if null is set');
        $this->assertSame(1, $bag->get('int'), '->get() gets the value of an int parameter');
        $this->assertSame(1.0, $bag->get('float'), '->get() gets the value of a float parameter');
        
$this->setupStubPathProcessor();

    $route_1 = new Route('/example');

    $this->requestMatcher->expects($this->exactly(1))
      ->method('matchRequest')
      ->willReturnCallback(function DRequest $request) use ($route_1) {
        if ($request->getPathInfo() == '/example') {
          return [
            RouteObjectInterface::ROUTE_NAME => 'example',
            RouteObjectInterface::ROUTE_OBJECT => $route_1,
            '_raw_variables' => new InputBag([]),
          ];
        }
      });

    $this->setupAccessManagerToAllow();

    $breadcrumb = $this->builder->build($this->createMock('Drupal\Core\Routing\RouteMatchInterface'));
    $this->assertEquals([0 => new Link('Home', new Url('<front>')), 1 => new Link('Example', new Url('example'))]$breadcrumb->getLinks());
    $this->assertEqualsCanonicalizing([
      'url.path.is_front',
      'url.path.parent',
      
/** * {@inheritdoc} */
  public function getRawParameter($parameter_name) {
    return NULL;
  }

  /** * {@inheritdoc} */
  public function getRawParameters() {
    return new InputBag();
  }

}
$this->assertEquals(new TranslatableMarkup('static title', []['context' => 'context']$this->translationManager)$this->titleResolver->getTitle($request$route));
  }

  /** * Tests a static title with a parameter. * * @see \Drupal\Core\Controller\TitleResolver::getTitle() * * @dataProvider providerTestStaticTitleWithParameter */
  public function testStaticTitleWithParameter($title$expected_title) {
    $raw_variables = new InputBag(['test' => 'value', 'test2' => 'value2']);
    $request = new Request();
    $request->attributes->set('_raw_variables', $raw_variables);

    $route = new Route('/test-route', ['_title' => $title]);
    $this->assertEquals($expected_title$this->titleResolver->getTitle($request$route));
  }

  public function providerTestStaticTitleWithParameter() {
    $translation_manager = $this->createMock('\Drupal\Core\StringTranslation\TranslationInterface');
    return [
      ['static title @test', new TranslatableMarkup('static title @test', ['@test' => 'value', '%test' => 'value', '@test2' => 'value2', '%test2' => 'value2'][]$translation_manager)],
      [

  protected function getRouteMatch($name, Route $route, array $parameters, array $raw_parameters) {
    $request_stack = new RequestStack();
    $request = new Request();
    $request_stack->push($request);

    $request = $request_stack->getCurrentRequest();
    $request->attributes = new ParameterBag($parameters);
    $request->attributes->set(RouteObjectInterface::ROUTE_NAME, $name);
    $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, $route);
    $request->attributes->set('_raw_variables', new InputBag($raw_parameters));
    return new CurrentRouteMatch($request_stack);
  }

  /** * @covers ::__construct * @covers ::getRouteObject * @covers ::getCurrentRouteMatch * @covers ::getRouteMatch */
  public function testGetCurrentRouteObject() {

    

    public function initialize(array $query = [], array $request = [], array $attributes = [], array $cookies = [], array $files = [], array $server = []$content = null)
    {
        $this->request = new InputBag($request);
        $this->query = new InputBag($query);
        $this->attributes = new ParameterBag($attributes);
        $this->cookies = new InputBag($cookies);
        $this->files = new FileBag($files);
        $this->server = new ServerBag($server);
        $this->headers = new HeaderBag($this->server->getHeaders());

        $this->content = $content;
        unset($this->languages);
        unset($this->charsets);
        unset($this->encodings);
        

  public function testIsValidWithLinkToAnyPageAccount() {
    $this->account->expects($this->once())
      ->method('hasPermission')
      ->with('link to any page')
      ->willReturn(TRUE);
    $this->accessAwareRouter->expects($this->never())
      ->method('match');
    $this->accessUnawareRouter->expects($this->once())
      ->method('match')
      ->with('/test-path')
      ->willReturn([RouteObjectInterface::ROUTE_NAME => 'test_route', '_raw_variables' => new InputBag(['key' => 'value'])]);
    $this->pathProcessor->expects($this->once())
      ->method('processInbound')
      ->willReturnArgument(0);

    $this->assertTrue($this->pathValidator->isValid('test-path'));
  }

  /** * Tests the isValid() method without the 'link to any page' permission. * * @covers ::isValid */

  public function __construct($route_name, Route $route, array $parameters = [], array $raw_parameters = []) {
    $this->routeName = $route_name;
    $this->route = $route;

    // Pre-filter parameters.     $route_params = $this->getParameterNames();
    $parameters = array_intersect_key($parameters$route_params);
    $raw_parameters = array_intersect_key($raw_parameters$route_params);
    $this->parameters = new ParameterBag($parameters);
    $this->rawParameters = new InputBag($raw_parameters);
  }

  /** * Creates a RouteMatch from a request. * * @param \Symfony\Component\HttpFoundation\Request $request * A request object. * * @return \Drupal\Core\Routing\RouteMatchInterface * A new RouteMatch object if there's a matched route for the request. * A new NullRouteMatch object otherwise (e.g., on a 404 page or when * invoked prior to routing). */
$route = new Route('/foo/{var_name}', []['_entity_access' => 'var_name.update']['parameters' => ['var_name' => ['type' => 'entity:node']]]);
    /** @var \Drupal\Core\Session\AccountInterface $account */
    $account = $this->prophesize(AccountInterface::class)->reveal();

    /** @var \Drupal\node\NodeInterface|\Prophecy\Prophecy\ObjectProphecy $route_match */
    $node = $this->prophesize(NodeInterface::class);
    $node->access('update', $account, TRUE)->willReturn(AccessResult::allowed());
    $node = $node->reveal();

    /** @var \Drupal\Core\Routing\RouteMatchInterface|\Prophecy\Prophecy\ObjectProphecy $route_match */
    $route_match = $this->prophesize(RouteMatchInterface::class);
    $route_match->getRawParameters()->willReturn(new InputBag(['var_name' => 1]));
    $route_match->getParameters()->willReturn(new ParameterBag(['var_name' => $node]));
    $route_match = $route_match->reveal();

    $access_check = new EntityAccessCheck();
    $this->assertEquals(AccessResult::allowed()$access_check->access($route$route_match$account));
  }

  /** * @covers ::access */
  public function testAccessWithTypePlaceholder() {
    

    public function initialize(array $query = [], array $request = [], array $attributes = [], array $cookies = [], array $files = [], array $server = []$content = null)
    {
        $this->request = new InputBag($request);
        $this->query = new InputBag($query);
        $this->attributes = new ParameterBag($attributes);
        $this->cookies = new InputBag($cookies);
        $this->files = new FileBag($files);
        $this->server = new ServerBag($server);
        $this->headers = new HeaderBag($this->server->getHeaders());

        $this->content = $content;
        $this->languages = null;
        $this->charsets = null;
        $this->encodings = null;
        
Home | Imprint | This part of the site doesn't use cookies.