Format = new FormatHelper(new View(null)); $this->Format->Html = new HtmlExtHelper(new View(null)); } /** * @return void */ public function testDisabledLink() { $content = 'xyz'; $data = [ [], ['class' => 'disabledLink', 'title' => false], ['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 = [ 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 = '[' . __d('tools', 'Edit') . ']'; $this->assertEquals($expected, $result); } /** * FormatHelperTest::testCIcon() * * @return void */ public function testCIcon() { $result = $this->Format->cIcon('edit.png'); $expected = '[' . __d('tools', 'Edit') . ']'; $this->assertEquals($expected, $result); } /** * FormatHelperTest::testIconWithFontIcon() * * @return void */ public function testIconWithFontIcon() { $this->Format->settings['fontIcons'] = ['edit' => 'fa fa-pencil']; $result = $this->Format->icon('edit'); $expected = ''; $this->assertEquals($expected, $result); } /** * FormatHelperTest::testCIconWithFontIcon() * * @return void */ public function testCIconWithFontIcon() { $this->Format->settings['fontIcons'] = ['edit' => 'fa fa-pencil']; $result = $this->Format->cIcon('edit.png'); $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'] = ['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', ['rotate' => 90]); $expected = ''; $this->assertEquals($expected, $result); $result = $this->Format->fontIcon('signin', ['size' => 5, 'extra' => ['muted']]); $expected = ''; $this->assertEquals($expected, $result); $result = $this->Format->fontIcon('signin', ['size' => 5, 'extra' => ['muted'], 'namespace' => 'icon']); $expected = ''; $this->assertEquals($expected, $result); } /** * @return void */ public function testYesNo() { $result = $this->Format->yesNo(true); $expected = ';
		$this->assertTextContains($expected, $result);

		$result = $this->Format->yesNo(false);
		$expected = 'fa fa-check', 'no' => 'fa fa-times']; $result = $this->Format->yesNo(true); $expected = ''; $this->assertEquals($expected, $result); $result = $this->Format->yesNo(false); $expected = ''; $this->assertEquals($expected, $result); } /** * @return void */ public function testOk() { $content = 'xyz'; $data = [ true, false ]; foreach ($data as $key => $value) { $res = $this->Format->ok($content . ' ' . (int)$value, $value); //echo ''.$res.''; $this->assertTrue(!empty($res)); } } /** * FormatHelperTest::testThumbs() * * @return void */ public function testThumbs() { $result = $this->Format->thumbs(1); } /** * FormatHelperTest::testGenderIcon() * * @return void */ public function testGenderIcon() { $result = $this->Format->genderIcon(); } /** * FormatHelperTest::testShowStars() * * @return void */ public function testShowStars() { $result = $this->Format->showStars(1, 3); $expected = 'assertContains($expected, $result); } /** * FormatHelperTest::testLanguageFlags() * * @return void */ public function testLanguageFlags() { $result = $this->Format->languageFlags(); $this->debug($result); } /** * FormatHelperTest::testTipHelp() * * @return void */ public function testTipHelp() { $result = $this->Format->tipHelp('foo'); $this->debug($result); $expected = 'assertContains($expected, $result); } /** * FormatHelperTest::testPad() * * @return void */ public function testPad() { $result = $this->Format->pad('foo bar', 20, '-'); $expected = 'foo bar-------------'; $this->assertEquals($expected, $result); $result = $this->Format->pad('foo bar', 20, '-', STR_PAD_LEFT); $expected = '-------------foo bar'; $this->assertEquals($expected, $result); } /** * FormatHelperTest::testOnlineIcon() * * @return void */ public function testOnlineIcon() { $result = $this->Format->onlineIcon(); $this->debug($result); $expected = 'assertContains($expected, $result); } /** * FormatHelperTest::testStatusLight() * * @return void */ public function testStatusLight() { $result = $this->Format->statusLight(); $this->debug($result); $expected = 'assertContains($expected, $result); } /** * FormatHelperTest::testProgressBar() * * @return void */ public function testProgressBar() { $result = $this->Format->progressBar(14); $this->debug($result); } /** * FormatHelperTest::testAbsolutePaginateCount() * * @return void */ public function testAbsolutePaginateCount() { $paginator = [ 'page' => 1, 'pageCount' => 3, 'count' => 25, 'limit' => 10 ]; $result = $this->Format->absolutePaginateCount($paginator, 2); $this->debug($result); $this->assertEquals(2, $result); } /** * FormatHelperTest::testSiteIcon() * * @return void */ public function testSiteIcon() { $result = $this->Format->siteIcon('http://www.example.org'); $this->debug($result); $expected = '[] prevRecord  [] nextRecord'; $this->assertEquals($expected, $result); $this->Format->settings['fontIcons'] = [ 'prev' => 'fa fa-prev', 'next' => 'fa fa-next']; $result = $this->Format->neighbors($neighbors, 'foo'); $expected = '
 prevRecord   nextRecord
'; $this->assertEquals($expected, $result); } /** * FormatHelperTest::testPriorityIcon() * * @return void */ public function testPriorityIcon() { $values = [ [1, [], '
 
'], [2, [], '
 
'], [3, [], ''], [3, ['normal' => true], '
 
'], [4, [], '
 
'], [5, [], '
 
'], [1, ['max' => 3], '
 
'], [2, ['max' => 3], ''], [2, ['max' => 3, 'normal' => true], '
 
'], [3, ['max' => 3], '
 
'], [0, ['max' => 3, 'map' => [0 => 1, 1 => 2, 2 => 3]], '
 
'], [1, ['max' => 3, 'map' => [0 => 1, 1 => 2, 2 => 3]], ''], [2, ['max' => 3, 'map' => [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); } } /** * @return void */ public function testShortenText() { $data = [ '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)); } } /** * @return void */ public function testTruncate() { $data = [ '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, ['html' => true]); //debug( '\''.h($value).'\' becomes \''.$res.'\'', null, false); $res = $this->Format->truncate($value, 30, ['html' => true]); //debug( '\''.h($value).'\' becomes \''.$res.'\'', null, false); //$this->assertTrue(!empty($res)); $this->assertEquals($expected, $res); } } /** * @return void */ public function testHideEmail() { $mails = [ '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); } } /** * @return void */ public function testWordCensor() { $data = [ '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, ['Arsch', 'Ficken', 'Bitch']); //debug('\''.h($value).'\' becomes \''.h($res).'\'', null, false); $this->assertEquals($expected === null ? $value : $expected, $res); } } /** * FormatHelperTest::testTab2space() * * @return void */ public function testTab2space() { $text = "foo\t\tfoobar\tbla\n"; $text .= "fooo\t\tbar\t\tbla\n"; $text .= "foooo\t\tbar\t\tbla\n"; $result = $this->Format->tab2space($text); //echo "
" . $text . "
"; //echo'becomes'; //echo "
" . $result . "
"; } /** * FormatHelperTest::testArray2table() * * @return void */ public function testArray2table() { $array = [ ['x' => '0', 'y' => '0.5', 'z' => '0.9'], ['1', '2', '3'], ['4', '5', '6'], ]; $is = $this->Format->array2table($array); //echo $is; //$this->assertEquals($expected, $is); // recursive? $array = [ ['a' => ['2'], 'b' => ['2'], 'c' => ['2']], [['2'], ['2'], ['2']], [['2'], ['2'], [['s' => '3', 't' => '4']]], ]; $is = $this->Format->array2table($array, ['recursive' => true]); //echo $is; } public function tearDown() { parent::tearDown(); unset($this->Format); } }