configurable csv/xlsx export templates (#5531)
This commit is contained in:
30
tests/Mocks/Export/CsvRendererFactoryMock.php
Normal file
30
tests/Mocks/Export/CsvRendererFactoryMock.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?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\Mocks\Export;
|
||||
|
||||
use App\Export\Renderer\CsvRendererFactory;
|
||||
use App\Tests\Mocks\AbstractMockFactory;
|
||||
use Psr\EventDispatcher\EventDispatcherInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class CsvRendererFactoryMock extends AbstractMockFactory
|
||||
{
|
||||
public function create(): CsvRendererFactory
|
||||
{
|
||||
return new CsvRendererFactory(
|
||||
$this->createMock(EventDispatcherInterface::class),
|
||||
$this->createMock(Security::class),
|
||||
$this->createMock(TranslatorInterface::class),
|
||||
$this->createMock(LoggerInterface::class),
|
||||
);
|
||||
}
|
||||
}
|
||||
30
tests/Mocks/Export/XlsxRendererFactoryMock.php
Normal file
30
tests/Mocks/Export/XlsxRendererFactoryMock.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?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\Mocks\Export;
|
||||
|
||||
use App\Export\Renderer\XlsxRendererFactory;
|
||||
use App\Tests\Mocks\AbstractMockFactory;
|
||||
use Psr\EventDispatcher\EventDispatcherInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class XlsxRendererFactoryMock extends AbstractMockFactory
|
||||
{
|
||||
public function create(): XlsxRendererFactory
|
||||
{
|
||||
return new XlsxRendererFactory(
|
||||
$this->createMock(EventDispatcherInterface::class),
|
||||
$this->createMock(Security::class),
|
||||
$this->createMock(TranslatorInterface::class),
|
||||
$this->createMock(LoggerInterface::class),
|
||||
);
|
||||
}
|
||||
}
|
||||
74
tests/Mocks/MetaFieldColumnSubscriberMock.php
Normal file
74
tests/Mocks/MetaFieldColumnSubscriberMock.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?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\Mocks;
|
||||
|
||||
use App\Entity\ActivityMeta;
|
||||
use App\Entity\CustomerMeta;
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Entity\ProjectMeta;
|
||||
use App\Entity\TimesheetMeta;
|
||||
use App\Entity\UserPreference;
|
||||
use App\Event\ActivityMetaDisplayEvent;
|
||||
use App\Event\CustomerMetaDisplayEvent;
|
||||
use App\Event\ProjectMetaDisplayEvent;
|
||||
use App\Event\TimesheetMetaDisplayEvent;
|
||||
use App\Event\UserPreferenceDisplayEvent;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
|
||||
class MetaFieldColumnSubscriberMock implements EventSubscriberInterface
|
||||
{
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
TimesheetMetaDisplayEvent::class => ['loadTimesheetField', 200],
|
||||
CustomerMetaDisplayEvent::class => ['loadCustomerField', 200],
|
||||
ProjectMetaDisplayEvent::class => ['loadProjectField', 200],
|
||||
ActivityMetaDisplayEvent::class => ['loadActivityField', 200],
|
||||
UserPreferenceDisplayEvent::class => ['loadUserField', 200],
|
||||
];
|
||||
}
|
||||
|
||||
public function loadTimesheetField(TimesheetMetaDisplayEvent $event): void
|
||||
{
|
||||
$event->addField($this->prepareEntity(new TimesheetMeta(), 'foo'));
|
||||
$event->addField($this->prepareEntity(new TimesheetMeta(), 'foo2'));
|
||||
}
|
||||
|
||||
public function loadCustomerField(CustomerMetaDisplayEvent $event): void
|
||||
{
|
||||
$event->addField($this->prepareEntity(new CustomerMeta(), 'customer-foo'));
|
||||
}
|
||||
|
||||
public function loadProjectField(ProjectMetaDisplayEvent $event): void
|
||||
{
|
||||
$event->addField($this->prepareEntity(new ProjectMeta(), 'project-foo'));
|
||||
$event->addField($this->prepareEntity(new ProjectMeta(), 'project-foo2')->setIsVisible(false));
|
||||
}
|
||||
|
||||
public function loadActivityField(ActivityMetaDisplayEvent $event): void
|
||||
{
|
||||
$event->addField($this->prepareEntity(new ActivityMeta(), 'activity-foo'));
|
||||
}
|
||||
|
||||
public function loadUserField(UserPreferenceDisplayEvent $event): void
|
||||
{
|
||||
$event->addPreference(new UserPreference('mypref', 'hello world'));
|
||||
}
|
||||
|
||||
private function prepareEntity(MetaTableTypeInterface $meta, string $name): MetaTableTypeInterface
|
||||
{
|
||||
return $meta
|
||||
->setLabel('Working place')
|
||||
->setName($name)
|
||||
->setType(TextType::class)
|
||||
->setIsVisible(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user