* deactivate deprecated auto-mapping * use native month-picker with fallback on old browser * bump dependencies to new major versions * replace deprecated ARRAY column type with JSON * named arguments * nullable arguments * native lazy ghosts * update routes to use php config * disable PHP < 8.4 * use static RTL configuration * new qr code package * clear out env file * recipe updates * fix deprecations * preset new env variable if not existing * bump maria db version examples * remove deprecated api-token support * fix validator deprecations * remove timesheet category column * fix broken validator autoconfiguration * stabilize tests * fix migration syntax compatibility * fix doctrine deprecation * fix datetime format * remove constructor dependency * only include visible preferences in invoice templates * fix test container dependency * removed ProjectConstraint multi-constraint logic * allow to disable plugins in certain environments * refactor TimesheetConstraint to non-service * activate new interface methods * prevent update issues with .env * improved customer fixture * removed $user->isExportDecimal()
93 lines
3.3 KiB
PHP
93 lines
3.3 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;
|
||
|
||
use App\Entity\Customer;
|
||
use App\Entity\Project;
|
||
use App\Entity\User;
|
||
use App\Export\ExportFilename;
|
||
use App\Repository\Query\TimesheetQuery;
|
||
use PHPUnit\Framework\Attributes\CoversClass;
|
||
use PHPUnit\Framework\TestCase;
|
||
|
||
#[CoversClass(ExportFilename::class)]
|
||
class ExportFilenameTest extends TestCase
|
||
{
|
||
public function testExportFilename(): void
|
||
{
|
||
$datePrefix = date('Ymd');
|
||
|
||
$query = new TimesheetQuery();
|
||
|
||
$sut = new ExportFilename($query);
|
||
|
||
self::assertEquals($datePrefix . '-kimai-export', $sut->getFilename());
|
||
self::assertEquals($datePrefix . '-kimai-export', (string) $sut);
|
||
|
||
$customer = new Customer('foo');
|
||
$query = new TimesheetQuery();
|
||
$query->addCustomer($customer);
|
||
$sut = new ExportFilename($query);
|
||
|
||
self::assertEquals($datePrefix . '-foo', $sut->getFilename());
|
||
self::assertEquals($datePrefix . '-foo', (string) $sut);
|
||
|
||
$customer->setCompany('barß / laölala # ldksjf 123 MyAwesome GmbH');
|
||
$sut = new ExportFilename($query);
|
||
|
||
self::assertEquals($datePrefix . '-barss_laolala_ldksjf_123_MyAwesome_GmbH', $sut->getFilename());
|
||
self::assertEquals($datePrefix . '-barss_laolala_ldksjf_123_MyAwesome_GmbH', (string) $sut);
|
||
|
||
$customer->setCompany('까깨꺄꺠꺼께껴꼐꼬꽈sssss');
|
||
$sut = new ExportFilename($query);
|
||
self::assertEquals($datePrefix . '-kkakkaekkyakkyaekkeokkekkyeokkyekkokkwasssss', $sut->getFilename());
|
||
|
||
$customer->setCompany('\"#+ß.!$%&/()=?\\n=/*-+´_<>@' . "\n");
|
||
$sut = new ExportFilename($query);
|
||
self::assertEquals($datePrefix . '-ss_n_-', $sut->getFilename());
|
||
|
||
$project = new Project();
|
||
$project->setName('Demo ProjecT1');
|
||
$customer->setCompany('\"#+ß.!$%&/()=?\\n=/*-+´_<>@' . "\n");
|
||
$query->addProject($project);
|
||
|
||
$sut = new ExportFilename($query);
|
||
self::assertEquals($datePrefix . '-ss_n_--Demo_ProjecT1', $sut->getFilename());
|
||
|
||
$reflectionUser = new \ReflectionClass(User::class);
|
||
$userIdProperty = $reflectionUser->getProperty('id');
|
||
|
||
$user = new User();
|
||
$user->setUserIdentifier('ayumi');
|
||
$userIdProperty->setValue($user, 1);
|
||
$query->addUser($user);
|
||
|
||
$sut = new ExportFilename($query);
|
||
self::assertEquals($datePrefix . '-ss_n_--Demo_ProjecT1-ayumi', $sut->getFilename());
|
||
$user->setAlias('Martin Müller-Lüdenscheidt');
|
||
|
||
$sut = new ExportFilename($query);
|
||
self::assertEquals($datePrefix . '-ss_n_--Demo_ProjecT1-Martin_Muller-Ludenscheidt', $sut->getFilename());
|
||
$query->removeUser($user);
|
||
|
||
$project = new Project();
|
||
$project->setName('Project2');
|
||
$query->addProject($project);
|
||
$sut = new ExportFilename($query);
|
||
self::assertEquals($datePrefix . '-ss_n_-', $sut->getFilename());
|
||
|
||
$customer = new Customer('Customer AAAA');
|
||
$query->addCustomer($customer);
|
||
|
||
$sut = new ExportFilename($query);
|
||
self::assertEquals($datePrefix . '-kimai-export', $sut->getFilename());
|
||
}
|
||
}
|