Completed
Pull Request — master (#888)
by Yassine
02:05
created

testProperlyGeneratesUrlFromCommonScenario()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 12
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
namespace Facebook\Tests\Url;
24
25
use Facebook\Url\UrlDetectionHandler;
26
use PHPUnit\Framework\TestCase;
27
28
class UrlDetectionHandlerTest extends TestCase
29
{
30
    public function testProperlyGeneratesUrlFromCommonScenario()
31
    {
32
        $_SERVER = [
33
            'HTTP_HOST' => 'foo.bar',
34
            'SERVER_PORT' => '80',
35
            'REQUEST_URI' => '/baz?foo=123',
36
        ];
37
38
        $urlHandler = new UrlDetectionHandler();
39
        $currentUri = $urlHandler->getCurrentUrl();
40
41
        $this->assertEquals('http://foo.bar/baz?foo=123', $currentUri);
42
    }
43
44
    public function testProperlyGeneratesSecureUrlFromCommonScenario()
45
    {
46
        $_SERVER = [
47
            'HTTP_HOST' => 'foo.bar',
48
            'SERVER_PORT' => '443',
49
            'REQUEST_URI' => '/baz?foo=123',
50
        ];
51
52
        $urlHandler = new UrlDetectionHandler();
53
        $currentUri = $urlHandler->getCurrentUrl();
54
55
        $this->assertEquals('https://foo.bar/baz?foo=123', $currentUri);
56
    }
57
58 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...
59
    {
60
        $_SERVER = [
61
            'HTTP_X_FORWARDED_PORT' => '80',
62
            'HTTP_X_FORWARDED_PROTO' => 'http',
63
            'HTTP_HOST' => 'foo.bar',
64
            'SERVER_PORT' => '80',
65
            'REQUEST_URI' => '/baz?foo=123',
66
        ];
67
68
        $urlHandler = new UrlDetectionHandler();
69
        $currentUri = $urlHandler->getCurrentUrl();
70
71
        $this->assertEquals('http://foo.bar/baz?foo=123', $currentUri);
72
    }
73
74 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...
75
    {
76
        $_SERVER = [
77
            'HTTP_X_FORWARDED_PORT' => '443',
78
            'HTTP_X_FORWARDED_PROTO' => 'https',
79
            'HTTP_HOST' => 'foo.bar',
80
            'SERVER_PORT' => '80',
81
            'REQUEST_URI' => '/baz?foo=123',
82
        ];
83
84
        $urlHandler = new UrlDetectionHandler();
85
        $currentUri = $urlHandler->getCurrentUrl();
86
87
        $this->assertEquals('https://foo.bar/baz?foo=123', $currentUri);
88
    }
89
90
    public function testProperlyGeneratesUrlWithCustomPort()
91
    {
92
        $_SERVER = [
93
            'HTTP_HOST' => 'foo.bar',
94
            'SERVER_PORT' => '1337',
95
            'REQUEST_URI' => '/foo.php',
96
        ];
97
98
        $urlHandler = new UrlDetectionHandler();
99
        $currentUri = $urlHandler->getCurrentUrl();
100
101
        $this->assertEquals('http://foo.bar:1337/foo.php', $currentUri);
102
    }
103
104 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...
105
    {
106
        $_SERVER = [
107
            'HTTP_HOST' => 'foo.bar',
108
            'SERVER_PORT' => '1337',
109
            'REQUEST_URI' => '/foo.php',
110
            'HTTPS' => 'On',
111
        ];
112
113
        $urlHandler = new UrlDetectionHandler();
114
        $currentUri = $urlHandler->getCurrentUrl();
115
116
        $this->assertEquals('https://foo.bar:1337/foo.php', $currentUri);
117
    }
118
119 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...
120
    {
121
        $_SERVER = [
122
            'HTTP_X_FORWARDED_PORT' => '8888',
123
            'HTTP_X_FORWARDED_PROTO' => 'http',
124
            'HTTP_HOST' => 'foo.bar',
125
            'SERVER_PORT' => '80',
126
            'REQUEST_URI' => '/foo.php',
127
        ];
128
129
        $urlHandler = new UrlDetectionHandler();
130
        $currentUri = $urlHandler->getCurrentUrl();
131
132
        $this->assertEquals('http://foo.bar:8888/foo.php', $currentUri);
133
    }
134
}
135