/var/www/hkosl.com/b2b2c/webadmin/libraies/klein/klein/tests/Klein/Tests/ResponseCookieTest.php


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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php
/**
 * Klein (klein.php) - A fast & flexible router for PHP
 *
 * @author      Chris O'Hara <cohara87@gmail.com>
 * @author      Trevor Suarez (Rican7) (contributor and v2 refactorer)
 * @copyright   (c) Chris O'Hara
 * @link        https://github.com/klein/klein.php
 * @license     MIT
 */

namespace Klein\Tests;

use 
Klein\ResponseCookie;

/**
 * ResponseCookieTest
 */
class ResponseCookieTest extends AbstractKleinTest
{

    
/*
     * Data Providers and Methods
     */

    /**
     * Sample data provider
     *
     * @return array
     */
    
public function sampleDataProvider()
    {
        
// Populate our sample data
        
$default_sample_data = array(
            
'name' => '',
            
'value' => '',
            
'expire' => 0,
            
'path' => '',
            
'domain' => '',
            
'secure' => false,
            
'http_only' => false,
        );

        
$sample_data = array(
            
'name' => 'Trevor',
            
'value' => 'is a programmer',
            
'expire' => 3600,
            
'path' => '/',
            
'domain' => 'example.com',
            
'secure' => false,
            
'http_only' => false,
        );

        
$sample_data_other = array(
            
'name' => 'Chris',
            
'value' => 'is a boss',
            
'expire' => 60,
            
'path' => '/app/',
            
'domain' => 'github.com',
            
'secure' => true,
            
'http_only' => true,
        );

        return array(
            array(
$default_sample_data$sample_data$sample_data_other),
        );
    }


    
/*
     * Tests
     */

    /**
     * @dataProvider sampleDataProvider
     */
    
public function testNameGetSet($defaults$sample_data$sample_data_other)
    {
        
$response_cookie = new ResponseCookie($sample_data['name']);

        
$this->assertSame($sample_data['name'], $response_cookie->getName());
        
$this->assertInternalType('string'$response_cookie->getName());

        
$response_cookie->setName($sample_data_other['name']);

        
$this->assertSame($sample_data_other['name'], $response_cookie->getName());
        
$this->assertInternalType('string'$response_cookie->getName());
    }

    
/**
     * @dataProvider sampleDataProvider
     */
    
public function testValueGetSet($defaults$sample_data$sample_data_other)
    {
        
$response_cookie = new ResponseCookie($defaults['name'], $sample_data['value']);

        
$this->assertSame($sample_data['value'], $response_cookie->getValue());
        
$this->assertInternalType('string'$response_cookie->getValue());

        
$response_cookie->setValue($sample_data_other['value']);

        
$this->assertSame($sample_data_other['value'], $response_cookie->getValue());
        
$this->assertInternalType('string'$response_cookie->getValue());
    }

    
/**
     * @dataProvider sampleDataProvider
     */
    
public function testExpireGetSet($defaults$sample_data$sample_data_other)
    {
        
$response_cookie = new ResponseCookie(
            
$defaults['name'],
            
null,
            
$sample_data['expire']
        );

        
$this->assertSame($sample_data['expire'], $response_cookie->getExpire());
        
$this->assertInternalType('int'$response_cookie->getExpire());

        
$response_cookie->setExpire($sample_data_other['expire']);

        
$this->assertSame($sample_data_other['expire'], $response_cookie->getExpire());
        
$this->assertInternalType('int'$response_cookie->getExpire());
    }

    
/**
     * @dataProvider sampleDataProvider
     */
    
public function testPathGetSet($defaults$sample_data$sample_data_other)
    {
        
$response_cookie = new ResponseCookie(
            
$defaults['name'],
            
null,
            
null,
            
$sample_data['path']
        );

        
$this->assertSame($sample_data['path'], $response_cookie->getPath());
        
$this->assertInternalType('string'$response_cookie->getPath());

        
$response_cookie->setPath($sample_data_other['path']);

        
$this->assertSame($sample_data_other['path'], $response_cookie->getPath());
        
$this->assertInternalType('string'$response_cookie->getPath());
    }

    
/**
     * @dataProvider sampleDataProvider
     */
    
public function testDomainGetSet($defaults$sample_data$sample_data_other)
    {
        
$response_cookie = new ResponseCookie(
            
$defaults['name'],
            
null,
            
null,
            
null,
            
$sample_data['domain']
        );

        
$this->assertSame($sample_data['domain'], $response_cookie->getDomain());
        
$this->assertInternalType('string'$response_cookie->getDomain());

        
$response_cookie->setDomain($sample_data_other['domain']);

        
$this->assertSame($sample_data_other['domain'], $response_cookie->getDomain());
        
$this->assertInternalType('string'$response_cookie->getDomain());
    }

    
/**
     * @dataProvider sampleDataProvider
     */
    
public function testSecureGetSet($defaults$sample_data$sample_data_other)
    {
        
$response_cookie = new ResponseCookie(
            
$defaults['name'],
            
null,
            
null,
            
null,
            
null,
            
$sample_data['secure']
        );

        
$this->assertSame($sample_data['secure'], $response_cookie->getSecure());
        
$this->assertInternalType('boolean'$response_cookie->getSecure());

        
$response_cookie->setSecure($sample_data_other['secure']);

        
$this->assertSame($sample_data_other['secure'], $response_cookie->getSecure());
        
$this->assertInternalType('boolean'$response_cookie->getSecure());
    }

    
/**
     * @dataProvider sampleDataProvider
     */
    
public function testHttpOnlyGetSet($defaults$sample_data$sample_data_other)
    {
        
$response_cookie = new ResponseCookie(
            
$defaults['name'],
            
null,
            
null,
            
null,
            
null,
            
null,
            
$sample_data['http_only']
        );

        
$this->assertSame($sample_data['http_only'], $response_cookie->getHttpOnly());
        
$this->assertInternalType('boolean'$response_cookie->getHttpOnly());

        
$response_cookie->setHttpOnly($sample_data_other['http_only']);

        
$this->assertSame($sample_data_other['http_only'], $response_cookie->getHttpOnly());
        
$this->assertInternalType('boolean'$response_cookie->getHttpOnly());
    }
}