Commit 61c3ee55 authored by catch's avatar catch
Browse files

task: #3308418 Improve more error messages on unrouted URLs

By: ronaldmulero
By: smustgrave
By: dcam
parent b4cd8ebc
Loading
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -588,7 +588,7 @@ public function getRouteName() {
   */
  public function getRouteParameters() {
    if ($this->unrouted) {
      throw new \UnexpectedValueException('External URLs do not have internal route parameters.');
      throw new \UnexpectedValueException($this->getUri() . ' has no corresponding route.');
    }

    return $this->routeParameters;
@@ -607,7 +607,7 @@ public function getRouteParameters() {
   */
  public function setRouteParameters($parameters) {
    if ($this->unrouted) {
      throw new \UnexpectedValueException('External URLs do not have route parameters.');
      throw new \UnexpectedValueException($this->getUri() . ' has no corresponding route.');
    }
    $this->routeParameters = $parameters;
    return $this;
@@ -628,7 +628,7 @@ public function setRouteParameters($parameters) {
   */
  public function setRouteParameter($key, $value) {
    if ($this->unrouted) {
      throw new \UnexpectedValueException('External URLs do not have route parameters.');
      throw new \UnexpectedValueException($this->getUri() . ' has no corresponding route.');
    }
    $this->routeParameters[$key] = $value;
    return $this;
+25 −0
Original line number Diff line number Diff line
@@ -426,9 +426,34 @@ public function testGetRouteParameters($urls): void {
  public function testGetRouteParametersWithExternalUrl(): void {
    $url = Url::fromUri('http://example.com');
    $this->expectException(\UnexpectedValueException::class);
    $this->expectExceptionMessage('http://example.com has no corresponding route.');
    $url->getRouteParameters();
  }

  /**
   * Tests the setRouteParameters() with an unrouted URL.
   *
   * @legacy-covers ::setRouteParameters
   */
  public function testSetRouteParametersWithUnroutedUrl(): void {
    $url = Url::fromUri('https://example.com');
    $this->expectException(\UnexpectedValueException::class);
    $this->expectExceptionMessage('https://example.com has no corresponding route.');
    $url->setRouteParameters(['foo' => 'bar']);
  }

  /**
   * Tests the setRouteParameter() with an unrouted URL.
   *
   * @legacy-covers ::setRouteParameter
   */
  public function testSetRouteParameterWithUnroutedUrl(): void {
    $url = Url::fromUri('https://example.com');
    $this->expectException(\UnexpectedValueException::class);
    $this->expectExceptionMessage('https://example.com has no corresponding route.');
    $url->setRouteParameter('foo', 'bar');
  }

  /**
   * Tests the getOptions() method.
   *