root/trunk/src/test/php/net/stubbles/ipo/session/stubNoneDurableSessionTestCase.php @ 1531

Revision 1531, 3.1 kB (checked in by mikey, 2 years ago)

implemented refactoring #142: refactor session so it has access to the response

Line 
1<?php
2/**
3 * Tests for net::stubbles::ipo::session::stubNoneDurableSession.
4 *
5 * @author      Frank Kleine <mikey@stubbles.net>
6 * @package     stubbles
7 * @subpackage  ipo_session_test
8 */
9stubClassLoader::load('net::stubbles::ipo::session::stubNoneDurableSession');
10/**
11 * Tests for net::stubbles::ipo::session::stubNoneDurableSession.
12 *
13 * @package     stubbles
14 * @subpackage  ipo_session_test
15 */
16class stubNoneDurableSessionTestCase extends PHPUnit_Framework_TestCase
17{
18    /**
19     * instance to test
20     *
21     * @var  stubNoneDurableSession
22     */
23    protected $session;
24
25    /**
26     * set up test environment
27     */
28    public function setUp()
29    {
30        $this->session = new stubNoneDurableSession($this->getMock('stubRequest'), $this->getMock('stubResponse'), 'test');
31    }
32
33    /**
34     * test that regenerating the id gives a new id for the session
35     *
36     * @test
37     */
38    public function regenerateId()
39    {
40        $id = $this->session->getId();
41        $this->session->regenerateId();
42        $this->assertNotEquals($id, $this->session->getId());
43    }
44
45    /**
46     * test that invalidating the session makes it invalid
47     *
48     * @test
49     */
50    public function invalidate()
51    {
52        $this->session->invalidate();
53        $this->assertFalse($this->session->isValid());
54    }
55
56    /**
57     * test getting a value from session
58     *
59     * @test
60     */
61    public function putGetHasValue()
62    {
63        $this->assertNull($this->session->getValue('foo'));
64        $this->assertEquals('bar', $this->session->getValue('foo', 'bar'));
65        $this->assertFalse($this->session->hasValue('foo'));
66        $this->session->putValue('foo', 'baz');
67        $this->assertTrue($this->session->hasValue('foo'));
68        $this->assertEquals('baz', $this->session->getValue('foo'));
69        $this->assertEquals('baz', $this->session->getValue('foo', 'bar'));
70    }
71
72    /**
73     * test removing a value from session
74     *
75     * @test
76     */
77    public function removeValue()
78    {
79        $this->assertFalse($this->session->removeValue('foo'));
80        $this->session->putValue('foo', 'baz');
81        $this->assertTrue($this->session->hasValue('foo'));
82        $this->assertTrue($this->session->removeValue('foo'));
83        $this->assertFalse($this->session->hasValue('foo'));
84        $this->assertFalse($this->session->removeValue('foo'));
85    }
86
87    /**
88     * assure the the value keys are returned as expected
89     *
90     * @test
91     */
92    public function getValueKeys()
93    {
94        $this->assertEquals(array(stubSession::START_TIME,
95                                  stubSession::FINGERPRINT,
96                                  stubSession::NEXT_TOKEN
97                            ),
98                            $this->session->getValueKeys()
99        );
100        $this->session->putValue('foo', 'baz');
101        $this->assertEquals(array(stubSession::START_TIME,
102                                  stubSession::FINGERPRINT,
103                                  stubSession::NEXT_TOKEN,
104                                 'foo'
105                            ),
106                            $this->session->getValueKeys()
107        );
108    }
109}
110?>
Note: See TracBrowser for help on using the browser.