You are here

class FieldUrlTest in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Kernel/Handler/FieldUrlTest.php \Drupal\Tests\views\Kernel\Handler\FieldUrlTest
  2. 9 core/modules/views/tests/src/Kernel/Handler/FieldUrlTest.php \Drupal\Tests\views\Kernel\Handler\FieldUrlTest

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

@group views

Hierarchy

  • class \Drupal\Tests\views\Kernel\Handler\FieldUrlTest extends \Drupal\Tests\views\Kernel\ViewsKernelTestBase

Expanded class hierarchy of FieldUrlTest

File

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

Namespace

Drupal\Tests\views\Kernel\Handler
View source
class FieldUrlTest extends ViewsKernelTestBase {
  protected static $modules = [
    'system',
  ];

  /**
   * Views used by this test.
   *
   * @var array
   */
  public static $testViews = [
    'test_view',
  ];
  public function viewsData() {
    $data = parent::viewsData();
    $data['views_test_data']['name']['field']['id'] = 'url';
    return $data;
  }
  public function testFieldUrl() {
    $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]));
  }

}

Members