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:
<?php
namespace Guzzle\Tests\Plugin\Cookie\CookieJar;
use Guzzle\Plugin\Cookie\Cookie;
use Guzzle\Plugin\Cookie\CookieJar\FileCookieJar;
class FileCookieJarTest extends \Guzzle\Tests\GuzzleTestCase
{
private $file;
public function setUp()
{
$this->file = tempnam('/tmp', 'file-cookies');
}
public function testLoadsFromFileFile()
{
$jar = new FileCookieJar($this->file);
$this->assertEquals(array(), $jar->all());
unlink($this->file);
}
public function testPersistsToFileFile()
{
$jar = new FileCookieJar($this->file);
$jar->add(new Cookie(array(
'name' => 'foo',
'value' => 'bar',
'domain' => 'foo.com',
'expires' => time() + 1000
)));
$jar->add(new Cookie(array(
'name' => 'baz',
'value' => 'bar',
'domain' => 'foo.com',
'expires' => time() + 1000
)));
$jar->add(new Cookie(array(
'name' => 'boo',
'value' => 'bar',
'domain' => 'foo.com',
)));
$this->assertEquals(3, count($jar));
unset($jar);
$contents = file_get_contents($this->file);
$this->assertNotEmpty($contents);
$jar = new FileCookieJar($this->file);
$this->assertEquals(2, count($jar));
unset($jar);
unlink($this->file);
}
}