assertLink example

/** @var \Drupal\Core\Session\AccountSwitcherInterface $account_switcher */
    $account_switcher = \Drupal::service('account_switcher');

    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = \Drupal::service('renderer');

    $account_switcher->switchTo($this->adminUser);
    $executable = Views::getView($view_id);
    $build = $executable->preview();
    $this->setRawContent($renderer->renderRoot($build));

    $this->assertLink('My comment title');
    $this->assertLink('Anonymous comment title');
    // Display plugin of the view is showing the name field. When comment     // belongs to an authenticated user the name field has no value.     $comment_author = $this->xpath('//div[contains(@class, :class)]/span[normalize-space(text())=""]', [
      ':class' => 'views-field-subject',
    ]);
    $this->assertNotEmpty($comment_author);
    // When comment belongs to an anonymous user the name field has a value and     // it is rendered correctly.     $this->assertLink('barry (not verified)');

    
// Set the formatter to link to the entity.     $this->display->setComponent($this->fieldName, [
      'type' => 'string',
      'settings' => [
        'link_to_entity' => TRUE,
      ],
    ]);
    $this->display->save();

    $this->renderEntityFields($entity$this->display);
    $this->assertLink($value, 0);
    $this->assertLinkByHref($entity->toUrl()->toString());

    // $entity->toUrl('revision') falls back to the canonical URL if this is no     // revision.     $this->assertLinkByHref($entity->toUrl('revision')->toString());

    // Make the entity a new revision.     $old_revision_id = $entity->getRevisionId();
    $entity->setNewRevision(TRUE);
    $value2 = $this->randomMachineName();
    $entity->{$this->fieldName}->value = $value2;
    
public function testGenerateHrefs($route_name, array $parameters$absolute$expected_url) {
    $this->urlGenerator->expects($this->once())
      ->method('generateFromRoute')
      ->with($route_name$parameters['absolute' => $absolute] + $this->defaultOptions)
      ->willReturn((new GeneratedUrl())->setGeneratedUrl($expected_url));
    $this->moduleHandler->expects($this->once())
      ->method('alter');

    $url = new Url($route_name$parameters['absolute' => $absolute]);
    $url->setUrlGenerator($this->urlGenerator);
    $result = $this->linkGenerator->generate('Test', $url);
    $this->assertLink([
      'attributes' => ['href' => $expected_url],
    ]$result);
  }

  /** * Tests the generate() method with a route. * * @covers ::generate */
  public function testGenerate() {
    $this->urlGenerator->expects($this->once())
      
Home | Imprint | This part of the site doesn't use cookies.