1<?php 2 3namespace Sabre\DAV; 4 5class StringUtilTest extends \PHPUnit_Framework_TestCase { 6 7 /** 8 * @dataProvider dataset 9 */ 10 function testTextMatch($haystack, $needle, $collation, $matchType, $result) { 11 12 $this->assertEquals($result, StringUtil::textMatch($haystack, $needle, $collation, $matchType)); 13 14 } 15 16 function dataset() { 17 18 return array( 19 array('FOOBAR', 'FOO', 'i;octet', 'contains', true), 20 array('FOOBAR', 'foo', 'i;octet', 'contains', false), 21 array('FÖÖBAR', 'FÖÖ', 'i;octet', 'contains', true), 22 array('FÖÖBAR', 'föö', 'i;octet', 'contains', false), 23 array('FOOBAR', 'FOOBAR', 'i;octet', 'equals', true), 24 array('FOOBAR', 'fooBAR', 'i;octet', 'equals', false), 25 array('FOOBAR', 'FOO', 'i;octet', 'starts-with', true), 26 array('FOOBAR', 'foo', 'i;octet', 'starts-with', false), 27 array('FOOBAR', 'BAR', 'i;octet', 'starts-with', false), 28 array('FOOBAR', 'bar', 'i;octet', 'starts-with', false), 29 array('FOOBAR', 'FOO', 'i;octet', 'ends-with', false), 30 array('FOOBAR', 'foo', 'i;octet', 'ends-with', false), 31 array('FOOBAR', 'BAR', 'i;octet', 'ends-with', true), 32 array('FOOBAR', 'bar', 'i;octet', 'ends-with', false), 33 34 array('FOOBAR', 'FOO', 'i;ascii-casemap', 'contains', true), 35 array('FOOBAR', 'foo', 'i;ascii-casemap', 'contains', true), 36 array('FÖÖBAR', 'FÖÖ', 'i;ascii-casemap', 'contains', true), 37 array('FÖÖBAR', 'föö', 'i;ascii-casemap', 'contains', false), 38 array('FOOBAR', 'FOOBAR', 'i;ascii-casemap', 'equals', true), 39 array('FOOBAR', 'fooBAR', 'i;ascii-casemap', 'equals', true), 40 array('FOOBAR', 'FOO', 'i;ascii-casemap', 'starts-with', true), 41 array('FOOBAR', 'foo', 'i;ascii-casemap', 'starts-with', true), 42 array('FOOBAR', 'BAR', 'i;ascii-casemap', 'starts-with', false), 43 array('FOOBAR', 'bar', 'i;ascii-casemap', 'starts-with', false), 44 array('FOOBAR', 'FOO', 'i;ascii-casemap', 'ends-with', false), 45 array('FOOBAR', 'foo', 'i;ascii-casemap', 'ends-with', false), 46 array('FOOBAR', 'BAR', 'i;ascii-casemap', 'ends-with', true), 47 array('FOOBAR', 'bar', 'i;ascii-casemap', 'ends-with', true), 48 49 array('FOOBAR', 'FOO', 'i;unicode-casemap', 'contains', true), 50 array('FOOBAR', 'foo', 'i;unicode-casemap', 'contains', true), 51 array('FÖÖBAR', 'FÖÖ', 'i;unicode-casemap', 'contains', true), 52 array('FÖÖBAR', 'föö', 'i;unicode-casemap', 'contains', true), 53 array('FOOBAR', 'FOOBAR', 'i;unicode-casemap', 'equals', true), 54 array('FOOBAR', 'fooBAR', 'i;unicode-casemap', 'equals', true), 55 array('FOOBAR', 'FOO', 'i;unicode-casemap', 'starts-with', true), 56 array('FOOBAR', 'foo', 'i;unicode-casemap', 'starts-with', true), 57 array('FOOBAR', 'BAR', 'i;unicode-casemap', 'starts-with', false), 58 array('FOOBAR', 'bar', 'i;unicode-casemap', 'starts-with', false), 59 array('FOOBAR', 'FOO', 'i;unicode-casemap', 'ends-with', false), 60 array('FOOBAR', 'foo', 'i;unicode-casemap', 'ends-with', false), 61 array('FOOBAR', 'BAR', 'i;unicode-casemap', 'ends-with', true), 62 array('FOOBAR', 'bar', 'i;unicode-casemap', 'ends-with', true), 63 ); 64 65 } 66 67 /** 68 * @expectedException Sabre\DAV\Exception\BadRequest 69 */ 70 public function testBadCollation() { 71 72 StringUtil::textMatch('foobar','foo','blabla','contains'); 73 74 } 75 76 77 /** 78 * @expectedException Sabre\DAV\Exception\BadRequest 79 */ 80 public function testBadMatchType() { 81 82 StringUtil::textMatch('foobar','foo','i;octet','booh'); 83 84 } 85 86 public function testEnsureUTF8_ascii() { 87 88 $inputString = "harkema"; 89 $outputString = "harkema"; 90 91 $this->assertEquals( 92 $outputString, 93 StringUtil::ensureUTF8($inputString) 94 ); 95 96 } 97 98 public function testEnsureUTF8_latin1() { 99 100 $inputString = "m\xfcnster"; 101 $outputString = "münster"; 102 103 $this->assertEquals( 104 $outputString, 105 StringUtil::ensureUTF8($inputString) 106 ); 107 108 } 109 110 public function testEnsureUTF8_utf8() { 111 112 $inputString = "m\xc3\xbcnster"; 113 $outputString = "münster"; 114 115 $this->assertEquals( 116 $outputString, 117 StringUtil::ensureUTF8($inputString) 118 ); 119 120 } 121 122} 123