@@ -72,9 +72,13 @@ public function testGetPath()
72
72
73
73
public function testGetExpiresTime ()
74
74
{
75
- $ cookie = new Cookie ('foo ' , 'bar ' , 3600 );
75
+ $ cookie = new Cookie ('foo ' , 'bar ' );
76
+
77
+ $ this ->assertEquals (0 , $ cookie ->getExpiresTime (), '->getExpiresTime() returns the default expire date ' );
78
+
79
+ $ cookie = new Cookie ('foo ' , 'bar ' , $ expire = time () + 3600 );
76
80
77
- $ this ->assertEquals (3600 , $ cookie ->getExpiresTime (), '->getExpiresTime() returns the expire date ' );
81
+ $ this ->assertEquals ($ expire , $ cookie ->getExpiresTime (), '->getExpiresTime() returns the expire date ' );
78
82
}
79
83
80
84
public function testConstructorWithDateTime ()
@@ -107,21 +111,21 @@ public function testGetExpiresTimeWithStringValue()
107
111
108
112
public function testGetDomain ()
109
113
{
110
- $ cookie = new Cookie ('foo ' , 'bar ' , 3600 , '/ ' , '.myfoodomain.com ' );
114
+ $ cookie = new Cookie ('foo ' , 'bar ' , 0 , '/ ' , '.myfoodomain.com ' );
111
115
112
116
$ this ->assertEquals ('.myfoodomain.com ' , $ cookie ->getDomain (), '->getDomain() returns the domain name on which the cookie is valid ' );
113
117
}
114
118
115
119
public function testIsSecure ()
116
120
{
117
- $ cookie = new Cookie ('foo ' , 'bar ' , 3600 , '/ ' , '.myfoodomain.com ' , true );
121
+ $ cookie = new Cookie ('foo ' , 'bar ' , 0 , '/ ' , '.myfoodomain.com ' , true );
118
122
119
123
$ this ->assertTrue ($ cookie ->isSecure (), '->isSecure() returns whether the cookie is transmitted over HTTPS ' );
120
124
}
121
125
122
126
public function testIsHttpOnly ()
123
127
{
124
- $ cookie = new Cookie ('foo ' , 'bar ' , 3600 , '/ ' , '.myfoodomain.com ' , false , true );
128
+ $ cookie = new Cookie ('foo ' , 'bar ' , 0 , '/ ' , '.myfoodomain.com ' , false , true );
125
129
126
130
$ this ->assertTrue ($ cookie ->isHttpOnly (), '->isHttpOnly() returns whether the cookie is only transmitted over HTTP ' );
127
131
}
@@ -142,14 +146,14 @@ public function testCookieIsCleared()
142
146
143
147
public function testToString ()
144
148
{
145
- $ cookie = new Cookie ('foo ' , 'bar ' , strtotime ('Fri, 20-May-2011 15:25:52 GMT ' ), '/ ' , '.myfoodomain.com ' , true );
146
- $ this ->assertEquals ('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; path=/; domain=.myfoodomain.com; secure; httponly ' , $ cookie -> __toString () , '->__toString() returns string representation of the cookie ' );
149
+ $ cookie = new Cookie ('foo ' , 'bar ' , $ expire = strtotime ('Fri, 20-May-2011 15:25:52 GMT ' ), '/ ' , '.myfoodomain.com ' , true );
150
+ $ this ->assertEquals ('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; max-age= ' .( $ expire - time ()). ' ; path=/; domain=.myfoodomain.com; secure; httponly ' , ( string ) $ cookie , '->__toString() returns string representation of the cookie ' );
147
151
148
152
$ cookie = new Cookie ('foo ' , null , 1 , '/admin/ ' , '.myfoodomain.com ' );
149
- $ this ->assertEquals ('foo=deleted; expires= ' .gmdate ('D, d-M-Y H:i:s T ' , time () - 31536001 ).'; path=/admin/; domain=.myfoodomain.com; httponly ' , $ cookie -> __toString () , '->__toString() returns string representation of a cleared cookie if value is NULL ' );
153
+ $ this ->assertEquals ('foo=deleted; expires= ' .gmdate ('D, d-M-Y H:i:s T ' , $ expire = time () - 31536001 ).'; max-age= ' .( $ expire - time ()). ' ; path=/admin/; domain=.myfoodomain.com; httponly ' , ( string ) $ cookie , '->__toString() returns string representation of a cleared cookie if value is NULL ' );
150
154
151
155
$ cookie = new Cookie ('foo ' , 'bar ' , 0 , '/ ' , '' );
152
- $ this ->assertEquals ('foo=bar; path=/; httponly ' , $ cookie -> __toString () );
156
+ $ this ->assertEquals ('foo=bar; path=/; httponly ' , ( string ) $ cookie );
153
157
}
154
158
155
159
public function testRawCookie ()
@@ -160,4 +164,16 @@ public function testRawCookie()
160
164
$ cookie = new Cookie ('foo ' , 'bar ' , 3600 , '/ ' , '.myfoodomain.com ' , false , true , true );
161
165
$ this ->assertTrue ($ cookie ->isRaw ());
162
166
}
167
+
168
+ public function testGetMaxAge ()
169
+ {
170
+ $ cookie = new Cookie ('foo ' , 'bar ' );
171
+ $ this ->assertEquals (0 , $ cookie ->getMaxAge ());
172
+
173
+ $ cookie = new Cookie ('foo ' , 'bar ' , $ expire = time () + 100 );
174
+ $ this ->assertEquals ($ expire - time (), $ cookie ->getMaxAge ());
175
+
176
+ $ cookie = new Cookie ('foo ' , 'bar ' , $ expire = time () - 100 );
177
+ $ this ->assertEquals ($ expire - time (), $ cookie ->getMaxAge ());
178
+ }
163
179
}
0 commit comments