Clears all keys from a single adapter (if a 'name' options is specified) or all
session adapters.
public static clear ( array $options = [] ) | ||
$options | array | Optional parameters that this method accepts: - `'name'` _string_: To force the write to a specific adapter, specify the name of the configuration (i.e. `'default'`) here. - `'strategies'` _boolean_: Indicates whether or not a configuration's applied strategy classes should be enabled for this operation. Defaults to `true`. |
public function testEncryptStrategyWithPhpAdapter() { $config = array('name' => 'encryptInt'); Session::config(array($config['name'] => array('adapter' => 'Php', 'strategies' => array('Encrypt' => array('secret' => 's3cr3t'))))); Session::clear($config); $key = 'test'; $value = 'value'; $this->assertTrue(Session::write($key, $value, $config)); $this->assertEqual($value, Session::read($key, $config)); $this->assertTrue(Session::delete($key, $config)); $this->assertNull(Session::read($key, $config)); Session::clear($config); $this->assertTrue(Session::write('foo', 'bar', $config)); $this->assertEqual('bar', Session::read('foo', $config)); $this->assertTrue(Session::write('foo', 'bar1', $config)); $this->assertEqual('bar1', Session::read('foo', $config)); Session::clear($config); $this->assertTrue(Session::write($key, $value, $config)); $this->assertEqual($value, Session::read($key, $config)); }
public function testEncryptedStrategy() { $this->skipIf(!MockEncrypt::enabled(), 'The Mcrypt extension is not installed or enabled.'); $key = 'foobar'; $adapter = new Memory(); Session::config(array('primary' => array('adapter' => $adapter, 'filters' => array(), 'strategies' => array('lithium\\tests\\mocks\\storage\\session\\strategy\\MockEncrypt' => array('secret' => $key))))); $value = array('foo' => 'bar'); Session::write('test', $value); $this->assertEqual(array('foo' => 'bar'), Session::read('test')); $this->assertTrue(Session::check('test')); $this->assertTrue(Session::check('test', array('strategies' => false))); $encrypted = Session::read('test', array('strategies' => false)); $this->assertNotEqual($value, $encrypted); $this->assertTrue(is_string($encrypted)); $result = Session::read('test'); $this->assertEqual($value, $result); $result = Session::clear(array('strategies' => false)); $this->assertNull(Session::read('test')); $this->assertFalse(Session::check('test')); $this->assertFalse(Session::check('test', array('strategies' => false))); $savedData = array('test' => $value); $encrypt = new MockEncrypt(array('secret' => $key)); $result = $encrypt->encrypt($savedData); $this->assertEqual($encrypted, $result); $result = $encrypt->decrypt($encrypted); $this->assertEqual($savedData, $result); }
public function testStrategies() { Session::config(array('primary' => array('adapter' => new Memory(), 'filters' => array(), 'strategies' => array('lithium\\storage\\cache\\strategy\\Json')))); Session::write('test', array('foo' => 'bar')); $this->assertEqual(array('foo' => 'bar'), Session::read('test')); $this->assertTrue(Session::check('test')); $this->assertTrue(Session::check('test', array('strategies' => false))); $result = Session::read('test', array('strategies' => false)); $this->assertEqual('{"foo":"bar"}', $result); $result = Session::clear(array('strategies' => false)); $this->assertNull(Session::read('test')); $this->assertFalse(Session::check('test')); $this->assertFalse(Session::check('test', array('strategies' => false))); }
public function testEncryptStrategyWithPhpAdapter() { $this->skipIf(PHP_SAPI === 'cli', 'No PHP session support in cli SAPI.'); $this->skipIf(!extension_loaded('mcrypt'), 'The `mcrypt` extension is not loaded.'); $config = array('name' => 'encryptInt'); Session::config(array($config['name'] => array('adapter' => 'Php', 'strategies' => array('Encrypt' => array('secret' => 's3cr3t'))))); Session::clear($config); $key = 'test'; $value = 'value'; $this->assertTrue(Session::write($key, $value, $config)); $this->assertEqual($value, Session::read($key, $config)); $this->assertTrue(Session::delete($key, $config)); $this->assertNull(Session::read($key, $config)); Session::clear($config); $this->assertTrue(Session::write('foo', 'bar', $config)); $this->assertEqual('bar', Session::read('foo', $config)); $this->assertTrue(Session::write('foo', 'bar1', $config)); $this->assertEqual('bar1', Session::read('foo', $config)); Session::clear($config); $this->assertTrue(Session::write($key, $value, $config)); $this->assertEqual($value, Session::read($key, $config)); }
/** * Tests clearing all session data from one or all adapters. * * @return void */ public function testSessionClear() { Session::config(array('primary' => array('adapter' => new Memory(), 'filters' => array()), 'secondary' => array('adapter' => new Memory(), 'filters' => array()))); Session::write('key1', 'value', array('name' => 'primary')); Session::write('key2', 'value', array('name' => 'secondary')); Session::clear(array('name' => 'secondary')); $this->assertTrue(Session::check('key1')); $this->assertFalse(Session::check('key2')); Session::write('key2', 'value', array('name' => 'secondary')); Session::clear(); $this->assertFalse(Session::check('key1')); $this->assertFalse(Session::check('key2')); }