public function test_getters_and_setters() { $cookie = new Cookie(); $this->assertFalse($cookie->hasName()); $this->assertFalse($cookie->hasValue()); $cookie->setName('foo'); $this->assertTrue($cookie->hasName()); $this->assertEquals('foo', $cookie->getName()); $cookie->setValue('bar'); $this->assertTrue($cookie->hasValue()); $this->assertEquals('bar', $cookie->getValue()); $this->assertFalse($cookie->hasPath()); $this->assertEquals('/', $cookie->getPath()); $cookie->setPath('foo'); $this->assertTrue($cookie->hasPath()); $this->assertEquals('foo', $cookie->getPath()); $this->assertFalse($cookie->hasDomain()); $cookie->setDomain('bar'); $this->assertTrue($cookie->hasDomain()); $this->assertEquals('bar', $cookie->getDomain()); $this->assertNull($cookie->getExpires()); $this->assertFalse($cookie->hasMaxAge()); $cookie->setMaxAge(1); $this->assertTrue($cookie->hasMaxAge()); $this->assertEquals(time() + 1, $cookie->getExpires()); $this->assertEquals(1, $cookie->getMaxAge()); $this->assertEquals(time() + 1, $cookie->getExpires()); $this->assertTrue($cookie->isHttpOnly()); $cookie->setHttpOnly(false); $this->assertFalse($cookie->isHttpOnly()); $this->assertFalse($cookie->isSecure()); $cookie->setSecure(true); $this->assertTrue($cookie->isSecure()); }
public function test_build() { $builder = new CookieBuilder(); $cookie = new Cookie('foo', 'bar'); $cookie->setPath('/foo/bar'); $cookie->setDomain('foo.bar'); $cookie->setSecure(true); $cookie->setHttpOnly(true); $cookie->setMaxAge(60); $this->assertEquals(s('foo=bar; expires=%s; max-age=%s; path=/foo/bar; domain=foo.bar; secure; httpOnly', $cookie->getExpiresDate(), $cookie->getMaxAge()), $builder->build($cookie)); }