1
1
<?php
2
+
2
3
namespace ESolution \DBEncryption \Tests ;
4
+
3
5
use Illuminate \Support \Facades \DB ;
4
6
use Illuminate \Foundation \Testing \RefreshDatabase ;
5
7
6
- class EncryptedTest extends TestCase {
8
+ class EncryptedTest extends TestCase
9
+ {
7
10
8
11
use RefreshDatabase;
9
12
10
13
/**
11
- * @test
12
- */
14
+ * @test
15
+ */
13
16
public function it_test_if_encryption_decoding_is_working ()
14
17
{
15
18
$ name = 'Jhon ' ;
@@ -19,7 +22,6 @@ public function it_test_if_encryption_decoding_is_working()
19
22
20
23
$ this ->assertEquals ($ user ->email , $ email );
21
24
$ this ->assertEquals ($ user ->name , $ name );
22
-
23
25
}
24
26
25
27
/**
@@ -39,8 +41,8 @@ public function it_test_if_encryption_encoding_is_working()
39
41
40
42
41
43
/**
42
- * @test
43
- */
44
+ * @test
45
+ */
44
46
public function it_test_that_encrypt_model_commands_encrypt_existing_records ()
45
47
{
46
48
TestUser::$ enableEncryption = false ;
@@ -58,8 +60,8 @@ public function it_test_that_encrypt_model_commands_encrypt_existing_records()
58
60
59
61
60
62
/**
61
- * @test
62
- */
63
+ * @test
64
+ */
63
65
public function it_test_that_where_in_query_builder_is_working ()
64
66
{
65
67
@@ -68,12 +70,11 @@ public function it_test_that_where_in_query_builder_is_working()
68
70
$ user = TestUser::whereEncrypted ('email ' , '= ' , $ email )->first ();
69
71
70
72
$ this ->assertNotNull ($ user );
71
-
72
73
}
73
74
74
75
/**
75
- * @test
76
- */
76
+ * @test
77
+ */
77
78
public function it_assert_that_where_does_not_retrieve_a_user_with_incorrect_email ()
78
79
{
79
80
$ this ->createUser ();
@@ -93,7 +94,7 @@ public function it_test_that_validation_rule_exists_when_record_exists_is_workin
93
94
94
95
$ this ->createUser ('Jhon Doe ' , $ email );
95
96
96
- $ validator = validator (compact ('email ' ), ['email ' => 'exists_encrypted:test_users,email ' ]);
97
+ $ validator = validator (compact ('email ' ), ['email ' => 'exists_encrypted:test_users,email ' ]);
97
98
98
99
$ this ->assertFalse ($ validator ->fails ());
99
100
}
@@ -106,8 +107,8 @@ public function it_test_that_validation_rule_exists_when_record_does_not_exists_
106
107
$ this ->createUser ();
107
108
108
109
$ validator = validator (
109
-
110
- ['email ' => 'exists_encrypted:test_users,email ' ]
110
+
111
+ ['email ' => 'exists_encrypted:test_users,email ' ]
111
112
);
112
113
113
114
$ this ->assertTrue ($ validator ->fails ());
@@ -123,7 +124,7 @@ public function it_test_that_validation_rule_unique_when_record_exists_is_workin
123
124
124
125
$ this ->createUser ('Jhon Doe ' , $ email );
125
126
126
- $ validator = validator (compact ('email ' ), ['email ' => 'unique_encrypted:test_users,email ' ]);
127
+ $ validator = validator (compact ('email ' ), ['email ' => 'unique_encrypted:test_users,email ' ]);
127
128
128
129
$ this ->assertTrue ($ validator ->fails ());
129
130
}
@@ -136,29 +137,29 @@ public function it_test_that_validation_rule_unique_when_record_does_not_exists_
136
137
$ this ->createUser ();
137
138
138
139
$ validator = validator (
139
-
140
- ['email ' => 'unique_encrypted:test_users,email ' ]
140
+
141
+ ['email ' => 'unique_encrypted:test_users,email ' ]
141
142
);
142
143
143
- $ this ->assertFalse ( $ validator ->fails () );
144
+ $ this ->assertFalse ($ validator ->fails ());
144
145
}
145
146
146
147
/**
147
148
* @test
148
149
*/
149
150
public function it_tests_that_empty_values_are_encrypted ()
150
151
{
151
- $ user =
$ this ->
createUser (
null ,
'[email protected] ' );
152
+ $ user =
$ this ->
createUser (
null ,
'[email protected] ' );
152
153
$ raw = DB ::table ('test_users ' )->select ('* ' )->first ();
153
-
154
+
154
155
$ this ->assertNotEmpty ($ raw ->name );
155
156
$ this ->assertEmpty ($ user ->name );
156
157
}
157
158
158
159
159
160
/**
160
- * @test
161
- */
161
+ * @test
162
+ */
162
163
public function it_test_that_decrypt_command_is_working ()
163
164
{
164
165
TestUser::$ enableEncryption = false ;
@@ -185,4 +186,16 @@ public function it_test_that_where_query_is_working_with_non_lowercase_values()
185
186
$ this ->
assertNotNull (TestUser::
whereEncrypted (
'email ' ,
'= ' ,
'[email protected] ' )->
first ());
186
187
}
187
188
188
- }
189
+ /**
190
+ * @test
191
+ */
192
+ public function it_test_that_whereencrypted_can_handle_single_quote ()
193
+ {
194
+
195
+ $ name = "Single's " ;
196
+ $ this ->createUser ($ name , $ email );
197
+ $ query = TestUser::whereEncrypted ('email ' , $ email )->orWhereEncrypted ('name ' , $ name )->first ();
198
+
199
+ $ this ->assertNotNull ($ query );
200
+ }
201
+ }
0 commit comments