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 = '';
$this->assertEquals($expected, $result);
}
/**
* FormatHelperTest::testIconWithFontIcon()
*
* @return void
*/
public function testIconWithCustomAttributes() {
$result = $this->Format->icon('edit', [], ['data-x' => 'y']);
$expected = '';
$this->assertEquals($expected, $result);
}
/**
* FormatHelperTest::testCIconWithFontIcon()
*
* @return void
*/
public function testIconWithCustomFontIcon() {
$this->Format->config('fontIcons', ['edit' => 'fax fax-pen']);
$result = $this->Format->icon('edit');
$expected = '';
$this->assertEquals($expected, $result);
}
/**
* @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' => 'myicon']);
$expected = '';
$this->assertEquals($expected, $result);
}
/**
* @return void
*/
public function testYesNo() {
$result = $this->Format->yesNo(true);
$expected = '';
$this->assertEquals($expected, $result);
$result = $this->Format->yesNo(false);
$expected = '';
$this->assertEquals($expected, $result);
$result = $this->Format->yesNo('2', ['on' => 2, 'onTitle' => 'foo']);
$expected = '';
$this->assertTextContains($expected, $result);
$result = $this->Format->yesNo('3', ['on' => 4, 'offTitle' => 'nope']);
$expected = '';
$this->assertEquals($expected, $result);
}
/**
* @return void
*/
public function testOk() {
$content = 'xyz';
$data = [
true => 'xyz 1',
false => 'xyz 0'
];
foreach ($data as $value => $expected) {
$result = $this->Format->ok($content . ' ' . (int)$value, $value);
$this->assertEquals($expected, $result);
}
}
/**
* FormatHelperTest::testThumbs()
*
* @return void
*/
public function testThumbs() {
$result = $this->Format->thumbs(1);
$expected = '';
$this->assertEquals($expected, $result);
$result = $this->Format->thumbs(0);
$expected = '';
$this->assertEquals($expected, $result);
}
/**
* FormatHelperTest::testGenderIcon()
*
* @return void
*/
public function testGenderIcon() {
$result = $this->Format->genderIcon(0);
$expected = '';
$this->assertEquals($expected, $result);
$result = $this->Format->genderIcon(1);
$expected = '';
$this->assertEquals($expected, $result);
$result = $this->Format->genderIcon(2);
$expected = '';
$this->assertEquals($expected, $result);
}
/**
* FormatHelperTest::testPad()
*
* @return void
*/
public function testPad() {
$result = $this->Format->pad('foo bär', 20, '-');
$expected = 'foo bär-------------';
$this->assertEquals($expected, $result);
$result = $this->Format->pad('foo bär', 20, '-', STR_PAD_LEFT);
$expected = '-------------foo bär';
$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->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);
}
/**
* 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);
$this->assertTextContains('', $is);
$this->assertTextContains('
', $is);
$this->assertTextContains('', $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]);
$expected = <<
| a | b | c |
|
|
|
|
|
|
|
|
|
|
|
|
TEXT;
$this->assertTextEquals($expected, $is);
$array = [
['x' => '0', 'y' => '0.5', 'z' => '0.9'],
['1', '2', '3'],
];
$options = [
'heading' => false
];
$attributes = [
'class' => 'foo',
'data-x' => 'y'
];
$is = $this->Format->array2table($array, $options, $attributes);
$this->assertTextContains('', $is);
$this->assertTextContains(' ', $is);
$this->assertTextNotContains('', $is);
}
public function tearDown() {
parent::tearDown();
unset($this->Format);
}
}
| |