Commit 1b0a4415 authored by catch's avatar catch
Browse files

Issue #3186821 by mohit_aghera, Dom., ankithashetty, Kristen Pol: Attribute...

Issue #3186821 by mohit_aghera, Dom., ankithashetty, Kristen Pol: Attribute “hreflang” not allowed on element “span” and “button” at this point
parent f3674e9b
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -170,13 +170,13 @@ public function generate($text, Url $url) {
    }
    if ($url->isRouted() && $url->getRouteName() === '<nolink>') {
      $generated_link = new GeneratedNoLink();
      unset($attributes['href']);
      unset($attributes['href'], $attributes['hreflang']);
      return $this->doGenerate($generated_link, $attributes, $variables);
    }
    if ($url->isRouted() && $url->getRouteName() === '<button>') {
      $generated_link = new GeneratedButton();
      $attributes['type'] = 'button';
      unset($attributes['href']);
      unset($attributes['href'], $attributes['hreflang']);
      return $this->doGenerate($generated_link, $attributes, $variables);
    }
    $generated_url = $url->toString(TRUE);
+18 −2
Original line number Diff line number Diff line
@@ -161,7 +161,7 @@ public function testGenerate() {
  public function testGenerateNoLink() {
    $this->urlGenerator->expects($this->never())
      ->method('generateFromRoute');
    $this->moduleHandler->expects($this->once())
    $this->moduleHandler->expects($this->exactly(2))
      ->method('alter')
      ->with('link', $this->isType('array'));

@@ -172,6 +172,14 @@ public function testGenerateNoLink() {
    $result = $this->linkGenerator->generate('Test', $url);
    $this->assertInstanceOf(GeneratedNoLink::class, $result);
    $this->assertSame('<span>Test</span>', (string) $result);

    // Validate removal of hreflang attributes.
    $url = Url::fromRoute('<nolink>', [], [
      'language' => new Language(['id' => 'de']),
    ]);
    $url->setUrlGenerator($this->urlGenerator);
    $result = $this->linkGenerator->generate('Test With Language', $url);
    $this->assertSame('<span>Test With Language</span>', (string) $result);
  }

  /**
@@ -208,7 +216,7 @@ public function testGenerateNone() {
  public function testGenerateButton() {
    $this->urlGenerator->expects($this->never())
      ->method('generateFromRoute');
    $this->moduleHandler->expects($this->once())
    $this->moduleHandler->expects($this->exactly(2))
      ->method('alter')
      ->with('link', $this->isType('array'));

@@ -218,6 +226,14 @@ public function testGenerateButton() {
    $result = $this->linkGenerator->generate('Test', $url);
    $this->assertInstanceOf(GeneratedButton::class, $result);
    $this->assertSame('<button type="button">Test</button>', (string) $result);

    // Validate removal of hreflang attributes.
    $url = new Url('<button>', [], [
      'language' => new Language(['id' => 'de']),
    ]);
    $url->setUrlGenerator($this->urlGenerator);
    $result = $this->linkGenerator->generate('Test With Language', $url);
    $this->assertSame('<button type="button">Test With Language</button>', (string) $result);
  }

  /**