Example #1
0
 function test_load()
 {
     $ts = new MyTextSanitizer();
     $instance = new $this->myclass($ts);
     $this->assertInstanceOf($this->myclass, $instance);
     $censorConf = null;
     $xoops = Xoops::getInstance();
     if (!isset($censorConf)) {
         $censorConf = $xoops->getConfigs();
         $config = $ts->loadConfig(dirname(__FILE__));
         //merge and allow config override
         $censorConf = array_merge($censorConf, $config);
     }
     $censorConf['censor_enable'] = 0;
     $text = 'text';
     $value = $instance->load($ts, $text, $censorConf);
     $this->assertSame($text, $value);
     $censorConf['censor_enable'] = 1;
     $censorConf['censor_words'] = null;
     $text = 'text';
     $value = $instance->load($ts, $text, $censorConf);
     $this->assertSame($text, $value);
     $censorConf['censor_enable'] = 1;
     $censorConf['censor_words'] = array('shit', 'f**k');
     $text = 'text';
     $value = $instance->load($ts, $text, $censorConf);
     $this->assertSame($text, $value);
     $censorConf['censor_enable'] = 1;
     $censorConf['censor_words'] = array('shit', 'f**k');
     $censorConf['censor_admin'] = 1;
     $text = 'text';
     $value = $instance->load($ts, $text, $censorConf);
     $this->assertSame($text, $value);
     $censorConf['censor_enable'] = 1;
     $censorConf['censor_words'] = array('shit', 'f**k');
     $censorConf['censor_admin'] = 0;
     $replacement = empty($censorConf['censor_replace']) ? '##censor##' : $censorConf['censor_replace'];
     $text = 'text with f**k and shit and f**k';
     $value = $instance->load($ts, $text, $censorConf);
     $this->assertTrue(strpos($value, 'f**k') === false);
     $this->assertTrue(strpos($value, 'shit') === false);
     $this->assertTrue(strpos($value, $replacement) !== false);
 }