xref: /dokuwiki/_test/tests/inc/httpclient_http_proxy.test.php (revision 605810ee2fba6c1a323e320dde2c78747b3e5f3a)
11ea7a6baSAndreas Gohr<?php
21ea7a6baSAndreas Gohr
395e6ded1SAndreas Gohrrequire_once(__DIR__ . '/httpclient_mock.php');
495e6ded1SAndreas Gohr
5*605810eeSAndreas Gohrclass httpclient_http_proxy_test extends DokuWikiTest
6*605810eeSAndreas Gohr{
7*605810eeSAndreas Gohr    protected $url = 'http://httpbingo.org/user-agent';
8*605810eeSAndreas Gohr    protected $host;
9*605810eeSAndreas Gohr    protected $port;
10*605810eeSAndreas Gohr
11*605810eeSAndreas Gohr
12*605810eeSAndreas Gohr    public function setUp(): void
13*605810eeSAndreas Gohr    {
14*605810eeSAndreas Gohr        parent::setUp();
15*605810eeSAndreas Gohr        $configuration = DOKU_UNITTEST . "proxy.conf.php";
16*605810eeSAndreas Gohr        if (file_exists($configuration)) {
17*605810eeSAndreas Gohr            /** @var $conf array */
18*605810eeSAndreas Gohr            include $configuration;
19*605810eeSAndreas Gohr            $this->host = $conf['host'];
20*605810eeSAndreas Gohr            $this->port = $conf['port'];
21*605810eeSAndreas Gohr        }
22*605810eeSAndreas Gohr
23*605810eeSAndreas Gohr        if (!$this->host || !$this->port) {
24*605810eeSAndreas Gohr            $this->markTestSkipped("Skipped proxy tests. Missing configuration");
25*605810eeSAndreas Gohr        }
26*605810eeSAndreas Gohr    }
27*605810eeSAndreas Gohr
281ea7a6baSAndreas Gohr
291ea7a6baSAndreas Gohr    /**
301ea7a6baSAndreas Gohr     * @group internet
311ea7a6baSAndreas Gohr     */
32*605810eeSAndreas Gohr    function testSimpleGet()
33*605810eeSAndreas Gohr    {
3495e6ded1SAndreas Gohr        $http = new HTTPMockClient();
35*605810eeSAndreas Gohr        $http->proxy_host = $this->host;
36*605810eeSAndreas Gohr        $http->proxy_port = $this->port;
371ea7a6baSAndreas Gohr
381ea7a6baSAndreas Gohr        $data = $http->get($this->url);
396aad717eSAndreas Gohr        $this->assertFalse($data === false, $http->errorInfo($this->url));
40*605810eeSAndreas Gohr        $this->assertStringContainsString('DokuWiki', $data, 'response content');
411ea7a6baSAndreas Gohr    }
421ea7a6baSAndreas Gohr}
43