colly_wyx
2018-06-13 e4d5467f055ece8cc9dfdc02dd836bcc187034a5
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
#!/usr/bin/env php
<?php
/**
 * PhpUnderControl_PhalApiCookieMulti_Test
 *
 * 针对 ../../PhalApi/Cookie/Multi.php PhalApi_Cookie_Multi 类的PHPUnit单元测试
 *
 * @author: dogstar 20150411
 */
 
require_once dirname(__FILE__) . '/../test_env.php';
 
if (!class_exists('PhalApi_Cookie_Multi')) {
    require dirname(__FILE__) . '/../../PhalApi/Cookie/Multi.php';
}
 
class PhpUnderControl_PhalApiCookieMulti_Test extends PHPUnit_Framework_TestCase
{
    public $phalApiCookieMulti;
 
    protected function setUp()
    {
        parent::setUp();
 
        $config = array('crypt' => new Cookie_Crypt_Mock(), 'key' => 'aha~');
        $this->phalApiCookieMulti = new PhalApi_Cookie_Multi($config);
    }
 
    protected function tearDown()
    {
    }
 
 
    /**
     * @group testGet
     */ 
    public function testGet()
    {
        $name = NULL;
 
        $rs = $this->phalApiCookieMulti->get($name);
 
        $this->assertTrue(is_array($rs));
 
    }
 
    /**
     * @group testSet
     */ 
    public function testSet()
    {
        $name = 'aEKey';
        $value = '2015';
        $expire = $_SERVER['REQUEST_TIME'] + 10;
 
        $rs = @$this->phalApiCookieMulti->set($name, $value, $expire);
 
        //remember
        $this->assertEquals($value, $this->phalApiCookieMulti->get($name));
    }
 
    /**
     * @group testDelete
     */ 
    public function testDelete()
    {
        $name = 'aEKey';
        $value = '2015';
        $expire = $_SERVER['REQUEST_TIME'] + 10;
 
        $rs = @$this->phalApiCookieMulti->set($name, $value, $expire);
 
        $this->assertNotEmpty($this->phalApiCookieMulti->get($name));
 
        $rs = @$this->phalApiCookieMulti->delete($name);
 
        $this->assertNull($this->phalApiCookieMulti->get($name));
    }
 
}
 
class Cookie_Crypt_Mock implements PhalApi_Crypt {
 
    public function encrypt($data, $key) {
        return base64_encode($data);
    }
 
    public function decrypt($data, $key) {
        return base64_decode($data);
    }
}