15 $this->assertEquals(
'/', $cookie->getPath());
16 $this->assertEquals(array(), $cookie->getPorts());
21 $cookie =
new Cookie(array(
22 'expires' =>
'November 20, 1984'
24 $this->assertTrue(is_numeric($cookie->getExpires()));
30 $cookie =
new Cookie(array(
33 $this->assertEquals($t + 100, $cookie->getExpires());
43 'domain' =>
'baz.com',
47 'comment_url' =>
'foo.com',
48 'port' => array(1, 2),
59 $cookie =
new Cookie($data);
60 $this->assertEquals($data, $cookie->toArray());
62 $this->assertEquals(
'foo', $cookie->getName());
63 $this->assertEquals(
'baz', $cookie->getValue());
64 $this->assertEquals(
'baz.com', $cookie->getDomain());
65 $this->assertEquals(
'/bar', $cookie->getPath());
66 $this->assertEquals($t, $cookie->getExpires());
67 $this->assertEquals(100, $cookie->getMaxAge());
68 $this->assertEquals(
'Hi', $cookie->getComment());
69 $this->assertEquals(
'foo.com', $cookie->getCommentUrl());
70 $this->assertEquals(array(1, 2), $cookie->getPorts());
71 $this->assertEquals(2, $cookie->getVersion());
72 $this->assertTrue($cookie->getSecure());
73 $this->assertTrue($cookie->getDiscard());
74 $this->assertTrue($cookie->getHttpOnly());
75 $this->assertEquals(
'baz', $cookie->getAttribute(
'foo'));
76 $this->assertEquals(
'bam', $cookie->getAttribute(
'bar'));
77 $this->assertEquals(array(
80 ), $cookie->getAttributes());
85 ->setDomain(
'bar.com')
95 ->setAttribute(
'snoop',
'dog');
97 $this->assertEquals(
'a', $cookie->getName());
98 $this->assertEquals(
'b', $cookie->getValue());
99 $this->assertEquals(
'c', $cookie->getPath());
100 $this->assertEquals(
'bar.com', $cookie->getDomain());
101 $this->assertEquals(10, $cookie->getExpires());
102 $this->assertEquals(200, $cookie->getMaxAge());
103 $this->assertEquals(
'e', $cookie->getComment());
104 $this->assertEquals(
'f', $cookie->getCommentUrl());
105 $this->assertEquals(array(80), $cookie->getPorts());
106 $this->assertEquals(3, $cookie->getVersion());
107 $this->assertFalse($cookie->getSecure());
108 $this->assertFalse($cookie->getDiscard());
109 $this->assertFalse($cookie->getHttpOnly());
110 $this->assertEquals(
'dog', $cookie->getAttribute(
'snoop'));
117 $this->assertTrue($c->isExpired());
118 $c->setExpires(time() + 10000);
119 $this->assertFalse($c->isExpired());
126 $this->assertTrue($cookie->matchesPort(2));
128 $cookie->setPorts(array(1, 2));
129 $this->assertTrue($cookie->matchesPort(2));
130 $this->assertFalse($cookie->matchesPort(100));
136 $this->assertTrue($cookie->matchesDomain(
'baz.com'));
138 $cookie->setDomain(
'baz.com');
139 $this->assertTrue($cookie->matchesDomain(
'baz.com'));
140 $this->assertFalse($cookie->matchesDomain(
'bar.com'));
142 $cookie->setDomain(
'.baz.com');
143 $this->assertTrue($cookie->matchesDomain(
'.baz.com'));
144 $this->assertTrue($cookie->matchesDomain(
'foo.baz.com'));
145 $this->assertFalse($cookie->matchesDomain(
'baz.bar.com'));
146 $this->assertTrue($cookie->matchesDomain(
'baz.com'));
148 $cookie->setDomain(
'.127.0.0.1');
149 $this->assertTrue($cookie->matchesDomain(
'127.0.0.1'));
151 $cookie->setDomain(
'127.0.0.1');
152 $this->assertTrue($cookie->matchesDomain(
'127.0.0.1'));
154 $cookie->setDomain(
'.com.');
155 $this->assertFalse($cookie->matchesDomain(
'baz.com'));
157 $cookie->setDomain(
'.local');
158 $this->assertTrue($cookie->matchesDomain(
'example.local'));
164 $this->assertTrue($cookie->matchesPath(
'/foo'));
166 $cookie->setPath(
'/foo');
169 $this->assertTrue($cookie->matchesPath(
'/foo'));
170 $this->assertFalse($cookie->matchesPath(
'/bar'));
175 $this->assertTrue($cookie->matchesPath(
'/foo/bar'));
176 $this->assertFalse($cookie->matchesPath(
'/fooBar'));
180 $cookie->setPath(
'/foo/');
181 $this->assertTrue($cookie->matchesPath(
'/foo/bar'));
182 $this->assertFalse($cookie->matchesPath(
'/fooBaz'));
183 $this->assertFalse($cookie->matchesPath(
'/foo'));
190 array(
'foo',
'baz',
'bar',
true),
191 array(
'0',
'0',
'0',
true),
192 array(
'',
'baz',
'bar',
'The cookie name must not be empty'),
193 array(
'foo',
'',
'bar',
'The cookie value must not be empty'),
194 array(
'foo',
'baz',
'',
'The cookie domain must not be empty'),
195 array(
'foo\\',
'baz',
'0',
'The cookie name must not contain invalid characters: foo\\'),
204 $cookie =
new Cookie(array(
209 $this->assertSame($result, $cookie->validate());
214 $m = new \ReflectionMethod(
'Guzzle\Plugin\Cookie\Cookie',
'getInvalidCharacters');
215 $m->setAccessible(
true);
216 $p = new \ReflectionProperty(
'Guzzle\Plugin\Cookie\Cookie',
'invalidCharString');
217 $p->setAccessible(
true);
220 $this->assertEquals(51, strlen($m->invoke($m)));
221 $this->assertContains(
'@', $m->invoke($m));