class KernelTestHttpRequestTest

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/KernelTestHttpRequestTest.php \Drupal\KernelTests\KernelTestHttpRequestTest

Tests making HTTP requests in a kernel test.

Attributes

#[CoversTrait(HttpKernelUiHelperTrait::class)] #[Group('PHPUnit')] #[Group('Test')] #[Group('KernelTests')] #[RunTestsInSeparateProcesses]

Hierarchy

Expanded class hierarchy of KernelTestHttpRequestTest

File

core/tests/Drupal/KernelTests/KernelTestHttpRequestTest.php, line 16

Namespace

Drupal\KernelTests
View source
class KernelTestHttpRequestTest extends KernelTestBase {
  
  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'system',
    'system_test',
    'test_page_test',
  ];
  
  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
  }
  
  /**
   * Tests making a request.
   */
  public function testRequest() : void {
    $this->drupalGet('/system-test/main-content-handling');
    $this->assertEquals(Response::HTTP_OK, $this->getSession()
      ->getStatusCode());
    $this->assertSession()
      ->pageTextContains('Content to test main content fallback');
  }
  
  /**
   * Tests clickLink() functionality.
   */
  public function testClickLink() : void {
    $this->drupalGet('test-page');
    $this->clickLink('Visually identical test links');
    $this->assertStringContainsString('user/login', $this->getSession()
      ->getCurrentUrl());
    $this->drupalGet('test-page');
    $this->clickLink('Visually identical test links', 0);
    $this->assertStringContainsString('user/login', $this->getSession()
      ->getCurrentUrl());
    $this->drupalGet('test-page');
    $this->clickLink('Visually identical test links', 1);
    $this->assertStringContainsString('user/register', $this->getSession()
      ->getCurrentUrl());
  }

}

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