public function test_compare_string_with_wildcard() { // Test case sensitive literal matches. $this->assertTrue(qtype_shortanswer_question::compare_string_with_wildcard('Frog', 'Frog', false)); $this->assertFalse(qtype_shortanswer_question::compare_string_with_wildcard('Frog', 'frog', false)); $this->assertTrue(qtype_shortanswer_question::compare_string_with_wildcard(' Frog ', 'Frog', false)); $this->assertFalse(qtype_shortanswer_question::compare_string_with_wildcard('Frogs', 'Frog', false)); // Test case insensitive literal matches. $this->assertTrue(qtype_shortanswer_question::compare_string_with_wildcard('Frog', 'frog', true)); $this->assertTrue(qtype_shortanswer_question::compare_string_with_wildcard(' FROG ', 'Frog', true)); $this->assertFalse(qtype_shortanswer_question::compare_string_with_wildcard('Frogs', 'Frog', true)); // Test case sensitive wildcard matches. $this->assertTrue(qtype_shortanswer_question::compare_string_with_wildcard('Frog', 'F*og', false)); $this->assertTrue(qtype_shortanswer_question::compare_string_with_wildcard('Fog', 'F*og', false)); $this->assertTrue(qtype_shortanswer_question::compare_string_with_wildcard(' Fat dog ', 'F*og', false)); $this->assertFalse(qtype_shortanswer_question::compare_string_with_wildcard('Frogs', 'F*og', false)); $this->assertFalse(qtype_shortanswer_question::compare_string_with_wildcard('Fg', 'F*og', false)); $this->assertFalse(qtype_shortanswer_question::compare_string_with_wildcard('frog', 'F*og', false)); $this->assertFalse(qtype_shortanswer_question::compare_string_with_wildcard(' fat dog ', 'F*og', false)); // Test case insensitive wildcard matches. $this->assertTrue(qtype_shortanswer_question::compare_string_with_wildcard('Frog', 'F*og', true)); $this->assertTrue(qtype_shortanswer_question::compare_string_with_wildcard('Fog', 'F*og', true)); $this->assertTrue(qtype_shortanswer_question::compare_string_with_wildcard(' Fat dog ', 'F*og', true)); $this->assertFalse(qtype_shortanswer_question::compare_string_with_wildcard('Frogs', 'F*og', true)); $this->assertFalse(qtype_shortanswer_question::compare_string_with_wildcard('Fg', 'F*og', true)); $this->assertTrue(qtype_shortanswer_question::compare_string_with_wildcard('frog', 'F*og', true)); $this->assertTrue(qtype_shortanswer_question::compare_string_with_wildcard(' fat dog ', 'F*og', true)); // Test match using regexp special chars. $this->assertTrue(qtype_shortanswer_question::compare_string_with_wildcard(' * ', '\\*', false)); $this->assertTrue(qtype_shortanswer_question::compare_string_with_wildcard('*', '\\*', false)); $this->assertTrue(qtype_shortanswer_question::compare_string_with_wildcard('Frog*toad', 'Frog\\*toad', false)); $this->assertFalse(qtype_shortanswer_question::compare_string_with_wildcard('a', '[a-z]', false)); $this->assertTrue(qtype_shortanswer_question::compare_string_with_wildcard('[a-z]', '[a-z]', false)); $this->assertTrue(qtype_shortanswer_question::compare_string_with_wildcard('\\{}/', '\\{}/', true)); // See http://moodle.org/mod/forum/discuss.php?d=120557 $this->assertTrue(qtype_shortanswer_question::compare_string_with_wildcard('ITÁLIE', 'Itálie', true)); }
public function test_compare_0_with_wildcard() { // Test the classic PHP problem case with '0'. $this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard( '0', '0', false)); $this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard( '0', '0*', false)); $this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard( '0', '*0', false)); $this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard( '0', '*0*', false)); }
public function test_compare_string_with_wildcard_many_stars() { // Test the classic PHP problem case with '0'. $this->assertTrue((bool) qtype_shortanswer_question::compare_string_with_wildcard('<em></em>', '***********************************<em>***********************************</em>', false)); }
public function test_compare_string_with_wildcard() { // Test case sensitive literal matches. $this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard( 'Frog', 'Frog', false)); $this->assertFalse((bool)qtype_shortanswer_question::compare_string_with_wildcard( 'Frog', 'frog', false)); $this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard( ' Frog ', 'Frog', false)); $this->assertFalse((bool)qtype_shortanswer_question::compare_string_with_wildcard( 'Frogs', 'Frog', false)); // Test case insensitive literal matches. $this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard( 'Frog', 'frog', true)); $this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard( ' FROG ', 'Frog', true)); $this->assertFalse((bool)qtype_shortanswer_question::compare_string_with_wildcard( 'Frogs', 'Frog', true)); // Test case sensitive wildcard matches. $this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard( 'Frog', 'F*og', false)); $this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard( 'Fog', 'F*og', false)); $this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard( ' Fat dog ', 'F*og', false)); $this->assertFalse((bool)qtype_shortanswer_question::compare_string_with_wildcard( 'Frogs', 'F*og', false)); $this->assertFalse((bool)qtype_shortanswer_question::compare_string_with_wildcard( 'Fg', 'F*og', false)); $this->assertFalse((bool)qtype_shortanswer_question::compare_string_with_wildcard( 'frog', 'F*og', false)); $this->assertFalse((bool)qtype_shortanswer_question::compare_string_with_wildcard( ' fat dog ', 'F*og', false)); // Test case insensitive wildcard matches. $this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard( 'Frog', 'F*og', true)); $this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard( 'Fog', 'F*og', true)); $this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard( ' Fat dog ', 'F*og', true)); $this->assertFalse((bool)qtype_shortanswer_question::compare_string_with_wildcard( 'Frogs', 'F*og', true)); $this->assertFalse((bool)qtype_shortanswer_question::compare_string_with_wildcard( 'Fg', 'F*og', true)); $this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard( 'frog', 'F*og', true)); $this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard( ' fat dog ', 'F*og', true)); // Test match using regexp special chars. $this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard( ' * ', '\*', false)); $this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard( '*', '\*', false)); $this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard( 'Frog*toad', 'Frog\*toad', false)); $this->assertFalse((bool)qtype_shortanswer_question::compare_string_with_wildcard( 'a', '[a-z]', false)); $this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard( '[a-z]', '[a-z]', false)); $this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard( '\{}/', '\{}/', true)); // See http://moodle.org/mod/forum/discuss.php?d=120557 $this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard( 'ITÁLIE', 'Itálie', true)); if (function_exists('normalizer_normalize')) { // Test ambiguous unicode representations $this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard( 'départ', 'DÉPART', true)); $this->assertFalse((bool)qtype_shortanswer_question::compare_string_with_wildcard( 'départ', 'DÉPART', false)); $this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard( 'd'."\xC3\xA9".'part', 'd'."\x65\xCC\x81".'part', false)); $this->assertTrue((bool)qtype_shortanswer_question::compare_string_with_wildcard( 'd'."\xC3\xA9".'part', 'D'."\x45\xCC\x81".'PART', true)); } }