lithium\tests\cases\storage\SessionTest::testEncryptedStrategy PHP Method

testEncryptedStrategy() public method

    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->assertInternalType('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);
    }