File: GetAllHeadersTest.php

package info (click to toggle)
php-getallheaders 3.0.3-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 136 kB
  • sloc: php: 153; xml: 16; makefile: 4
file content (127 lines) | stat: -rw-r--r-- 3,656 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php

namespace getallheaders\Tests;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class GetAllHeadersTest extends TestCase
{
    #[DataProvider('dataWorks')]
    public function testWorks($test_type, $expected, $server)
    {
        foreach ($server as $key => $val) {
            $_SERVER[$key] = $val;
        }
        $result = getallheaders();
        $this->assertEquals($expected, $result, "Error testing $test_type works.");
        // Clean up.
        foreach ($server as $key => $val) {
            unset($_SERVER[$key]);
        }
    }

    public static function dataWorks()
    {
        return [
            [
                'normal case',
                [
                    'Key-One'                 => 'foo',
                    'Key-Two'                 => 'bar',
                    'Another-Key-For-Testing' => 'baz',
                ],
                [
                    'HTTP_KEY_ONE'                 => 'foo',
                    'HTTP_KEY_TWO'                 => 'bar',
                    'HTTP_ANOTHER_KEY_FOR_TESTING' => 'baz',
                ],
            ],
            [
                'Content-Type',
                [
                    'Content-Type' => 'two',
                ],
                [
                    'HTTP_CONTENT_TYPE' => 'one',
                    'CONTENT_TYPE'      => 'two',
                ],
            ],
            [
                'Content-Length',
                [
                    'Content-Length' => '222',
                ],
                [
                    'CONTENT_LENGTH'      => '222',
                    'HTTP_CONTENT_LENGTH' => '111',
                ],
            ],
            [
                'Content-Length (HTTP_CONTENT_LENGTH only)',
                [
                    'Content-Length' => '111',
                ],
                [
                    'HTTP_CONTENT_LENGTH' => '111',
                ],
            ],
            [
                'Content-MD5',
                [
                    'Content-Md5' => 'aef123',
                ],
                [
                    'CONTENT_MD5'      => 'aef123',
                    'HTTP_CONTENT_MD5' => 'fea321',
                ],
            ],
            [
                'Content-MD5 (HTTP_CONTENT_MD5 only)',
                [
                    'Content-Md5' => 'f123',
                ],
                [
                    'HTTP_CONTENT_MD5' => 'f123',
                ],
            ],
            [
                'Authorization (normal)',
                [
                    'Authorization' => 'testing',
                ],
                [
                    'HTTP_AUTHORIZATION' => 'testing',
                ],
            ],
            [
                'Authorization (redirect)',
                [
                    'Authorization' => 'testing redirect',
                ],
                [
                    'REDIRECT_HTTP_AUTHORIZATION' => 'testing redirect',
                ],
            ],
            [
                'Authorization (PHP_AUTH_USER + PHP_AUTH_PW)',
                [
                    'Authorization' => 'Basic ' . base64_encode('foo:bar'),
                ],
                [
                    'PHP_AUTH_USER' => 'foo',
                    'PHP_AUTH_PW'   => 'bar',
                ],
            ],
            [
                'Authorization (PHP_AUTH_DIGEST)',
                [
                    'Authorization' => 'example-digest',
                ],
                [
                    'PHP_AUTH_DIGEST' => 'example-digest',
                ],
            ],
        ];
    }
}