X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Ftests%2FDrupal%2FTests%2FCore%2FTest%2FBrowserTestBaseTest.php;fp=web%2Fcore%2Ftests%2FDrupal%2FTests%2FCore%2FTest%2FBrowserTestBaseTest.php;h=a8eb65f667e24bd9dde7f7bb3265a07ad412a1fe;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=0000000000000000000000000000000000000000;hpb=74df008bdbb3a11eeea356744f39b802369bda3c;p=yaffs-website diff --git a/web/core/tests/Drupal/Tests/Core/Test/BrowserTestBaseTest.php b/web/core/tests/Drupal/Tests/Core/Test/BrowserTestBaseTest.php new file mode 100644 index 000000000..a8eb65f66 --- /dev/null +++ b/web/core/tests/Drupal/Tests/Core/Test/BrowserTestBaseTest.php @@ -0,0 +1,82 @@ +getMockBuilder(Session::class) + ->disableOriginalConstructor() + ->setMethods(['getDriver']) + ->getMock(); + $session->expects($this->once()) + ->method('getDriver') + ->willReturn($driver); + + $btb = $this->getMockBuilder(BrowserTestBase::class) + ->disableOriginalConstructor() + ->setMethods(['getSession']) + ->getMockForAbstractClass(); + $btb->expects($this->once()) + ->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(Client::class) + ->setMethods(['getClient']) + ->getMockForAbstractClass(); + $browserkit_client->expects($this->once()) + ->method('getClient') + ->willReturn($expected); + + // Because the driver is a GoutteDriver, we'll get back a client. + $driver = $this->getMockBuilder(GoutteDriver::class) + ->setMethods(['getClient']) + ->getMock(); + $driver->expects($this->once()) + ->method('getClient') + ->willReturn($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 GoutteDriver. This should cause a + // RuntimeException. + $btb = $this->mockBrowserTestBaseWithDriver(new \stdClass()); + + $ref_gethttpclient = new \ReflectionMethod($btb, 'getHttpClient'); + $ref_gethttpclient->setAccessible(TRUE); + + $this->setExpectedException(\RuntimeException::class, 'The Mink client type stdClass does not support getHttpClient().'); + $ref_gethttpclient->invoke($btb); + } + +}