function test_omit_error() { $str = 'On January 29, 1737, Thomas Paine was born in Thetford, England. His father, a corseter, had grand visions for his son, but by the age of 12, Thomas had failed out of school. The young Paine began apprenticing for his father, but again, he failed.'; $myobj = new TextLanguageDetect(); $result = $myobj->detectSimple($str); $this->assertEquals('english', $result); // omit all languages and you should get an error $myobj->omitLanguages($myobj->getLanguages()); $result = $myobj->detectSimple($str); $this->assertNull($result, gettype($result)); }
function testOmitLanguages() { $str = 'This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE, such as 0 or "". Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.'; $myobj = new TextLanguageDetect(); $method = new \ReflectionProperty('\\TextLanguageDetect\\TextLanguageDetect', '_use_unicode_narrowing'); $method->setAccessible(TRUE); $method->setValue($myobj, false); $count = $myobj->getLanguageCount(); $returnval = $myobj->omitLanguages('english'); $newcount = $myobj->getLanguageCount(); $this->assertEquals(1, $returnval); $this->assertEquals(1, $count - $newcount); $result = strtolower($myobj->detectSimple($str)); $this->assertTrue($result != 'english', $result); $myobj = new TextLanguageDetect(); $count = $myobj->getLanguageCount(); $returnval = $myobj->omitLanguages(array('danish', 'italian'), true); $newcount = $myobj->getLanguageCount(); $this->assertEquals($count - $newcount, $returnval); $this->assertEquals($count - $returnval, $newcount); $result = strtolower($myobj->detectSimple($str)); $this->assertTrue($result == 'danish' || $result == 'italian', $result); $result = $myobj->detect($str); $this->assertEquals(2, count($result)); $this->assertTrue(isset($result['danish'])); $this->assertTrue(isset($result['italian'])); unset($myobj); }