You are here

class BrowserTestBaseTest in Drupal 10

Same name in this branch
  1. 10 core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php \Drupal\FunctionalTests\BrowserTestBaseTest
  2. 10 core/tests/Drupal/Tests/Core/Test/BrowserTestBaseTest.php \Drupal\Tests\Core\Test\BrowserTestBaseTest
  3. 10 core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php \Drupal\KernelTests\Core\Test\BrowserTestBaseTest
Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Test/BrowserTestBaseTest.php \Drupal\Tests\Core\Test\BrowserTestBaseTest
  2. 9 core/tests/Drupal/Tests/Core/Test/BrowserTestBaseTest.php \Drupal\Tests\Core\Test\BrowserTestBaseTest

@coversDefaultClass \Drupal\Tests\BrowserTestBase @group Test

Hierarchy

Expanded class hierarchy of BrowserTestBaseTest

File

core/tests/Drupal/Tests/Core/Test/BrowserTestBaseTest.php, line 15

Namespace

Drupal\Tests\Core\Test
View source
class BrowserTestBaseTest extends UnitTestCase {
  protected function mockBrowserTestBaseWithDriver($driver) {
    $session = $this
      ->getMockBuilder(Session::class)
      ->disableOriginalConstructor()
      ->onlyMethods([
      'getDriver',
    ])
      ->getMock();
    $session
      ->expects($this
      ->any())
      ->method('getDriver')
      ->willReturn($driver);
    $btb = $this
      ->getMockBuilder(BrowserTestBase::class)
      ->disableOriginalConstructor()
      ->onlyMethods([
      'getSession',
    ])
      ->getMockForAbstractClass();
    $btb
      ->expects($this
      ->any())
      ->method('getSession')
      ->willReturn($session);
    return $btb;
  }

  /**
   * @covers ::getHttpClient
   */
  public function testGetHttpClient() {

    // Our stand-in for the Guzzle client object.
    $expected = new \stdClass();
    $browserkit_client = $this
      ->getMockBuilder(DrupalTestBrowser::class)
      ->onlyMethods([
      'getClient',
    ])
      ->getMockForAbstractClass();
    $browserkit_client
      ->expects($this
      ->once())
      ->method('getClient')
      ->willReturn($expected);

    // Because the driver is a BrowserKitDriver, we'll get back a client.
    $driver = new BrowserKitDriver($browserkit_client);
    $btb = $this
      ->mockBrowserTestBaseWithDriver($driver);
    $ref_gethttpclient = new \ReflectionMethod($btb, 'getHttpClient');
    $ref_gethttpclient
      ->setAccessible(TRUE);
    $this
      ->assertSame(get_class($expected), get_class($ref_gethttpclient
      ->invoke($btb)));
  }

  /**
   * @covers ::getHttpClient
   */
  public function testGetHttpClientException() {

    // A driver type that isn't BrowserKitDriver. This should cause a
    // RuntimeException.
    $btb = $this
      ->mockBrowserTestBaseWithDriver(new \stdClass());
    $ref_gethttpclient = new \ReflectionMethod($btb, 'getHttpClient');
    $ref_gethttpclient
      ->setAccessible(TRUE);
    $this
      ->expectException(\RuntimeException::class);
    $this
      ->expectExceptionMessage('The Mink client type stdClass does not support getHttpClient().');
    $ref_gethttpclient
      ->invoke($btb);
  }

  /**
   * Tests that tearDown doesn't call cleanupEnvironment if setUp is not called.
   *
   * @covers ::tearDown
   */
  public function testTearDownWithoutSetUp() {
    $method = 'cleanupEnvironment';
    $this
      ->assertTrue(method_exists(BrowserTestBase::class, $method));
    $btb = $this
      ->getMockBuilder(BrowserTestBase::class)
      ->disableOriginalConstructor()
      ->onlyMethods([
      $method,
    ])
      ->getMockForAbstractClass();
    $btb
      ->expects($this
      ->never())
      ->method($method);
    $ref_tearDown = new \ReflectionMethod($btb, 'tearDown');
    $ref_tearDown
      ->setAccessible(TRUE);
    $ref_tearDown
      ->invoke($btb);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BrowserTestBaseTest::mockBrowserTestBaseWithDriver protected function
BrowserTestBaseTest::testGetHttpClient public function @covers ::getHttpClient
BrowserTestBaseTest::testGetHttpClientException public function @covers ::getHttpClient
BrowserTestBaseTest::testTearDownWithoutSetUp public function Tests that tearDown doesn't call cleanupEnvironment if setUp is not called.
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 206
UnitTestCase::setUpBeforeClass public static function