Login   Register  
PHP Classes
elePHPant
Icontem

File: tests/Pimf/Util/CryptTest.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Gjero Krsteski  >  PIMF  >  tests/Pimf/Util/CryptTest.php  >  Download  
File: tests/Pimf/Util/CryptTest.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: PIMF
Framework for Web application development
Author: By
Last change:
Date: 5 months ago
Size: 1,784 bytes
 

Contents

Class file image Download
<?php

class CryptTest extends PHPUnit_Framework_TestCase {

    public function 
testCreatingNewInstance()
    {
        new \
Pimf\Util\Crypt();
    }

    public function 
testEncryptExpectsBase64Output()
    {
        
$cryper = new \Pimf\Util\Crypt();
        
$encrypted $cryper->encrypt('some data here');

        
$this->assertTrue(base64_decode($encryptedtrue) !== false);
    }

    public function 
testDecryptExpectsStringOutput()
    {
        
$cryper = new \Pimf\Util\Crypt();
        
$encrypted $cryper->encrypt('t i n t e d');
        
$decrypted $cryper->decrypt($encrypted);

        
$this->assertInternalType('string'$decrypted);
    }

    public function 
testEncryptAndDecryptByOneInstance()
    {
        
$tinted json_encode(array('email' => 'test@test.de''expires' => time()));

        
$cryper = new \Pimf\Util\Crypt();

        
$encrypted $cryper->encrypt($tinted);
        
$decrypted $cryper->decrypt($encrypted);

        
$this->assertTrue($decrypted === $tinted'decrypted data is not same as tinted data!');
    }

    public function 
testEncryptAndDecryptByTwoInstances()
    {
        
$tinted json_encode(array('email' => 'test@test.de''expires' => time()));

        
$cryper = new \Pimf\Util\Crypt();
        
$encrypted $cryper->encrypt($tinted);

        
$cryper = new \Pimf\Util\Crypt();
        
$decrypted $cryper->decrypt($encrypted);

        
$this->assertTrue($decrypted === $tinted'decrypted data is not same as tinted data!');
    }

    
/**
     * @expectedException \PHPUnit_Framework_Error_Warning
     */
    
public function testExpectingErrorWarningIfDecryptGetsNotHisOwnCipherTextBase64()
    {
        
$cryper = new \Pimf\Util\Crypt();
        
$cryper->decrypt(base64_encode('comes not from mr. crypt'));
    }

}