1
0
قرینه از https://github.com/matomo-org/matomo.git synced 2025-08-24 16:07:37 +00:00
Files
matomo/tests/PHPUnit/Unit/TwigTest.php
Stefan Giehl 993d6c3fd9 Prevent automated linking in emails (#23248)
* Prevent automated linking in emails

* prevent linking on some more elements

* add some tests

---------

Co-authored-by: caddoo <1169490+caddoo@users.noreply.github.com>
2025-04-28 20:07:54 +12:00

66 خطوط
1.7 KiB
PHP

<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Tests\Unit;
use Piwik\Twig;
require_once(PIWIK_INCLUDE_PATH . '/core/Twig.php');
/**
* @group Twig
*/
class TwigTest extends \PHPUnit\Framework\TestCase
{
/**
* @dataProvider getTruncateTests
*/
public function testPiwikFilterTruncate($in, $size, $out)
{
$truncated = \Piwik\piwik_filter_truncate($in, $size);
$this->assertEquals($out, $truncated);
}
public function getTruncateTests()
{
return [
['abc', 4, 'abc'],
['abc&quot;', 4, 'abc&quot;'],
['abc&nbsp;', 4, 'abc&nbsp;'],
['abcdef', 3, 'abc...'],
['ab&amp;ef', 3, 'ab&amp;...'],
['some&#9660;thing', 5, 'some&#9660;...'],
['ab&ef ;', 3, 'ab&...'],
['&lt;&gt;&#9660;&nbsp;', 4, '&lt;&gt;&#9660;&nbsp;']
];
}
/**
* @dataProvider getPreventLinkingTests
*/
public function testFilterPreventLinking($in, $out)
{
$twig = new Twig();
$preventFilter = $twig->getTwigEnvironment()->getFilter('preventLinking');
$this->assertEquals($out, $preventFilter->getCallable()($in));
}
public function getPreventLinkingTests(): iterable
{
return [
['abc<!$%&', 'abc<!$%&'],
['abc...', 'abc...'],
['abc. test;', 'abc. test;'],
['abc.fgh', 'abc.<!-- -->fgh'],
['www.google.com', 'www.<!-- -->google.<!-- -->com'],
['www..google.com', 'www..google.<!-- -->com'],
];
}
}