Format = new FormatHelper(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->config('fontIcons', ['edit' => 'fa fa-pencil']); $result = $this->Format->icon('edit'); $expected = ''; $this->assertEquals($expected, $result); } /** * FormatHelperTest::testCIconWithFontIcon() * * @return void */ public function testCIconWithFontIcon() { $this->Format->config('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->config('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); $this->assertNotEmpty($result); } /** * FormatHelperTest::testGenderIcon() * * @return void */ public function testGenderIcon() { $result = $this->Format->genderIcon(); $this->assertNotEmpty($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::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->config('fontIcons', [ 'prev' => 'fa fa-prev', 'next' => 'fa fa-next']); $result = $this->Format->neighbors($neighbors, 'foo'); $expected = '
 prevRecord   nextRecord
'; $this->assertEquals($expected, $result); } /** * 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); } }