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: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382:
<?php
namespace Guzzle\Tests\Parser\Cookie;
use Guzzle\Http\Url;
class CookieParserProvider extends \Guzzle\Tests\GuzzleTestCase
{
public function cookieParserDataProvider()
{
return array(
array(
'ASIHTTPRequestTestCookie=This+is+the+value; expires=Sat, 26-Jul-2008 17:00:42 GMT; path=/tests; domain=allseeing-i.com; PHPSESSID=6c951590e7a9359bcedde25cda73e43c; path=/";',
array(
'domain' => 'allseeing-i.com',
'path' => '/',
'data' => array(
'PHPSESSID' => '6c951590e7a9359bcedde25cda73e43c'
),
'max_age' => NULL,
'expires' => 'Sat, 26-Jul-2008 17:00:42 GMT',
'version' => NULL,
'secure' => NULL,
'discard' => NULL,
'port' => NULL,
'cookies' => array(
'ASIHTTPRequestTestCookie' => 'This+is+the+value'
),
'comment' => null,
'comment_url' => null,
'http_only' => false
)
),
array('', false),
array('foo', false),
array(array(
'foo=', 'foo =', 'foo =;', 'foo= ;', 'foo =', 'foo= '),
array(
'cookies' => array(
'foo' => ''
),
'data' => array(),
'discard' => null,
'domain' => null,
'expires' => null,
'max_age' => null,
'path' => '/',
'port' => null,
'secure' => null,
'version' => null,
'comment' => null,
'comment_url' => null,
'http_only' => false
)
),
array(array(
'foo=1', 'foo =1', 'foo =1;', 'foo=1 ;', 'foo =1', 'foo= 1', 'foo = 1 ;', 'foo="1"', 'foo="1";', 'foo= "1";'),
array(
'cookies' => array(
'foo' => '1'
),
'data' => array(),
'discard' => null,
'domain' => null,
'expires' => null,
'max_age' => null,
'path' => '/',
'port' => null,
'secure' => null,
'version' => null,
'comment' => null,
'comment_url' => null,
'http_only' => false
)
),
array(array(
'foo=1; bar=2;', 'foo =1; bar = "2"', 'foo=1; bar=2'),
array(
'cookies' => array(
'foo' => '1',
'bar' => '2',
),
'data' => array(),
'discard' => null,
'domain' => null,
'expires' => null,
'max_age' => null,
'path' => '/',
'port' => null,
'secure' => null,
'version' => null,
'comment' => null,
'comment_url' => null,
'http_only' => false
)
),
array(array(
'foo=1; port="80,8081"; httponly', 'foo=1; port="80,8081"; domain=www.test.com; HttpOnly;', 'foo=1; ; domain=www.test.com; path=/path; port="80,8081"; HttpOnly;'),
array(
'cookies' => array(
'foo' => 1
),
'data' => array(),
'discard' => null,
'domain' => 'www.test.com',
'expires' => null,
'max_age' => null,
'path' => '/path',
'port' => array('80', '8081'),
'secure' => null,
'version' => null,
'comment' => null,
'comment_url' => null,
'http_only' => true
),
'http://www.test.com/path/'
),
array(
'justacookie=foo; domain=example.com',
array(
'cookies' => array(
'justacookie' => 'foo'
),
'domain' => 'example.com',
'data' => array(),
'discard' => null,
'expires' => null,
'max_age' => null,
'path' => '/',
'port' => null,
'secure' => null,
'version' => null,
'comment' => null,
'comment_url' => null,
'http_only' => false
)
),
array(
'expires=tomorrow; secure; path=/Space Out/; expires=Tue, 21-Nov-2006 08:33:44 GMT; domain=.example.com',
array(
'cookies' => array(
'expires' => 'tomorrow'
),
'domain' => '.example.com',
'path' => '/Space Out/',
'expires' => 'Tue, 21-Nov-2006 08:33:44 GMT',
'data' => array(),
'discard' => null,
'port' => null,
'secure' => true,
'version' => null,
'max_age' => null,
'comment' => null,
'comment_url' => null,
'http_only' => false
)
),
array(
'domain=unittests; expires=Tue, 21-Nov-2006 08:33:44 GMT; domain=example.com; path=/some value/',
array(
'cookies' => array(
'domain' => 'unittests'
),
'domain' => 'example.com',
'path' => '/some value/',
'expires' => 'Tue, 21-Nov-2006 08:33:44 GMT',
'secure' => false,
'data' => array(),
'discard' => null,
'max_age' => null,
'port' => null,
'version' => null,
'comment' => null,
'comment_url' => null,
'http_only' => false
)
),
array(
'path=indexAction; path=/; domain=.foo.com; expires=Tue, 21-Nov-2006 08:33:44 GMT',
array(
'cookies' => array(
'path' => 'indexAction'
),
'domain' => '.foo.com',
'path' => '/',
'expires' => 'Tue, 21-Nov-2006 08:33:44 GMT',
'secure' => false,
'data' => array(),
'discard' => null,
'max_age' => null,
'port' => null,
'version' => null,
'comment' => null,
'comment_url' => null,
'http_only' => false
)
),
array(
'secure=sha1; secure; SECURE; domain=some.really.deep.domain.com; version=1; Max-Age=86400',
array(
'cookies' => array(
'secure' => 'sha1'
),
'domain' => 'some.really.deep.domain.com',
'path' => '/',
'secure' => true,
'data' => array(),
'discard' => null,
'expires' => time() + 86400,
'max_age' => 86400,
'port' => null,
'version' => 1,
'comment' => null,
'comment_url' => null,
'http_only' => false
)
),
array(
'PHPSESSID=123456789+abcd%2Cef; secure; discard; domain=.localdomain; path=/foo/baz; expires=Tue, 21-Nov-2006 08:33:44 GMT;',
array(
'cookies' => array(
'PHPSESSID' => '123456789+abcd%2Cef'
),
'domain' => '.localdomain',
'path' => '/foo/baz',
'expires' => 'Tue, 21-Nov-2006 08:33:44 GMT',
'secure' => true,
'data' => array(),
'discard' => true,
'max_age' => null,
'port' => null,
'version' => null,
'comment' => null,
'comment_url' => null,
'http_only' => false
)
),
array(
'cookie=value',
array(
'cookies' => array(
'cookie' => 'value'
),
'domain' => 'example.com',
'data' => array(),
'discard' => null,
'expires' => null,
'max_age' => null,
'path' => '/some/path',
'port' => null,
'secure' => null,
'version' => null,
'comment' => null,
'comment_url' => null,
'http_only' => false
),
'http://example.com/some/path/test.html'
),
array(
'empty=path',
array(
'cookies' => array(
'empty' => 'path'
),
'domain' => 'example.com',
'data' => array(),
'discard' => null,
'expires' => null,
'max_age' => null,
'path' => '/',
'port' => null,
'secure' => null,
'version' => null,
'comment' => null,
'comment_url' => null,
'http_only' => false
),
'http://example.com/test.html'
),
array(
'baz=qux',
array(
'cookies' => array(
'baz' => 'qux'
),
'domain' => 'example.com',
'data' => array(),
'discard' => null,
'expires' => null,
'max_age' => null,
'path' => '/',
'port' => null,
'secure' => null,
'version' => null,
'comment' => null,
'comment_url' => null,
'http_only' => false
),
'http://example.com?query=here'
),
array(
'test=noSlashPath; path=someString',
array(
'cookies' => array(
'test' => 'noSlashPath'
),
'domain' => 'example.com',
'data' => array(),
'discard' => null,
'expires' => null,
'max_age' => null,
'path' => '/real/path',
'port' => null,
'secure' => null,
'version' => null,
'comment' => null,
'comment_url' => null,
'http_only' => false
),
'http://example.com/real/path/'
),
);
}
public function testParseCookie($cookie, $parsed, $url = null)
{
$c = $this->cookieParserClass;
$parser = new $c();
$request = null;
if ($url) {
$url = Url::factory($url);
$host = $url->getHost();
$path = $url->getPath();
} else {
$host = '';
$path = '';
}
foreach ((array) $cookie as $c) {
$p = $parser->parseCookie($c, $host, $path);
if ($p['expires'] != $parsed['expires']) {
if (abs($p['expires'] - $parsed['expires']) < 300) {
unset($p['expires']);
unset($parsed['expires']);
}
}
if (is_array($parsed)) {
foreach ($parsed as $key => $value) {
$this->assertEquals($parsed[$key], $p[$key], 'Comparing ' . $key . ' ' . var_export($value, true) . ' : ' . var_export($parsed, true) . ' | ' . var_export($p, true));
}
foreach ($p as $key => $value) {
$this->assertEquals($p[$key], $parsed[$key], 'Comparing ' . $key . ' ' . var_export($value, true) . ' : ' . var_export($parsed, true) . ' | ' . var_export($p, true));
}
} else {
$this->assertEquals($parsed, $p);
}
}
}
}