0
0
Fork 0
mirror of https://github.com/kevinpapst/kimai2.git synced 2025-01-11 11:58:10 +00:00
kevinpapst_kimai2/tests/Export/Package/CellFormatter/TextFormatterTest.php

59 lines
1.8 KiB
PHP

<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Tests\Export\Package\CellFormatter;
use App\Export\Package\CellFormatter\TextFormatter;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Export\Package\CellFormatter\TextFormatter
*/
class TextFormatterTest extends TestCase
{
public function testFormatValueReturnsSanitizedStringWhenSanitizeDdeIsTrue(): void
{
$formatter = new TextFormatter(true);
$result = $formatter->formatValue('=cmd|\' /C calc\'!A0');
self::assertEquals('\' =cmd|\' /C calc\'!A0', $result);
}
public function testFormatValueReturnsOriginalStringWhenSanitizeDdeIsFalse(): void
{
$formatter = new TextFormatter(false);
$result = $formatter->formatValue('=cmd|\' /C calc\'!A0');
self::assertEquals('=cmd|\' /C calc\'!A0', $result);
}
public function testFormatValueReturnsOriginalValueForNonStringWhenSanitizeDdeIsTrue(): void
{
$formatter = new TextFormatter(true);
$result = $formatter->formatValue(123);
self::assertEquals(123, $result);
$result = $formatter->formatValue(45.67);
self::assertEquals(45.67, $result);
$result = $formatter->formatValue(true);
self::assertTrue($result);
}
public function testFormatValueReturnsOriginalValueForNonStringWhenSanitizeDdeIsFalse(): void
{
$formatter = new TextFormatter(false);
$result = $formatter->formatValue(123);
self::assertEquals(123, $result);
$result = $formatter->formatValue(45.67);
self::assertEquals(45.67, $result);
$result = $formatter->formatValue(true);
self::assertTrue($result);
}
}