1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace devtoolboxuk\soteria; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
|
7
|
|
|
class StringTest extends TestCase |
8
|
|
|
{ |
9
|
|
|
protected $testString = 'Test String'; |
10
|
|
|
protected $testEmail = '[email protected]'; |
11
|
|
|
protected $testUrl = 'https://www.google.com'; |
12
|
|
|
protected $latinAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
13
|
|
|
protected $numbers = '0123456789'; |
14
|
|
|
protected $specialCharactersA = '!"£$%^&*()_+{}:@~<>?¬|'; |
15
|
|
|
protected $specialCharactersB = "\`-=[];'#,./`"; |
16
|
|
|
protected $germanSpecialCharacters = "ÄÖÜẞäöüß"; |
17
|
|
|
protected $frenchSpecialCharacters = "âàäçéèêëîïôùûüœ"; |
18
|
|
|
protected $dutchSpecialCharacters = "áéíóúàèëïöüijÁÉÍÓÚÀÈËÏÖÜIJ"; |
19
|
|
|
protected $spanishSpecialCharacters = "áéíóúñü¿¡"; |
20
|
|
|
protected $scandinavianSpecialCharactersA = "æÆäÄøØöÖåÅ"; |
21
|
|
|
protected $scandinavianSpecialCharactersB = "ÅåÄäÖöŠšŽž"; |
22
|
|
|
protected $irishSpecialCharacters = "áíéóú"; |
23
|
|
|
protected $polishSpecialCharactersA = "AĄBCĆDEĘFGHIJKLŁMNŃOÓPRSŚTUWYZŹŻ"; |
24
|
|
|
protected $polishSpecialCharactersB = "aąbcćdeęfghijklłmnńoóprsśtuwyzźż"; |
25
|
|
|
protected $cyrillicCharactersA = "Аа Бб Вв Гг Дд Ее Жж Зз Ии Йй Кк Лл Мм Нн"; |
26
|
|
|
protected $cyrillicCharactersB = "Оо Пп Рр Сс Тт Уу Фф Хх Цц Чч Шш Щщ Ьь Юю Яя"; |
27
|
|
|
protected $cyrillicCharactersB_Output = "Оо ПпРр Сс Тт Уу Фф Хх Цц Чч Шш Щщ Ьь Юю Яя"; |
28
|
|
|
protected $arabic = "غ ظ ض ذ خ ث ت ش ر ق ص ف ع س ن م ل ك ي ط ح ز و ه د ج ب ا"; |
29
|
|
|
protected $chineseTraditionalA = "電 買 車 紅 無 東 馬 風 時 鳥 語 頭 魚 園 長 島 愛 紙 書 見 假 佛 德 拜 黑 冰 兔 妒 每 壤 步"; |
30
|
|
|
protected $chineseTraditionalB = "巢 惠 鞋 莓 圓 聽 實 證 龍 賣 龜 藝 戰 繩 關 鐵 圖 團 轉 廣 惡 豐 腦 雜 壓 雞 價 樂 氣 廳 發"; |
31
|
|
|
protected $chineseTraditionalC = "勞 劍 歲 權 燒 贊 兩 譯 觀 營 處 齒 驛 櫻 產 藥 讀 顏 聲 學 體 點 麥 蟲 舊 會 萬 盜 寶 國 醫"; |
32
|
|
|
protected $chineseTraditionalD = "雙 晝 觸 來 畫 黃 區"; |
33
|
|
|
protected $chineseSimplifiedA = "电 买 车 红 无 东 马 风 时 鸟 语 头 鱼 园 长 岛 爱 纸 书 见 假 佛 德 拜 黑 冰 兔 妒 每 壤"; |
34
|
|
|
protected $chineseSimplifiedB = "步 巢 惠 鞋 莓 圆 听 实 证 龙 卖 龟 艺 战 绳 关 铁 图 团 转 广 恶 丰 脑 杂 压 鸡 价 乐 气"; |
35
|
|
|
protected $chineseSimplifiedC = "厅 发 劳 剑 岁 权 烧 赞 两 译 观 营 处 齿 驿 樱 产 药 读 颜 声 学 体 点 麦 虫 旧 会 万 盗"; |
36
|
|
|
protected $chineseSimplifiedD = "宝 国 医 双 昼 触 来 画 黄 区"; |
37
|
|
|
protected $testArray = []; |
38
|
|
|
private $security; |
39
|
|
|
private $sanitise; |
40
|
|
|
|
41
|
|
|
function __construct($name = null, array $data = [], $dataName = '') |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
parent::__construct($name, $data, $dataName); |
44
|
|
|
$this->security = new SoteriaService(); |
45
|
|
|
|
46
|
|
|
$this->sanitise = $this->security->sanitise(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
function testArrayStringFilter() |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
$equalsArray = [ |
52
|
|
|
//Character Sets |
53
|
|
|
[$this->numbers, $this->numbers], |
54
|
|
|
[$this->latinAlphabet, $this->latinAlphabet], |
55
|
|
|
[$this->latinAlphabet . $this->numbers, $this->latinAlphabet . $this->numbers], |
56
|
|
|
[$this->germanSpecialCharacters, $this->germanSpecialCharacters], |
57
|
|
|
[$this->frenchSpecialCharacters, $this->frenchSpecialCharacters], |
58
|
|
|
[$this->dutchSpecialCharacters, $this->dutchSpecialCharacters], |
59
|
|
|
[$this->spanishSpecialCharacters, $this->spanishSpecialCharacters], |
60
|
|
|
[$this->scandinavianSpecialCharactersA, $this->scandinavianSpecialCharactersA], |
61
|
|
|
[$this->scandinavianSpecialCharactersB, $this->scandinavianSpecialCharactersB], |
62
|
|
|
[$this->irishSpecialCharacters, $this->irishSpecialCharacters], |
63
|
|
|
[$this->cyrillicCharactersA, $this->cyrillicCharactersA], |
64
|
|
|
[$this->cyrillicCharactersB_Output, $this->cyrillicCharactersB], |
65
|
|
|
[$this->arabic, $this->arabic], |
66
|
|
|
[$this->chineseTraditionalA, $this->chineseTraditionalA], |
67
|
|
|
[$this->chineseTraditionalB, $this->chineseTraditionalB], |
68
|
|
|
[$this->chineseTraditionalC, $this->chineseTraditionalC], |
69
|
|
|
[$this->chineseTraditionalD, $this->chineseTraditionalD], |
70
|
|
|
[$this->chineseSimplifiedA, $this->chineseSimplifiedA], |
71
|
|
|
[$this->chineseSimplifiedB, $this->chineseSimplifiedB], |
72
|
|
|
[$this->chineseSimplifiedC, $this->chineseSimplifiedC], |
73
|
|
|
[$this->chineseSimplifiedD, $this->chineseSimplifiedD], |
74
|
|
|
//Known Cases |
75
|
|
|
['!"£$%^&*()_+{}:@~?¬|', $this->specialCharactersA], |
76
|
|
|
["`-=[];'#,./`", $this->specialCharactersB], |
77
|
|
|
["O'Neil", "O\'Neil"], |
78
|
|
|
["O'Neil", "O\\\'Neil"], |
79
|
|
|
["c/o Department", "c/o Department"], |
80
|
|
|
//HTML |
81
|
|
|
["testing", '<a href="http://www.google.co.uk">testing</a>'] |
82
|
|
|
]; |
83
|
|
|
|
84
|
|
|
foreach ($equalsArray as $arr) { |
85
|
|
|
$this->sanitise->disinfect($arr[1],'string'); |
86
|
|
|
$this->assertEquals($arr[0], $this->sanitise->result()->getOutput()); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
// |
90
|
|
|
function testArraySpecialFilter() |
|
|
|
|
91
|
|
|
{ |
92
|
|
|
$equalsArray = [ |
93
|
|
|
//Character Sets |
94
|
|
|
[$this->numbers, $this->numbers], |
95
|
|
|
[$this->latinAlphabet, $this->latinAlphabet], |
96
|
|
|
[$this->latinAlphabet . $this->numbers, $this->latinAlphabet . $this->numbers], |
97
|
|
|
|
98
|
|
|
//Known Cases |
99
|
|
|
['!"£$%^&*()_+{}:@~?¬|', $this->specialCharactersA], |
100
|
|
|
["`-=[];'#,./`", $this->specialCharactersB], |
101
|
|
|
["O'Neil", "O\'Neil"], |
102
|
|
|
["O'Neil", "O\\\'Neil"], |
103
|
|
|
["c/o Department", "c/o Department"], |
104
|
|
|
//HTML |
105
|
|
|
["testing", '<a href="http://www.google.co.uk">testing</a>'] |
106
|
|
|
]; |
107
|
|
|
|
108
|
|
|
foreach ($equalsArray as $arr) { |
109
|
|
|
|
110
|
|
|
$this->sanitise->disinfect($arr[1],'string'); |
111
|
|
|
$this->assertEquals($arr[0], $this->sanitise->result()->getOutput()); |
112
|
|
|
|
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
// |
116
|
|
|
function testArrayUrlFilter() |
|
|
|
|
117
|
|
|
{ |
118
|
|
|
$equalsArray = [ |
119
|
|
|
//Character Sets |
120
|
|
|
["c/o Department", "c/o Department"], |
121
|
|
|
//HTML |
122
|
|
|
["testing", '<a href="http://www.google.co.uk">testing</a>'] |
123
|
|
|
]; |
124
|
|
|
|
125
|
|
|
foreach ($equalsArray as $arr) { |
126
|
|
|
$this->sanitise->disinfect($arr[1],'string'); |
127
|
|
|
$this->assertEquals($arr[0], $this->sanitise->result()->getOutput()); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
|
132
|
|
|
} |
133
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.