Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame^] | 1 | <?php |
| 2 | |
| 3 | class Encrypt_test extends CI_TestCase { |
| 4 | |
| 5 | public function set_up() |
| 6 | { |
| 7 | $obj = new StdClass; |
| 8 | $obj->encrypt = new Mock_Libraries_Encrypt(); |
| 9 | |
| 10 | $this->ci_instance($obj); |
| 11 | $this->encrypt = $obj->encrypt; |
| 12 | |
| 13 | $this->ci_set_config('encryption_key', "Encryptin'glike@boss!"); |
| 14 | $this->msg = 'My secret message'; |
| 15 | } |
| 16 | |
| 17 | // -------------------------------------------------------------------- |
| 18 | |
| 19 | public function test_encode() |
| 20 | { |
| 21 | $this->assertNotEquals($this->msg, $this->encrypt->encode($this->msg)); |
| 22 | } |
| 23 | |
| 24 | // -------------------------------------------------------------------- |
| 25 | |
| 26 | public function test_decode() |
| 27 | { |
| 28 | $encoded_msg = $this->encrypt->encode($this->msg); |
| 29 | $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg)); |
| 30 | } |
| 31 | |
| 32 | // -------------------------------------------------------------------- |
| 33 | |
| 34 | public function test_optional_key() |
| 35 | { |
| 36 | $key = 'Ohai!ù0129°03182%HD1892P0'; |
| 37 | $encoded_msg = $this->encrypt->encode($this->msg, $key); |
| 38 | $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg, $key)); |
| 39 | } |
| 40 | |
| 41 | // -------------------------------------------------------------------- |
| 42 | |
| 43 | public function test_default_cipher() |
| 44 | { |
| 45 | $this->assertEquals('rijndael-256', $this->encrypt->get_cipher()); |
| 46 | } |
| 47 | |
| 48 | // -------------------------------------------------------------------- |
| 49 | |
| 50 | public function test_set_cipher() |
| 51 | { |
| 52 | $this->encrypt->set_cipher(MCRYPT_BLOWFISH); |
| 53 | $this->assertEquals('blowfish', $this->encrypt->get_cipher()); |
| 54 | } |
| 55 | |
| 56 | // -------------------------------------------------------------------- |
| 57 | |
| 58 | public function test_default_mode() |
| 59 | { |
| 60 | $this->assertEquals('cbc', $this->encrypt->get_mode()); |
| 61 | } |
| 62 | |
| 63 | // -------------------------------------------------------------------- |
| 64 | |
| 65 | public function test_set_mode() |
| 66 | { |
| 67 | $this->encrypt->set_mode(MCRYPT_MODE_CFB); |
| 68 | $this->assertEquals('cfb', $this->encrypt->get_mode()); |
| 69 | } |
| 70 | |
| 71 | } |