1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-13 18:14:26 +02:00

toGlyph() additional tests, Media-Manager includes bootstrap5 when detected and backward compatibility.

This commit is contained in:
Cameron
2021-01-31 13:09:53 -08:00
parent 2dedc8719f
commit 0b1a84068f
10 changed files with 362 additions and 172 deletions

View File

@@ -207,17 +207,91 @@
}
*/
private function compileFontAwesome5Meta()
{
$raw = file_get_contents(e_WEB."lib/font-awesome/5/metadata/icons.json");
$icons = e107::unserialize($raw);
$ret = [];
$keys = array('brands' => 'fab', 'solid' => 'fas', 'regular'=> 'far');
foreach($icons as $icon => $meta)
{
foreach($meta['free'] as $type)
{
$key = $keys[$type];
$ret[$key][] = $icon;
}
}
$ret['fa5-shims'] = $this->compileFontAwesome5Shims();
return $ret;
}
private function compileFontAwesome5Shims()
{
$raw = file_get_contents(e_WEB."lib/font-awesome/5/metadata/shims.json");
$icons = e107::unserialize($raw);
$ret = [];
foreach($icons as $var)
{
$i = $var[0];
$prefix = !empty($var[1]) ? $var[1] : 'fa';
$ico = !empty($var[2]) ? $var[2] : $i ;
$ret[$i] = $prefix." fa-".$ico;
}
return $ret;
}
public function testGetGlyphs()
{
// @todo uncomment to rebuild getGlyphs() arrays for fontawesome. (requires 'metadata' folder)
// $meta = $this->compileFontAwesome5Meta();
// var_export($meta);
// $far = $this->md->getGlyphs('far');
// $this->assertSame($meta['far'], $far);
// $fas = $this->md->getGlyphs('fas');
// $this->assertSame($meta['fas'], $fas);
// $fab = $this->md->getGlyphs('fab');
// $this->assertSame($meta['fab'], $fab);
// Check that FontAwesome 5 meta arrays are up-to-date.
// FontAwesome 5
$fab = $this->md->getGlyphs('fab');
$this->assertContains('500px', $fab);
$fas = $this->md->getGlyphs('fas');
$this->assertContains('address-book', $fas);
$far = $this->md->getGlyphs('far');
$this->assertContains('arrow-alt-circle-down', $far);
// Check FontAwesome 4
$fa4 = $this->md->getGlyphs('fas');
$this->assertContains('heart', $fa4);
// Check Bootstrap 3
$result = $this->md->getGlyphs('bs3');
$this->assertEquals('adjust', $result[0]);
$this->assertEquals('zoom-out', $result[198]);
$this->assertNotEmpty($result['adjust']);
$this->assertNotEmpty($result['zoom-out']);
$result = $this->md->getGlyphs('fab');
$this->assertTrue(in_array('xbox', $result));
// Check FontAweomse 5 Shims
$fa5Shims = $this->md->getGlyphs('fa5-shims');
$this->assertArrayHasKey('glass', $fa5Shims);
$result = $this->md->getGlyphs('fas');
$this->assertTrue(in_array('check-circle', $result));
$prefixTest = $this->md->getGlyphs('fab', 'myprefix-');
$this->assertContains('myprefix-500px', $prefixTest);
}
/*

View File

@@ -1972,6 +1972,62 @@ while($row = $sql->fetch())
$result = $this->tp->toGlyph('fas-camera'); // spefific call
$this->assertSame( "<i class='fas fa-camera' ><!-- --></i> ", $result);
// test core, shims and old identifiers with FontAwesome 5 installed.
$this->tp->setFontAwesome(5);
$tests = array(
'e-database-16' => "<i class='S16 e-database-16'></i>",
'e-database-32' => "<i class='S32 e-database-32'></i>",
'fa-sun-o' => "<i class='far fa-sun' ><!-- --></i> ",
'fa-comments-o' => "<i class='far fa-comments' ><!-- --></i> ",
'fa-file-text-o' => "<i class='far fa-file-alt' ><!-- --></i> ",
'fa-bank' => "<i class='fa fa-university' ><!-- --></i> ",
'fa-warning' => "<i class='fa fa-exclamation-triangle' ><!-- --></i> ",
'glyphicon-star' => "<i class='fas fa-star' ><!-- --></i> ",
'icon-star' => "<i class='fas fa-star' ><!-- --></i> ",
'floppy-disk' => "<i class='glyphicon glyphicon-floppy-disk' ><!-- --></i> ",
'icon-user' => "<i class='fas fa-user' ><!-- --></i> ",
'user' => "<i class='fas fa-user' ><!-- --></i> ",
'flag' => "<i class='fas fa-flag' ><!-- --></i> ",
'fa-' => null,
);
foreach($tests as $icon => $expected)
{
$result = $this->tp->toGlyph($icon);
$this->assertSame($expected, $result);
}
// test core, shims and old identifiers with FontAwesome 4 installed.
$this->tp->setFontAwesome(4);
$tests = array(
'e-database-16' => "<i class='S16 e-database-16'></i>",
'e-database-32' => "<i class='S32 e-database-32'></i>",
'fa-sun-o' => "<i class='fa fa-sun-o' ><!-- --></i> ",
'fa-comments-o' => "<i class='fa fa-comments-o' ><!-- --></i> ",
'fa-file-text-o' => "<i class='fa fa-file-text-o' ><!-- --></i> ",
'fa-bank' => "<i class='fa fa-bank' ><!-- --></i> ",
'fa-warning' => "<i class='fa fa-warning' ><!-- --></i> ",
'glyphicon-star' => "<i class='fa fa-star' ><!-- --></i> ",
'icon-star' => "<i class='fa fa-star' ><!-- --></i> ",
'floppy-disk' => "<i class='glyphicon glyphicon-floppy-disk' ><!-- --></i> ",
'icon-user' => "<i class='fa fa-user' ><!-- --></i> ",
'user' => "<i class='glyphicon glyphicon-user' ><!-- --></i> ",
'flag' => "<i class='glyphicon glyphicon-flag' ><!-- --></i> ",
'fa-' => null,
);
foreach($tests as $icon => $expected)
{
$result = $this->tp->toGlyph($icon);
$this->assertSame($expected, $result, 'Input was: '.$icon);
}
}
@@ -2330,7 +2386,7 @@ Your browser does not support the audio tag.
// -----
$result = $tp->makeClickable($email, 'email', array('sub' => 'fa-envelope.glyph'));
$this->assertStringContainsString("<i class='fa fa-envelope' ><!-- --></i></a>", $result);
$this->assertStringContainsString("fa-envelope' ><!-- --></i></a>", $result);
// links standard.
$tests = array(

View File

@@ -458,7 +458,7 @@ class e_parse_shortcodeTest extends \Codeception\Test\Unit
'=extended' => '<!-- bbcode-html-start --><p><strong>Extended Body</strong></p><!-- bbcode-html-end -->',
),
'newscommentlink' => array(
': class=me' => "<a title='0 Comments' class='e-tip me' href='".e107::url('news/view/item', ['news_id'=>1, 'news_sef'=>'welcome-to-e107-me-again-x'])."'><i class='fa fa-comment' ><!-- --></i></a>"
': class=me' => "<a title='0 Comments' class='e-tip me' href='".e107::url('news/view/item', ['news_id'=>1, 'news_sef'=>'welcome-to-e107-me-again-x'])."'><i class='fas fa-comment' ><!-- --></i></a>"
),