قرینه از
https://github.com/matomo-org/matomo.git
synced 2025-08-24 16:07:37 +00:00

* Prevent automated linking in emails * prevent linking on some more elements * add some tests --------- Co-authored-by: caddoo <1169490+caddoo@users.noreply.github.com>
66 خطوط
1.7 KiB
PHP
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"', 4, 'abc"'],
|
|
['abc ', 4, 'abc '],
|
|
['abcdef', 3, 'abc...'],
|
|
['ab&ef', 3, 'ab&...'],
|
|
['some▼thing', 5, 'some▼...'],
|
|
['ab&ef ;', 3, 'ab&...'],
|
|
['<>▼ ', 4, '<>▼ ']
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @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'],
|
|
];
|
|
}
|
|
}
|