blob: 153a25e1d675e75e6440e14a669c3e128702e564 [file] [log] [blame]
Joffrey Jaffeux9d140752012-06-06 01:40:18 +02001<?php
2
3class Encrypt_test extends CI_TestCase {
4
Andrey Andreevc1862882012-06-09 23:16:58 +03005 public function set_up()
6 {
7 $obj = new stdClass;
8 $obj->encrypt = new Mock_Libraries_Encrypt();
Joffrey Jaffeux9d140752012-06-06 01:40:18 +02009
Andrey Andreevc1862882012-06-09 23:16:58 +030010 $this->ci_instance($obj);
11 $this->encrypt = $obj->encrypt;
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020012
Andrey Andreevc1862882012-06-09 23:16:58 +030013 $this->ci_set_config('encryption_key', "Encryptin'glike@boss!");
14 $this->msg = 'My secret message';
15 }
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020016
Andrey Andreevc1862882012-06-09 23:16:58 +030017 // --------------------------------------------------------------------
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020018
Andrey Andreevc1862882012-06-09 23:16:58 +030019 public function test_encode()
20 {
21 $this->assertNotEquals($this->msg, $this->encrypt->encode($this->msg));
22 }
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020023
Andrey Andreevc1862882012-06-09 23:16:58 +030024 // --------------------------------------------------------------------
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020025
Andrey Andreevc1862882012-06-09 23:16:58 +030026 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 Jaffeux9d140752012-06-06 01:40:18 +020031
Andrey Andreevc1862882012-06-09 23:16:58 +030032 // --------------------------------------------------------------------
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020033
Andrey Andreevc1862882012-06-09 23:16:58 +030034 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 Jaffeux9d140752012-06-06 01:40:18 +020040
Andrey Andreevc1862882012-06-09 23:16:58 +030041 // --------------------------------------------------------------------
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020042
Andrey Andreevc1862882012-06-09 23:16:58 +030043 public function test_default_cipher()
44 {
45 $this->assertEquals('rijndael-256', $this->encrypt->get_cipher());
46 }
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020047
Andrey Andreevc1862882012-06-09 23:16:58 +030048 // --------------------------------------------------------------------
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020049
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020050
Andrey Andreevc1862882012-06-09 23:16:58 +030051 public function test_set_cipher()
52 {
53 $this->encrypt->set_cipher(MCRYPT_BLOWFISH);
54 $this->assertEquals('blowfish', $this->encrypt->get_cipher());
55 }
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020056
Andrey Andreevc1862882012-06-09 23:16:58 +030057 // --------------------------------------------------------------------
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020058
Andrey Andreevc1862882012-06-09 23:16:58 +030059 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 Jaffeux9d140752012-06-06 01:40:18 +020071
72}