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 | { |
dchill42 | 7ecc5cd | 2012-10-12 16:25:51 -0400 | [diff] [blame] | 7 | $this->encrypt = new Mock_Libraries_Encrypt(); |
| 8 | $this->ci_instance_var('encrypt', $this->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_set_config('encryption_key', "Encryptin'glike@boss!"); |
| 11 | $this->msg = 'My secret message'; |
| 12 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 13 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 14 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 15 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 16 | public function test_encode() |
| 17 | { |
| 18 | $this->assertNotEquals($this->msg, $this->encrypt->encode($this->msg)); |
| 19 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 20 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 21 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 22 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 23 | public function test_decode() |
| 24 | { |
| 25 | $encoded_msg = $this->encrypt->encode($this->msg); |
| 26 | $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg)); |
| 27 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 28 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 29 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 30 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 31 | public function test_optional_key() |
| 32 | { |
| 33 | $key = 'Ohai!ù0129°03182%HD1892P0'; |
| 34 | $encoded_msg = $this->encrypt->encode($this->msg, $key); |
| 35 | $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg, $key)); |
| 36 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 37 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 38 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 39 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 40 | public function test_default_cipher() |
| 41 | { |
| 42 | $this->assertEquals('rijndael-256', $this->encrypt->get_cipher()); |
| 43 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 44 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 45 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 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 | public function test_set_cipher() |
| 49 | { |
| 50 | $this->encrypt->set_cipher(MCRYPT_BLOWFISH); |
| 51 | $this->assertEquals('blowfish', $this->encrypt->get_cipher()); |
| 52 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 53 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 54 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 55 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 56 | public function test_default_mode() |
| 57 | { |
| 58 | $this->assertEquals('cbc', $this->encrypt->get_mode()); |
| 59 | } |
| 60 | |
| 61 | // -------------------------------------------------------------------- |
| 62 | |
| 63 | public function test_set_mode() |
| 64 | { |
| 65 | $this->encrypt->set_mode(MCRYPT_MODE_CFB); |
| 66 | $this->assertEquals('cfb', $this->encrypt->get_mode()); |
| 67 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 68 | |
| 69 | } |