You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PhalApi_Cookie_Multi_Test.php 1.9 KiB

3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/usr/bin/env php
  2. <?php
  3. /**
  4. * PhpUnderControl_PhalApiCookieMulti_Test
  5. *
  6. * 针对 ../../PhalApi/Cookie/Multi.php PhalApi_Cookie_Multi 类的PHPUnit单元测试
  7. *
  8. * @author: dogstar 20150411
  9. */
  10. require_once dirname(__FILE__) . '/../test_env.php';
  11. if (!class_exists('PhalApi_Cookie_Multi')) {
  12. require dirname(__FILE__) . '/../../PhalApi/Cookie/Multi.php';
  13. }
  14. class PhpUnderControl_PhalApiCookieMulti_Test extends PHPUnit_Framework_TestCase
  15. {
  16. public $phalApiCookieMulti;
  17. protected function setUp()
  18. {
  19. parent::setUp();
  20. $config = array('crypt' => new Cookie_Crypt_Mock(), 'key' => 'aha~');
  21. $this->phalApiCookieMulti = new PhalApi_Cookie_Multi($config);
  22. }
  23. protected function tearDown()
  24. {
  25. }
  26. /**
  27. * @group testGet
  28. */
  29. public function testGet()
  30. {
  31. $name = NULL;
  32. $rs = $this->phalApiCookieMulti->get($name);
  33. $this->assertTrue(is_array($rs));
  34. }
  35. /**
  36. * @group testSet
  37. */
  38. public function testSet()
  39. {
  40. $name = 'aEKey';
  41. $value = '2015';
  42. $expire = $_SERVER['REQUEST_TIME'] + 10;
  43. $rs = @$this->phalApiCookieMulti->set($name, $value, $expire);
  44. //remember
  45. $this->assertEquals($value, $this->phalApiCookieMulti->get($name));
  46. }
  47. /**
  48. * @group testDelete
  49. */
  50. public function testDelete()
  51. {
  52. $name = 'aEKey';
  53. $value = '2015';
  54. $expire = $_SERVER['REQUEST_TIME'] + 10;
  55. $rs = @$this->phalApiCookieMulti->set($name, $value, $expire);
  56. $this->assertNotEmpty($this->phalApiCookieMulti->get($name));
  57. $rs = @$this->phalApiCookieMulti->delete($name);
  58. $this->assertNull($this->phalApiCookieMulti->get($name));
  59. }
  60. }
  61. class Cookie_Crypt_Mock implements PhalApi_Crypt {
  62. public function encrypt($data, $key) {
  63. return base64_encode($data);
  64. }
  65. public function decrypt($data, $key) {
  66. return base64_decode($data);
  67. }
  68. }