mirror of
https://github.com/e107inc/e107.git
synced 2025-08-13 01:54:12 +02:00
Bbcode code optimization and test.
This commit is contained in:
79
e107_tests/tests/unit/bbcodes/bb_imgTest.php
Normal file
79
e107_tests/tests/unit/bbcodes/bb_imgTest.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* e107 website system
|
||||
*
|
||||
* Copyright (C) 2008-2020 e107 Inc (e107.org)
|
||||
* Released under the terms and conditions of the
|
||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class bb_imgTest extends \Codeception\Test\Unit
|
||||
{
|
||||
|
||||
/** @var bb_img */
|
||||
protected $bb;
|
||||
|
||||
protected function _before()
|
||||
{
|
||||
|
||||
require_once(e_CORE."bbcodes/bb_img.php");
|
||||
|
||||
try
|
||||
{
|
||||
$this->bb = $this->make('bb_img');
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
$this->assertTrue(false, "Couldn't load bb_img object");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function testToDB()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function testToHTML()
|
||||
{
|
||||
$tests = array(
|
||||
array(
|
||||
'codetext' => '{e_MEDIA_IMAGE}2020-12/5.sm.webp',
|
||||
'parm' => '',
|
||||
'expected' => '<img class="img-rounded rounded bbcode bbcode-img" src="thumb.php?src=e_MEDIA_IMAGE%2F2020-12%2F5.sm.webp&w=0&h=0" alt="5.sm.webp" />'
|
||||
),
|
||||
array(
|
||||
'codetext' => '{e_MEDIA}images/2020-12/horse.jpg',
|
||||
'parm' => 'width=300',
|
||||
'expected' => '<img class="img-rounded rounded bbcode bbcode-img" src="thumb.php?src=e_MEDIA_IMAGE%2F2020-12%2Fhorse.jpg&w=300&h=0" alt="Horse" srcset="thumb.php?src=e_MEDIA_IMAGE%2F2020-12%2Fhorse.jpg&w=600&h=0 2x" width="300" title="Horse" />'
|
||||
),
|
||||
array(
|
||||
'codetext' => '{e_MEDIA_IMAGE}2020-12/horse.jpg',
|
||||
'parm' => 'width=300',
|
||||
'expected' => '<img class="img-rounded rounded bbcode bbcode-img" src="thumb.php?src=e_MEDIA_IMAGE%2F2020-12%2Fhorse.jpg&w=300&h=0" alt="Horse" srcset="thumb.php?src=e_MEDIA_IMAGE%2F2020-12%2Fhorse.jpg&w=600&h=0 2x" width="300" title="Horse" />'
|
||||
),
|
||||
array(
|
||||
'codetext' => '{e_THEME}voux/install/gasmask.jpg',
|
||||
'parm' => 'width=300&alt=Custom',
|
||||
'expected' => "<figure>
|
||||
<img class=\"img-rounded rounded bbcode bbcode-img\" src=\"thumb.php?src=e_THEME%2Fvoux%2Finstall%2Fgasmask.jpg&w=300&h=0\" alt=\"Custom\" srcset=\"thumb.php?src=e_THEME%2Fvoux%2Finstall%2Fgasmask.jpg&w=600&h=0 2x\" width=\"300\" title=\"Custom\" /><figcaption>Custom</figcaption>
|
||||
</figure>"
|
||||
),
|
||||
);
|
||||
|
||||
foreach($tests as $var)
|
||||
{
|
||||
$result = $this->bb->toHTML($var['codetext'], $var['parm']);
|
||||
$result = preg_replace('/"([^"]*)thumb.php/','"thumb.php', $result); // remove the path before thumb.php
|
||||
|
||||
$this->assertSame($var['expected'], $result);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@@ -65,7 +65,7 @@ TMP;
|
||||
|
||||
$actual = $this->tp->toHTML($src,true);
|
||||
|
||||
$expected = "<div class='bbcode-center' style='text-align:center'><img src='".e_HTTP."e107_images/generic/blank_avatar.jpg' width='' alt='Blank Avatar' title='Blank Avatar' class='img-rounded rounded bbcode bbcode-img' /></div>";
|
||||
$expected = "<div class='bbcode-center' style='text-align:center'><img src='".e_HTTP."e107_images/generic/blank_avatar.jpg' alt='Blank Avatar' title='Blank Avatar' class='img-rounded rounded bbcode bbcode-img' /></div>";
|
||||
|
||||
$this->assertEquals($expected, $actual, "BBcode parsing failed on [img]");
|
||||
|
||||
@@ -1034,6 +1034,24 @@ while($row = $sql->fetch())
|
||||
$this->tp->setConvertToWebP(false);
|
||||
|
||||
|
||||
$tests = array(
|
||||
0 => array(
|
||||
'src' => '{e_PLUGIN}gallery/images/butterfly.jpg',
|
||||
'parms' => array('w'=>300, 'alt'=>"Custom"),
|
||||
'expected' => '<img class="img-responsive img-fluid" src="thumb.php?src=e_PLUGIN%2Fgallery%2Fimages%2Fbutterfly.jpg&w=300&h=0" alt="Custom" srcset="thumb.php?src=e_PLUGIN%2Fgallery%2Fimages%2Fbutterfly.jpg&w=600&h=0 2x" width="300" />'
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
foreach($tests as $index => $var)
|
||||
{
|
||||
$result = $this->tp->toImage($var['src'], $var['parms']);
|
||||
$result = preg_replace('/"([^"]*)thumb.php/','"thumb.php', $result);
|
||||
$this->assertSame($var['expected'], $result);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function testThumbSrcSet()
|
||||
|
Reference in New Issue
Block a user