fromUri example

'menu_name' => 'main',
    ]);
    $menu_link->save();

    return $menu_link;
  }

  /** * {@inheritdoc} */
  protected function getExpectedDocument() {
    $base_url = Url::fromUri('base:/jsonapi/menu_link_content/menu_link_content/' . $this->entity->uuid())->setAbsolute();
    $self_url = clone $base_url;
    $version_identifier = 'id:' . $this->entity->getRevisionId();
    $self_url = $self_url->setOption('query', ['resourceVersion' => $version_identifier]);
    $version_query_string = '?resourceVersion=' . urlencode($version_identifier);
    return [
      'jsonapi' => [
        'meta' => [
          'links' => [
            'self' => ['href' => 'http://jsonapi.org/format/1.0/'],
          ],
        ],
        


    $camelids->save();

    return $camelids;
  }

  /** * {@inheritdoc} */
  protected function getExpectedDocument() {
    $self_url = Url::fromUri('base:/jsonapi/media_type/media_type/' . $this->entity->uuid())->setAbsolute()->toString(TRUE)->getGeneratedUrl();
    return [
      'jsonapi' => [
        'meta' => [
          'links' => [
            'self' => ['href' => 'http://jsonapi.org/format/1.0/'],
          ],
        ],
        'version' => '1.0',
      ],
      'links' => [
        'self' => ['href' => $self_url],
      ],
'methods' => ['POST'],
        'formats' => [static::$format],
        'authentication' => isset(static::$auth) ? [static::$auth] : [],
      ],
      'status' => TRUE,
    ])->save();
    $this->refreshTestStateAfterRestConfigChange();

    $this->initAuthentication();

    // POST to create a File entity.     $url = Url::fromUri('base:file/upload/media/camelids/field_media_file');
    $url->setOption('query', ['_format' => static::$format]);
    $request_options = [];
    $request_options[RequestOptions::HEADERS] = [
      // Set the required (and only accepted) content type for the request.       'Content-Type' => 'application/octet-stream',
      // Set the required Content-Disposition header for the file name.       'Content-Disposition' => 'file; filename="drupal rocks 🤘.txt"',
    ];
    $request_options[RequestOptions::BODY] = 'Drupal is the best!';
    $request_options = NestedArray::mergeDeep($request_options$this->getAuthenticationRequestOptions('POST'));
    $response = $this->request('POST', $url$request_options);
    

    ]);
    $block->save();

    return $block;
  }

  /** * {@inheritdoc} */
  protected function getExpectedDocument() {
    $self_url = Url::fromUri('base:/jsonapi/block/block/' . $this->entity->uuid())->setAbsolute()->toString(TRUE)->getGeneratedUrl();
    return [
      'jsonapi' => [
        'meta' => [
          'links' => [
            'self' => ['href' => 'http://jsonapi.org/format/1.0/'],
          ],
        ],
        'version' => '1.0',
      ],
      'links' => [
        'self' => ['href' => $self_url],
      ],
if ($parsed_url['path'] == '<front>') {
      return new Url('<front>', []$options);
    }
    elseif ($parsed_url['path'] == '<none>') {
      return new Url('<none>', []$options);
    }
    elseif (UrlHelper::isExternal($path) && UrlHelper::isValid($path)) {
      if (empty($parsed_url['path'])) {
        return FALSE;
      }
      return Url::fromUri($path);
    }

    $request = Request::create('/' . $path);
    $attributes = $this->getPathAttributes($path$request$access_check);

    if (!$attributes) {
      return FALSE;
    }

    $route_name = $attributes[RouteObjectInterface::ROUTE_NAME];
    $route_parameters = $attributes['_raw_variables']->all();

    

      ])
      ->save();

    return $camelids;
  }

  /** * {@inheritdoc} */
  protected function getExpectedDocument() {
    $self_url = Url::fromUri('base:/jsonapi/editor/editor/' . $this->entity->uuid())->setAbsolute()->toString(TRUE)->getGeneratedUrl();
    return [
      'jsonapi' => [
        'meta' => [
          'links' => [
            'self' => ['href' => 'http://jsonapi.org/format/1.0/'],
          ],
        ],
        'version' => '1.0',
      ],
      'links' => [
        'self' => ['href' => $self_url],
      ],
'mode' => 'default',
    ]);
    $form_display->save();

    return $form_display;
  }

  /** * {@inheritdoc} */
  protected function getExpectedDocument() {
    $self_url = Url::fromUri('base:/jsonapi/entity_form_display/entity_form_display/' . $this->entity->uuid())->setAbsolute()->toString(TRUE)->getGeneratedUrl();
    return [
      'jsonapi' => [
        'meta' => [
          'links' => [
            'self' => ['href' => 'http://jsonapi.org/format/1.0/'],
          ],
        ],
        'version' => '1.0',
      ],
      'links' => [
        'self' => ['href' => $self_url],
      ],
    $this->testUsers[] = $this->createUser([], NULL, FALSE, ['uid' => 2]);
    $this->testUsers[] = $this->createUser([], NULL, FALSE, ['uid' => 3]);
    $this->serializer = $this->container->get('jsonapi.serializer');
  }

  /** * Tests the link collection normalizer. */
  public function testNormalize() {
    $link_context = new ResourceObject(new CacheableMetadata()new ResourceType('n/a', 'n/a', 'n/a'), 'n/a', NULL, []new LinkCollection([]));
    $link_collection = (new LinkCollection([]))
      ->withLink('related', new Link(new CacheableMetadata(), Url::fromUri('http://example.com/post/42'), 'related', ['title' => 'Most viewed']))
      ->withLink('related', new Link(new CacheableMetadata(), Url::fromUri('http://example.com/post/42'), 'related', ['title' => 'Top rated']))
      ->withContext($link_context);
    // Create the SUT.     $normalized = $this->getNormalizer()->normalize($link_collection)->getNormalization();
    $this->assertIsArray($normalized);
    foreach (array_keys($normalized) as $key) {
      $this->assertStringStartsWith('related', $key);
    }
    $this->assertSame([
      [
        'href' => 'http://example.com/post/42',
        
/** * Tests fromUri() method with a user-entered path not matching any route. * * @covers ::fromUri */
  public function testFromRoutedPathWithInvalidRoute() {
    $this->pathValidator->expects($this->once())
      ->method('getUrlIfValidWithoutAccessCheck')
      ->with('invalid-path')
      ->willReturn(FALSE);
    $url = Url::fromUri('internal:/invalid-path');
    $this->assertFalse($url->isRouted());
    $this->assertSame('base:invalid-path', $url->getUri());
  }

  /** * Tests fromUri() method with user-entered path matching a valid route. * * @covers ::fromUri */
  public function testFromRoutedPathWithValidRoute() {
    $url = Url::fromRoute('test_route');
    
if (!empty($trail) && !empty($parts)) {
      foreach ($trail as $path => $title) {
        // If the path is empty, generate the path from the <front> route. If         // the path does not start with a leading slash, then run it through         // Url::fromUri('base:')->toString() to get the correct base         // prepended.         if ($path == '') {
          $url = Url::fromRoute('<front>')->toString();
        }
        elseif ($path[0] != '/') {
          $url = Url::fromUri('base:' . $path)->toString();
        }
        else {
          $url = $path;
        }
        $part = array_shift($parts);
        $pass = ($pass && $part['href'] === $url && $part['text'] === Html::escape($title));
      }
    }
    elseif (!empty($trail) && empty($parts) || empty($trail) && !empty($parts)) {
      // Fail if there is no breadcrumb and we have a trail or breadcrumb       // exists but trail is empty.
public function testLinkXSS() {
    // Test link generator.     $text = $this->randomMachineName();
    $path = "<SCRIPT>alert('XSS')</SCRIPT>";
    $encoded_path = "3CSCRIPT%3Ealert%28%27XSS%27%29%3C/SCRIPT%3E";

    $link = Link::fromTextAndUrl($text, Url::fromUserInput('/' . $path))->toString();
    $this->assertStringContainsString($encoded_path$linknew FormattableMarkup('XSS attack @path was filtered by \Drupal\Core\Utility\LinkGeneratorInterface::generate().', ['@path' => $path]));
    $this->assertStringNotContainsString($path$linknew FormattableMarkup('XSS attack @path was filtered by \Drupal\Core\Utility\LinkGeneratorInterface::generate().', ['@path' => $path]));

    // Test \Drupal\Core\Url.     $link = Url::fromUri('base:' . $path)->toString();
    $this->assertStringContainsString($encoded_path$linknew FormattableMarkup('XSS attack @path was filtered by #theme', ['@path' => $path]));
    $this->assertStringNotContainsString($path$linknew FormattableMarkup('XSS attack @path was filtered by #theme', ['@path' => $path]));
  }

  /** * Tests that #type=link bubbles outbound route/path processors' metadata. */
  public function testLinkBubbleableMetadata() {
    \Drupal::service('module_installer')->install(['user']);

    $cases = [
      [
'id' => 'llama_set',
      'label' => 'Llama Set',
    ]);
    $set->save();
    return $set;
  }

  /** * {@inheritdoc} */
  protected function getExpectedDocument() {
    $self_url = Url::fromUri('base:/jsonapi/shortcut_set/shortcut_set/' . $this->entity->uuid())->setAbsolute()->toString(TRUE)->getGeneratedUrl();
    return [
      'jsonapi' => [
        'meta' => [
          'links' => [
            'self' => ['href' => 'http://jsonapi.org/format/1.0/'],
          ],
        ],
        'version' => '1.0',
      ],
      'links' => [
        'self' => ['href' => $self_url],
      ],

  public function getLink($text$url$attributes = []) {
    assert(is_string($url) || $url instanceof Url, '$url must be a string or object of type \Drupal\Core\Url');
    assert(is_array($attributes) || $attributes instanceof Attribute, '$attributes, if set, must be an array or object of type \Drupal\Core\Template\Attribute');

    if (!$url instanceof Url) {
      $url = Url::fromUri($url);
    }
    // The twig extension should not modify the original URL object, this     // ensures consistent rendering.     // @see https://www.drupal.org/node/2842399     $url = clone $url;
    if ($attributes) {
      if ($attributes instanceof Attribute) {
        $attributes = $attributes->toArray();
      }
      $url->mergeOptions(['attributes' => $attributes]);
    }
    

      ],
    ]);
    $pablo_format->save();
    return $pablo_format;
  }

  /** * {@inheritdoc} */
  protected function getExpectedDocument() {
    $self_url = Url::fromUri('base:/jsonapi/filter_format/filter_format/' . $this->entity->uuid())->setAbsolute()->toString(TRUE)->getGeneratedUrl();
    return [
      'jsonapi' => [
        'meta' => [
          'links' => [
            'self' => ['href' => 'http://jsonapi.org/format/1.0/'],
          ],
        ],
        'version' => '1.0',
      ],
      'links' => [
        'self' => ['href' => $self_url],
      ],
$this->assertSame($normalized['data']['attributes']['title'], 'dummy_title');
    $this->assertEquals($normalized['data']['id']$this->node->uuid());
    $this->assertSame([
      'data' => [
        'type' => 'node_type--node_type',
        'id' => NodeType::load('article')->uuid(),
        'meta' => [
          'drupal_internal__target_id' => 'article',
        ],
      ],
      'links' => [
        'related' => ['href' => Url::fromUri('internal:/jsonapi/node/article/' . $this->node->uuid() . '/node_type', ['query' => ['resourceVersion' => 'id:' . $this->node->getRevisionId()]])->setAbsolute()->toString(TRUE)->getGeneratedUrl()],
        'self' => ['href' => Url::fromUri('internal:/jsonapi/node/article/' . $this->node->uuid() . '/relationships/node_type', ['query' => ['resourceVersion' => 'id:' . $this->node->getRevisionId()]])->setAbsolute()->toString(TRUE)->getGeneratedUrl()],
      ],
    ]$normalized['data']['relationships']['node_type']);
    $this->assertTrue(!isset($normalized['data']['attributes']['created']));
    $this->assertEquals([
      'alt' => 'test alt',
      'title' => 'test title',
      'width' => 10,
      'height' => 11,
      'drupal_internal__target_id' => $this->file->id(),
    ]$normalized['data']['relationships']['field_image']['data']['meta']);
    
Home | Imprint | This part of the site doesn't use cookies.