ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
StringUtilTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\DAV;
4 
6 
17  function testTextMatch($haystack, $needle, $collation, $matchType, $result) {
18 
19  $this->assertEquals($result, StringUtil::textMatch($haystack, $needle, $collation, $matchType));
20 
21  }
22 
23  function dataset() {
24 
25  return [
26  ['FOOBAR', 'FOO', 'i;octet', 'contains', true],
27  ['FOOBAR', 'foo', 'i;octet', 'contains', false],
28  ['FÖÖBAR', 'FÖÖ', 'i;octet', 'contains', true],
29  ['FÖÖBAR', 'föö', 'i;octet', 'contains', false],
30  ['FOOBAR', 'FOOBAR', 'i;octet', 'equals', true],
31  ['FOOBAR', 'fooBAR', 'i;octet', 'equals', false],
32  ['FOOBAR', 'FOO', 'i;octet', 'starts-with', true],
33  ['FOOBAR', 'foo', 'i;octet', 'starts-with', false],
34  ['FOOBAR', 'BAR', 'i;octet', 'starts-with', false],
35  ['FOOBAR', 'bar', 'i;octet', 'starts-with', false],
36  ['FOOBAR', 'FOO', 'i;octet', 'ends-with', false],
37  ['FOOBAR', 'foo', 'i;octet', 'ends-with', false],
38  ['FOOBAR', 'BAR', 'i;octet', 'ends-with', true],
39  ['FOOBAR', 'bar', 'i;octet', 'ends-with', false],
40 
41  ['FOOBAR', 'FOO', 'i;ascii-casemap', 'contains', true],
42  ['FOOBAR', 'foo', 'i;ascii-casemap', 'contains', true],
43  ['FÖÖBAR', 'FÖÖ', 'i;ascii-casemap', 'contains', true],
44  ['FÖÖBAR', 'föö', 'i;ascii-casemap', 'contains', false],
45  ['FOOBAR', 'FOOBAR', 'i;ascii-casemap', 'equals', true],
46  ['FOOBAR', 'fooBAR', 'i;ascii-casemap', 'equals', true],
47  ['FOOBAR', 'FOO', 'i;ascii-casemap', 'starts-with', true],
48  ['FOOBAR', 'foo', 'i;ascii-casemap', 'starts-with', true],
49  ['FOOBAR', 'BAR', 'i;ascii-casemap', 'starts-with', false],
50  ['FOOBAR', 'bar', 'i;ascii-casemap', 'starts-with', false],
51  ['FOOBAR', 'FOO', 'i;ascii-casemap', 'ends-with', false],
52  ['FOOBAR', 'foo', 'i;ascii-casemap', 'ends-with', false],
53  ['FOOBAR', 'BAR', 'i;ascii-casemap', 'ends-with', true],
54  ['FOOBAR', 'bar', 'i;ascii-casemap', 'ends-with', true],
55 
56  ['FOOBAR', 'FOO', 'i;unicode-casemap', 'contains', true],
57  ['FOOBAR', 'foo', 'i;unicode-casemap', 'contains', true],
58  ['FÖÖBAR', 'FÖÖ', 'i;unicode-casemap', 'contains', true],
59  ['FÖÖBAR', 'föö', 'i;unicode-casemap', 'contains', true],
60  ['FOOBAR', 'FOOBAR', 'i;unicode-casemap', 'equals', true],
61  ['FOOBAR', 'fooBAR', 'i;unicode-casemap', 'equals', true],
62  ['FOOBAR', 'FOO', 'i;unicode-casemap', 'starts-with', true],
63  ['FOOBAR', 'foo', 'i;unicode-casemap', 'starts-with', true],
64  ['FOOBAR', 'BAR', 'i;unicode-casemap', 'starts-with', false],
65  ['FOOBAR', 'bar', 'i;unicode-casemap', 'starts-with', false],
66  ['FOOBAR', 'FOO', 'i;unicode-casemap', 'ends-with', false],
67  ['FOOBAR', 'foo', 'i;unicode-casemap', 'ends-with', false],
68  ['FOOBAR', 'BAR', 'i;unicode-casemap', 'ends-with', true],
69  ['FOOBAR', 'bar', 'i;unicode-casemap', 'ends-with', true],
70  ];
71 
72  }
73 
77  function testBadCollation() {
78 
79  StringUtil::textMatch('foobar', 'foo', 'blabla', 'contains');
80 
81  }
82 
83 
87  function testBadMatchType() {
88 
89  StringUtil::textMatch('foobar', 'foo', 'i;octet', 'booh');
90 
91  }
92 
93  function testEnsureUTF8_ascii() {
94 
95  $inputString = "harkema";
96  $outputString = "harkema";
97 
98  $this->assertEquals(
99  $outputString,
100  StringUtil::ensureUTF8($inputString)
101  );
102 
103  }
104 
106 
107  $inputString = "m\xfcnster";
108  $outputString = "münster";
109 
110  $this->assertEquals(
111  $outputString,
112  StringUtil::ensureUTF8($inputString)
113  );
114 
115  }
116 
117  function testEnsureUTF8_utf8() {
118 
119  $inputString = "m\xc3\xbcnster";
120  $outputString = "münster";
121 
122  $this->assertEquals(
123  $outputString,
124  StringUtil::ensureUTF8($inputString)
125  );
126 
127  }
128 
129 }
$result
static ensureUTF8($input)
This method takes an input string, checks if it&#39;s not valid UTF-8 and attempts to convert it to UTF-8...
Definition: StringUtil.php:79
static textMatch($haystack, $needle, $collation, $matchType='contains')
Checks if a needle occurs in a haystack ;)
Definition: StringUtil.php:27
testTextMatch($haystack, $needle, $collation, $matchType, $result)