Changeset 376

Show
Ignore:
Timestamp:
03/14/07 10:36:27 (1 year ago)
Author:
mikey
Message:

created a more generic version of reset()

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/ipo/session/stubAbstractSession.php

    r374 r376  
    150150    } 
    151151     
     152     /** 
     153     * resets the session and deletes all session data 
     154     * 
     155     * @return  int 
     156     */ 
     157    public function reset() 
     158    { 
     159        $valueKeys = $this->getValueKeys(); 
     160        $count     = 0; 
     161        foreach ($valueKeys as $valueKey) { 
     162            if (stubSession::NEXT_TOKEN == $valueKey || stubSession::FINGERPRINT == $valueKey) { 
     163                continue; 
     164            } 
     165             
     166            if (stubSession::START_TIME == $valueKey) { 
     167                $this->putValue(stubSession::START_TIME, time()); 
     168                continue; 
     169            } 
     170             
     171            $count += (int) $this->doRemoveValue($valueKey); 
     172        } 
     173         
     174        return $count; 
     175    } 
     176     
    152177    /** 
    153178     * returns a value associated with the key or the default value 
  • trunk/src/main/php/net/stubbles/ipo/session/stubPHPSession.php

    r374 r376  
    8080        @session_start(); 
    8181    } 
    82      
    83     /** 
    84      * resets the session and deletes all session data 
    85      * 
    86      * @return  int 
    87      */ 
    88     public function reset() 
    89     { 
    90         $nextToken = $_SESSION[stubSession::NEXT_TOKEN]; 
    91         $_SESSION  = array(stubSession::START_TIME  => time(), 
    92                            stubSession::FINGERPRINT => $this->getFingerprint(), 
    93                            stubSession::NEXT_TOKEN  => $nextToken 
    94                      ); 
    95     } 
    96      
     82 
    9783    /** 
    9884     * stores a value associated with the key 
  • trunk/src/test/php/net/stubbles/ipo/session/stubAbstractSessionTestCase.php

    r374 r376  
    3636    public function regenerateID() { $this->id = 'foo'; } 
    3737 
    38     public function invalidate() { $this->reset(); } 
    39  
    40     public function reset() { $this->data = array(); } 
     38    public function invalidate() { $this->data = array(); } 
    4139 
    4240    public function putValue($key, $value) { $this->data[$key] = $value; } 
     
    182180        $this->assertNotEqual($this->session->getCurrentToken(),'dummy'); 
    183181    } 
     182     
     183    /** 
     184     * test that resetting the session removes all stored values but does not 
     185     * make the session invalid 
     186     */ 
     187    public function testReset() 
     188    { 
     189        $this->session->putValue('foo', 'baz'); 
     190        $nextToken = $this->session->getNextToken(); 
     191        $this->assertEqual($this->session->reset(), 1); 
     192        $this->assertTrue($this->session->isValid()); 
     193        $this->assertEqual($this->session->getNextToken(), $nextToken); 
     194        $this->assertFalse($this->session->hasValue('foo')); 
     195    } 
    184196} 
    185197?> 
  • trunk/src/test/php/net/stubbles/ipo/session/stubPHPSessionTestCase.php

    r374 r376  
    6666        $this->assertFalse($this->session->isValid()); 
    6767    } 
    68      
    69     /** 
    70      * test that resetting the session removes all stored values but does not 
    71      * make the session invalid 
    72      */ 
    73     public function testReset() 
    74     { 
    75         $this->session->putValue('foo', 'baz'); 
    76         $nextToken = $this->session->getNextToken(); 
    77         $this->session->reset(); 
    78         $this->assertTrue($this->session->isValid()); 
    79         $this->assertEqual($this->session->getNextToken(), $nextToken); 
    80         $this->assertFalse($this->session->hasValue('foo')); 
    81     } 
    82      
     68 
    8369    /** 
    8470     * test getting a value from session