Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 1 | <?php |
| 2 | |
| 3 | class Encrypt_test extends CI_TestCase { |
| 4 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 5 | public function set_up() |
| 6 | { |
| 7 | $obj = new stdClass; |
| 8 | $obj->encrypt = new Mock_Libraries_Encrypt(); |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 9 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 10 | $this->ci_instance($obj); |
| 11 | $this->encrypt = $obj->encrypt; |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 12 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 13 | $this->ci_set_config('encryption_key', "Encryptin'glike@boss!"); |
| 14 | $this->msg = 'My secret message'; |
| 15 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 16 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 17 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 18 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 19 | public function test_encode() |
| 20 | { |
| 21 | $this->assertNotEquals($this->msg, $this->encrypt->encode($this->msg)); |
| 22 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 23 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 24 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 25 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 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 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 31 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 32 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 33 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 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 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 40 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 41 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 42 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 43 | public function test_default_cipher() |
| 44 | { |
| 45 | $this->assertEquals('rijndael-256', $this->encrypt->get_cipher()); |
| 46 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 47 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 48 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 49 | |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 50 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 51 | public function test_set_cipher() |
| 52 | { |
| 53 | $this->encrypt->set_cipher(MCRYPT_BLOWFISH); |
| 54 | $this->assertEquals('blowfish', $this->encrypt->get_cipher()); |
| 55 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 56 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 57 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 58 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 59 | public function test_default_mode() |
| 60 | { |
| 61 | $this->assertEquals('cbc', $this->encrypt->get_mode()); |
| 62 | } |
| 63 | |
| 64 | // -------------------------------------------------------------------- |
| 65 | |
| 66 | public function test_set_mode() |
| 67 | { |
| 68 | $this->encrypt->set_mode(MCRYPT_MODE_CFB); |
| 69 | $this->assertEquals('cfb', $this->encrypt->get_mode()); |
| 70 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 71 | |
| 72 | } |