This repository was archived by the owner on Feb 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringUtilsTest.php
More file actions
75 lines (54 loc) · 3.84 KB
/
StringUtilsTest.php
File metadata and controls
75 lines (54 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace uzgent\StringUtils;
require_once "AnnotationParser.php";
$stringUtils = new AnnotationParser();
list($warnings, $listeners) = $stringUtils->getListenersFromAnot("@TOLOWER", ["field_name" => "sourceField"], "@TOLOWER", [], [], []);
//Expect a warning because there is no "=" part.
assert(count($warnings) > 0);
list($warnings, $listeners) = $stringUtils->getListenersFromAnot("@TOLOWER=myupper", ["field_name" => "sourceField"], "@TOLOWER", [], [], []);
assert(count($listeners) > 0);
list($warnings, $listeners) = $stringUtils->getListenersFromAnot("@TOLOWER=myupper", ["field_name" => "sourceField"], "@TOLOWER", [], [], []);
assert(count($listeners) > 0);
list($warnings, $listeners) = $stringUtils->getListenersFromAnot("@SUBSTR=mysubstr, 1, 5", ["field_name" => "sourceField"], "@SUBSTR", [], [], ["mysubstr"]);
assert(count($warnings) == 0);
assert(count($listeners) > 0);
list($warnings, $listeners) = $stringUtils->getListenersFromAnot("@SUBSTR=mysubstr, 1, 5", ["field_name" => "sourceField"], "@SUBSTR", [], [], ["wrong"]);
assert(count($warnings) == 1);
assert(count($listeners) == 0);
list($warnings, $listeners) = $stringUtils->getListenersFromAnot("@SUBSTR=mysubstr, 1", ["field_name" => "sourceField"], "@SUBSTR", [], [], ["mysubstr"]);
assert(count($warnings) == 1);
assert(count($listeners) == 0);
list($warnings, $listeners) = $stringUtils->getListenersFromAnot("@RIGHT=mysubstr, 1", ["field_name" => "sourceField"], "@RIGHT", [], [], ["mysubstr"]);
assert(count($warnings) == 0);
assert(count($listeners) == 1);
list($warnings, $listeners) = $stringUtils->getListenersFromAnot("@RIGHT=mysubstr, 1,4", ["field_name" => "sourceField"], "@RIGHT", [], [], ["mysubstr"]);
assert(count($warnings) == 1);
assert(count($listeners) == 0);
list($warnings, $listeners) = $stringUtils->getListenersFromAnot("@LEFT=mysubstr, 1", ["field_name" => "sourceField"], "@LEFT", [], [], ["mysubstr"]);
assert(count($warnings) == 0);
assert(count($listeners) == 1);
list($warnings, $listeners) = $stringUtils->getListenersFromAnot("@LEFT=mysubstr", ["field_name" => "sourceField"], "@LEFT", [], [], ["mysubstr"]);
assert(count($warnings) == 1);
assert(count($listeners) == 0);
list($warnings, $listeners) = $stringUtils->getListenersFromAnot("@CONCAT=str1, str2, str3", ["field_name" => "sourceField"], "@CONCAT", [], [], ["mysubstr"]);
assert(count($warnings) == 3); // One error for each field.
assert(count($listeners) == 0);
list($warnings, $listeners) = $stringUtils->getListenersFromAnot("@CONCAT=str1, str2, str3", ["field_name" => "sourceField"], "@CONCAT", [], [], ["str1", "str2", "str3"]);
assert(count($warnings) == 0);
assert(count($listeners) == 3);
list($warnings, $listeners) = $stringUtils->getListenersFromAnot("@CONCAT=str1, str2, str3 @READONLY", ["field_name" => "sourceField"], "@CONCAT", [], [], ["str1", "str2", "str3"]);
assert(count($warnings) == 0);
assert(count($listeners) == 3);
list($warnings, $listeners) = $stringUtils->getListenersFromAnot("@CONCAT=img_1,url,img_2 @READONLY", ["field_name" => "sourceField"], "@CONCAT", [], [], ["img_1", "url", "img_2"]);
assert(count($warnings) == 0);
assert(count($listeners) == 3);
assert(array_key_exists("img_2", $listeners));
list($warnings, $listeners) = $stringUtils->getListenersFromAnot("@CONCAT=img_1 , url , img_2 @READONLY", ["field_name" => "sourceField"], "@CONCAT", [], [], ["img_1", "url", "img_2"]);
assert(count($warnings) == 0);
assert(count($listeners) == 3);
assert(array_key_exists("img_1", $listeners));
assert(array_key_exists("url", $listeners));
assert(array_key_exists("img_2", $listeners));
list($warnings, $listeners) = $stringUtils->getListenersFromAnot("@REPLACE=sourceField, searchvaluefield, newvaluefield", ["field_name" => "resultField"], "@REPLACE", [], [], ["resultField", "sourceField", "searchvaluefield", "newvaluefield"]);
assert(count($warnings) == 0);
assert(count($listeners) == 1);