示例#1
0
 public function testOne()
 {
     $jar = new CookieJar();
     $this->assertEquals(0, $jar->count());
     $jar->add(array('name' => 'foo', 'value' => 'dingbat', "domain" => '.client9.com', 'path' => '/'));
     $this->assertEquals(1, $jar->count());
     $jar->add(array('name' => 'foo', 'value' => 'dingbat', "domain" => '.sdfs.com', 'path' => '/'));
     $this->assertEquals(2, $jar->count());
     $jar->add(array('name' => 'foo', 'value' => 'asterisk', "domain" => '.client9.com', 'path' => '/'));
     $this->assertEquals(2, $jar->count());
     $matches = $jar->get('www.client9.com', '/', FALSE);
     $this->assertEquals(1, count($matches));
     $m = array_shift($matches);
     $this->assertEquals('foo', $m['name']);
     $this->assertEquals('asterisk', $m['value']);
     $jar->clearByDomain('.client9.com');
     $this->assertEquals(1, $jar->count());
     // do nothing
     $jar->clearByDomain('junk');
     $this->assertEquals(1, $jar->count());
     // do nothing
     $jar->clearByName('junk');
     $this->assertEquals(1, $jar->count());
     // all gone
     $jar->clearSessions();
     $this->assertEquals(0, $jar->count());
     $jar->add(array('name' => 'foo', 'value' => 'dingbat', "domain" => '.client9.com', 'path' => '/', 'expires' => 'Fri, 31-Dec-2010 23:59:59 GMT'));
     $this->assertEquals(1, $jar->count());
     $jar->clearSessions();
     $this->assertEquals(1, $jar->count());
     $jar->clearExpired();
     $this->assertEquals(0, $jar->count());
 }
 /**
  * Check we can remove cookies and we can access their original values
  */
 public function testForceExpiry()
 {
     //load an existing cookie
     $cookieJar = new CookieJar(array('cookieExisting' => 'i woz here'));
     //make sure it's available
     $this->assertEquals('i woz here', $cookieJar->get('cookieExisting'));
     //remove the cookie
     $cookieJar->forceExpiry('cookieExisting');
     //check it's gone
     $this->assertEmpty($cookieJar->get('cookieExisting'));
     //check we can get it's original value
     $this->assertEquals('i woz here', $cookieJar->get('cookieExisting', false));
     //check we can add a new cookie and remove it and it doesn't leave any phantom values
     $cookieJar->set('newCookie', 'i am new');
     //check it's set by not received
     $this->assertEquals('i am new', $cookieJar->get('newCookie'));
     $this->assertEmpty($cookieJar->get('newCookie', false));
     //remove it
     $cookieJar->forceExpiry('newCookie');
     //check it's neither set nor received
     $this->assertEmpty($cookieJar->get('newCookie'));
     $this->assertEmpty($cookieJar->get('newCookie', false));
 }