Format = new FormatHelper(new View(null)); $this->Format->Html = new HtmlHelper(new View(null)); } /** */ public function testDisabledLink() { $content = 'xyz'; $data = array( array(), array('class' => 'disabledLink', 'title' => false), array('class' => 'helloClass', 'title' => 'helloTitle') ); foreach ($data as $key => $value) { $res = $this->Format->disabledLink($content, $value); //echo ''.$res.' (\''.h($res).'\')'; $this->assertTrue(!empty($res)); } } /** * @return void */ public function testWarning() { $content = 'xyz'; $data = array( true, false ); foreach ($data as $key => $value) { $res = $this->Format->warning($content . ' ' . (int)$value, $value); //echo ''.$res.''; $this->assertTrue(!empty($res)); } } /** * FormatHelperTest::testIcon() * * @return void */ public function testIcon() { $result = $this->Format->icon('edit'); $expected = '[' . __('Edit') . ']'; $this->assertEquals($expected, $result); } /** * FormatHelperTest::testIconWithFontIcon() * * @return void */ public function testIconWithFontIcon() { $this->Format->settings['fontIcons'] = array('edit' => 'fa fa-pencil'); $result = $this->Format->icon('edit'); $expected = ''; $this->assertEquals($expected, $result); } /** * FormatHelperTest::testSpeedOfIcons() * * @return void */ public function testSpeedOfIcons() { $count = 1000; $time1 = microtime(true); for ($i = 0; $i < $count; $i++) { $result = $this->Format->icon('edit'); } $time2 = microtime(true); $this->Format->settings['fontIcons'] = array('edit' => 'fa fa-pencil'); $time3 = microtime(true); for ($i = 0; $i < $count; $i++) { $result = $this->Format->icon('edit'); } $time4 = microtime(true); $normalIconSpeed = number_format($time2 - $time1, 2); $this->debug('Normal Icons: ' . $normalIconSpeed); $fontIconViaStringTemplateSpeed = number_format($time4 - $time3, 2); $this->debug('StringTemplate and Font Icons: ' . $fontIconViaStringTemplateSpeed); $this->assertTrue($fontIconViaStringTemplateSpeed < $normalIconSpeed); } /** * @return void */ public function testFontIcon() { $result = $this->Format->fontIcon('signin'); $expected = ''; $this->assertEquals($expected, $result); $result = $this->Format->fontIcon('signin', array('rotate' => 90)); $expected = ''; $this->assertEquals($expected, $result); $result = $this->Format->fontIcon('signin', array('size' => 5, 'extra' => array('muted'))); $expected = ''; $this->assertEquals($expected, $result); } /** */ public function testOk() { $content = 'xyz'; $data = array( true, false ); foreach ($data as $key => $value) { $res = $this->Format->ok($content . ' ' . (int)$value, $value); //echo ''.$res.''; $this->assertTrue(!empty($res)); } } public function testPriorityIcon() { $values = array( array(1, array(), '
 
'), array(2, array(), '
 
'), array(3, array(), ''), array(3, array('normal' => true), '
 
'), array(4, array(), '
 
'), array(5, array(), '
 
'), array(1, array('max' => 3), '
 
'), array(2, array('max' => 3), ''), array(2, array('max' => 3, 'normal' => true), '
 
'), array(3, array('max' => 3), '
 
'), array(0, array('max' => 3, 'map' => array(0 => 1, 1 => 2, 2 => 3)), '
 
'), array(1, array('max' => 3, 'map' => array(0 => 1, 1 => 2, 2 => 3)), ''), array(2, array('max' => 3, 'map' => array(0 => 1, 1 => 2, 2 => 3)), '
 
'), ); foreach ($values as $key => $value) { $res = $this->Format->priorityIcon($value[0], $value[1]); //echo $key; //debug($res, null, false); $this->assertEquals($value[2], $res); } } /** */ public function testShortenText() { $data = array( 'dfssdfsdj sdkfj sdkfj ksdfj sdkf ksdfj ksdfjsd kfjsdk fjsdkfj ksdjf ksdf jsdsdf', '122 jsdf sjdkf sdfj sdf', 'ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd', '\';alert(String.fromCharCode(88,83,83))//\';alert(String.fromCharCode(88,83,83))//";alert(String.fromCharCode(88,83,83))//\";alert(String.fromCharCode(88,83,83))//-->">\'>' ); foreach ($data as $key => $value) { $res = $this->Format->shortenText($value, 30); //echo '\''.h($value).'\' becomes \''.$res.'\''; $this->assertTrue(!empty($res)); } } /** */ public function testTruncate() { $data = array( 'dfssdfsdj sdkfj sdkfj ksdfj sdkf ksdfj ksdfjsd kfjsdk fjsdkfj ksdjf ksdf jsdsdf' => 'dfssdfsdj sdkfj sdkfj ksdfj s' . "\xe2\x80\xa6", '122 jsdf sjdkf sdfj sdf' => '122 jsdf sjdkf sdfj sdf', 'ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd' => 'ddddddddddddddddddddddddddddd' . "\xe2\x80\xa6", 'dsfdsf hods hfoéfh oéfhoéfhoéfhoéfhoéfhiu oéfhoéfhdüf s' => 'dsfdsf hods hfoéfh oéfhoéfhoé' . "\xe2\x80\xa6" ); foreach ($data as $value => $expected) { $res = $this->Format->truncate($value, 30, array('html' => true)); //debug( '\''.h($value).'\' becomes \''.$res.'\'', null, false); $res = $this->Format->truncate($value, 30, array('html' => true)); //debug( '\''.h($value).'\' becomes \''.$res.'\'', null, false); //$this->assertTrue(!empty($res)); $this->assertEquals($expected, $res); } } /** */ public function testHideEmail() { $mails = array( 'test@test.de' => 't..t@t..t.de', 'xx@yy.de' => 'x..x@y..y.de', 'erk-wf@ve-eeervdg.com' => 'e..f@v..g.com', ); foreach ($mails as $mail => $expected) { $res = $this->Format->hideEmail($mail); //echo '\''.$mail.'\' becomes \''.$res.'\' - expected \''.$expected.'\''; $this->assertEquals($expected, $res); } } /** */ public function testWordCensor() { $data = array( 'dfssdfsdj sdkfj sdkfj ksdfj bitch ksdfj' => 'dfssdfsdj sdkfj sdkfj ksdfj ##### ksdfj', '122 jsdf ficken Sjdkf sdfj sdf' => '122 jsdf ###### Sjdkf sdfj sdf', '122 jsdf FICKEN sjdkf sdfjs sdf' => '122 jsdf ###### sjdkf sdfjs sdf', 'dddddddddd ARSCH ddddddddddddd' => 'dddddddddd ##### ddddddddddddd', //'\';alert(String.fromCharCode(88,83,83))//\';alert(String.fromCharCode(88,83,83))//";alert(String.fromCharCode(88,83,83))//\";alert(String.fromCharCode(88,83,83))//-->">\'>' => null ); foreach ($data as $value => $expected) { $res = $this->Format->wordCensor($value, array('Arsch', 'Ficken', 'Bitch')); //debug('\''.h($value).'\' becomes \''.h($res).'\'', null, false); $this->assertEquals($expected === null ? $value : $expected, $res); } } /** */ /* public function testReverseAscii() { $is = $this->Format->reverseAscii('fés'); $expected = 'fés'; $this->assertEquals($expected, $is); $is = entDec('fés'); $expected = 'fés'; $this->assertEquals($expected, $is); $is = html_entity_decode('fés'); $expected = 'fés'; $this->assertEquals($expected, $is); #TODO: correct it + more } */ /** */ /* public function testDecodeEntities() { $is = $this->Format->decodeEntities('fés'); $expected = 'fés'; $this->assertEquals($expected, $is); } */ public function testTab2space() { //echo '

'.__FUNCTION__.'

'; $text = "foo\t\tfoobar\tbla\n"; $text .= "fooo\t\tbar\t\tbla\n"; $text .= "foooo\t\tbar\t\tbla\n"; //echo "
" . $text . "
"; //echo'becomes'; //echo "
" . $this->Format->tab2space($text) . "
"; } public function testArray2table() { //echo '

'.__FUNCTION__.'

'; $array = array( array('x' => '0', 'y' => '0.5', 'z' => '0.9'), array('1', '2', '3'), array('4', '5', '6'), ); $is = $this->Format->array2table($array); //echo $is; //$this->assertEquals($expected, $is); // recursive? $array = array( array('a' => array('2'), 'b' => array('2'), 'c' => array('2')), array(array('2'), array('2'), array('2')), array(array('2'), array('2'), array(array('s' => '3', 't' => '4'))), ); $is = $this->Format->array2table($array, array('recursive' => true)); //echo $is; } public function tearDown() { parent::tearDown(); unset($this->Format); } }