function FieldUrlTest::testFieldUrl

Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/Handler/FieldUrlTest.php \Drupal\Tests\views\Kernel\Handler\FieldUrlTest::testFieldUrl()
  2. 8.9.x core/modules/views/tests/src/Kernel/Handler/FieldUrlTest.php \Drupal\Tests\views\Kernel\Handler\FieldUrlTest::testFieldUrl()
  3. 10 core/modules/views/tests/src/Kernel/Handler/FieldUrlTest.php \Drupal\Tests\views\Kernel\Handler\FieldUrlTest::testFieldUrl()

File

core/modules/views/tests/src/Kernel/Handler/FieldUrlTest.php, line 37

Class

FieldUrlTest
Tests the core Drupal\views\Plugin\views\field\Url handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testFieldUrl() : void {
    $view = Views::getView('test_view');
    $view->setDisplay();
    $view->displayHandlers
        ->get('default')
        ->overrideOption('fields', [
        'name' => [
            'id' => 'name',
            'table' => 'views_test_data',
            'field' => 'name',
            'relationship' => 'none',
            'display_as_link' => FALSE,
        ],
    ]);
    $this->executeView($view);
    $this->assertEquals('John', $view->field['name']
        ->advancedRender($view->result[0]));
    // Make the URL a link.
    $view->destroy();
    $view->setDisplay();
    $view->displayHandlers
        ->get('default')
        ->overrideOption('fields', [
        'name' => [
            'id' => 'name',
            'table' => 'views_test_data',
            'field' => 'name',
            'relationship' => 'none',
        ],
    ]);
    $this->executeView($view);
    $this->assertEquals(Link::fromTextAndUrl('John', Url::fromUri('base:John'))->toString(), $view->field['name']
        ->advancedRender($view->result[0]));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.