Passed
Pull Request — master (#888)
by Tobias
01:50
created

testProperlyGeneratesSecureUrlFromProxy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 14
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright 2017 Facebook, Inc.
4
 *
5
 * You are hereby granted a non-exclusive, worldwide, royalty-free license to
6
 * use, copy, modify, and distribute this software in source code or binary
7
 * form for use in connection with the web services and APIs provided by
8
 * Facebook.
9
 *
10
 * As with any software that integrates with the Facebook platform, your use
11
 * of this software is subject to the Facebook Developer Principles and
12
 * Policies [http://developers.facebook.com/policy/]. This copyright notice
13
 * shall be included in all copies or substantial portions of the software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
 * DEALINGS IN THE SOFTWARE.
22
 *
23
 */
24
namespace Facebook\Tests\Url;
25
26
use Facebook\Url\UrlDetectionHandler;
27
use PHPUnit\Framework\TestCase;
28
29
class UrlDetectionHandlerTest extends TestCase
30
{
31
    public function testProperlyGeneratesUrlFromCommonScenario()
32
    {
33
        $_SERVER = [
34
            'HTTP_HOST' => 'foo.bar',
35
            'SERVER_PORT' => '80',
36
            'REQUEST_URI' => '/baz?foo=123',
37
        ];
38
39
        $urlHandler = new UrlDetectionHandler();
40
        $currentUri = $urlHandler->getCurrentUrl();
41
42
        $this->assertEquals('http://foo.bar/baz?foo=123', $currentUri);
43
    }
44
45
    public function testProperlyGeneratesSecureUrlFromCommonScenario()
46
    {
47
        $_SERVER = [
48
            'HTTP_HOST' => 'foo.bar',
49
            'SERVER_PORT' => '443',
50
            'REQUEST_URI' => '/baz?foo=123',
51
        ];
52
53
        $urlHandler = new UrlDetectionHandler();
54
        $currentUri = $urlHandler->getCurrentUrl();
55
56
        $this->assertEquals('https://foo.bar/baz?foo=123', $currentUri);
57
    }
58
59 View Code Duplication
    public function testProperlyGeneratesUrlFromProxy()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
60
    {
61
        $_SERVER = [
62
            'HTTP_X_FORWARDED_PORT' => '80',
63
            'HTTP_X_FORWARDED_PROTO' => 'http',
64
            'HTTP_HOST' => 'foo.bar',
65
            'SERVER_PORT' => '80',
66
            'REQUEST_URI' => '/baz?foo=123',
67
        ];
68
69
        $urlHandler = new UrlDetectionHandler();
70
        $currentUri = $urlHandler->getCurrentUrl();
71
72
        $this->assertEquals('http://foo.bar/baz?foo=123', $currentUri);
73
    }
74
75 View Code Duplication
    public function testProperlyGeneratesSecureUrlFromProxy()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
76
    {
77
        $_SERVER = [
78
            'HTTP_X_FORWARDED_PORT' => '443',
79
            'HTTP_X_FORWARDED_PROTO' => 'https',
80
            'HTTP_HOST' => 'foo.bar',
81
            'SERVER_PORT' => '80',
82
            'REQUEST_URI' => '/baz?foo=123',
83
        ];
84
85
        $urlHandler = new UrlDetectionHandler();
86
        $currentUri = $urlHandler->getCurrentUrl();
87
88
        $this->assertEquals('https://foo.bar/baz?foo=123', $currentUri);
89
    }
90
91
    public function testProperlyGeneratesUrlWithCustomPort()
92
    {
93
        $_SERVER = [
94
            'HTTP_HOST' => 'foo.bar',
95
            'SERVER_PORT' => '1337',
96
            'REQUEST_URI' => '/foo.php',
97
        ];
98
99
        $urlHandler = new UrlDetectionHandler();
100
        $currentUri = $urlHandler->getCurrentUrl();
101
102
        $this->assertEquals('http://foo.bar:1337/foo.php', $currentUri);
103
    }
104
105 View Code Duplication
    public function testProperlyGeneratesSecureUrlWithCustomPort()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
106
    {
107
        $_SERVER = [
108
            'HTTP_HOST' => 'foo.bar',
109
            'SERVER_PORT' => '1337',
110
            'REQUEST_URI' => '/foo.php',
111
            'HTTPS' => 'On',
112
        ];
113
114
        $urlHandler = new UrlDetectionHandler();
115
        $currentUri = $urlHandler->getCurrentUrl();
116
117
        $this->assertEquals('https://foo.bar:1337/foo.php', $currentUri);
118
    }
119
120 View Code Duplication
    public function testProperlyGeneratesUrlWithCustomPortFromProxy()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
121
    {
122
        $_SERVER = [
123
            'HTTP_X_FORWARDED_PORT' => '8888',
124
            'HTTP_X_FORWARDED_PROTO' => 'http',
125
            'HTTP_HOST' => 'foo.bar',
126
            'SERVER_PORT' => '80',
127
            'REQUEST_URI' => '/foo.php',
128
        ];
129
130
        $urlHandler = new UrlDetectionHandler();
131
        $currentUri = $urlHandler->getCurrentUrl();
132
133
        $this->assertEquals('http://foo.bar:8888/foo.php', $currentUri);
134
    }
135
}
136