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