Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / fabpot / goutte / Goutte / Tests / ClientTest.php
index 02866159c58f4a10d8976c897f37b09696a186ca..c57e0e24be52ee8aff0dedcb6d14e5867f1a8017 100644 (file)
@@ -33,7 +33,7 @@ class ClientTest extends TestCase
     /** @var MockHandler */
     protected $mock;
 
-    protected function getGuzzle(array $responses = [])
+    protected function getGuzzle(array $responses = [], array $extraConfig = [])
     {
         if (empty($responses)) {
             $responses = [new GuzzleResponse(200, [], '<html><body><p>Hi</p></body></html>')];
@@ -42,7 +42,7 @@ class ClientTest extends TestCase
         $handlerStack = HandlerStack::create($this->mock);
         $this->history = [];
         $handlerStack->push(Middleware::history($this->history));
-        $guzzle = new GuzzleClient(array('redirect.disable' => true, 'base_uri' => '', 'handler' => $handlerStack));
+        $guzzle = new GuzzleClient(array_merge(array('redirect.disable' => true, 'base_uri' => '', 'handler' => $handlerStack), $extraConfig));
 
         return $guzzle;
     }
@@ -407,4 +407,41 @@ class ClientTest extends TestCase
         $this->assertEquals([], $headersReflectionProperty->getValue($client));
         $this->assertNull($authReflectionProperty->getValue($client));
     }
+
+    public function testSetBaseUri()
+    {
+        $guzzle = $this->getGuzzle([], ['base_uri' => 'http://example.com/']);
+        $client = new Client();
+        $client->setClient($guzzle);
+
+        $this->assertNull($client->getServerParameter('HTTPS', null));
+        $this->assertSame('example.com', $client->getServerParameter('HTTP_HOST'));
+
+        $client->request('GET', '/foo');
+        $this->assertSame('http://example.com/foo', (string) end($this->history)['request']->getUri());
+    }
+
+    public function testSetHttpsBaseUri()
+    {
+        $guzzle = $this->getGuzzle([], ['base_uri' => 'https://example.com:1234']);
+        $client = new Client();
+        $client->setClient($guzzle);
+
+        $this->assertSame('on', $client->getServerParameter('HTTPS'));
+        $this->assertSame('example.com:1234', $client->getServerParameter('HTTP_HOST'));
+
+        $client->request('GET', '/foo');
+        $this->assertSame('https://example.com:1234/foo', (string) end($this->history)['request']->getUri());
+    }
+
+    /**
+     * @expectedException \InvalidArgumentException
+     * @expectedExceptionMessage Setting a path in the Guzzle "base_uri" config option is not supported by Goutte yet.
+     */
+    public function testSetBaseUriWithPath()
+    {
+        $guzzle = $this->getGuzzle([], ['base_uri' => 'http://example.com/foo/']);
+        $client = new Client();
+        $client->setClient($guzzle);
+    }
 }