Configurable activity and project number (#4729)

* added configurable activity number
* added configurable project number
* fix deprecations
* added some tests for entity exporter
* better configuration of dropdown pattern for customer, project and activity
This commit is contained in:
Kevin Papst
2024-04-04 17:43:22 +02:00
committed by GitHub
parent c1f5d3def4
commit a636683dee
55 changed files with 920 additions and 136 deletions

View File

@@ -472,6 +472,7 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
'billable' => 'bool',
'color' => '@string',
'customer' => 'int',
'number' => '@int',
'globalActivities' => 'bool',
'comment' => '@string',
];
@@ -485,6 +486,7 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
'billable' => 'bool',
'color' => '@string',
'customer' => ['result' => 'object', 'type' => 'Customer'],
'number' => '@int',
'globalActivities' => 'bool',
'comment' => '@string',
];
@@ -497,6 +499,7 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
'visible' => 'bool',
'billable' => 'bool',
'customer' => 'int',
'number' => '@int',
'color' => '@string',
'metaFields' => ['result' => 'array', 'type' => 'ProjectMeta'],
'parentTitle' => 'string',
@@ -515,6 +518,7 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
'visible' => 'bool',
'billable' => 'bool',
'customer' => 'int',
'number' => '@int',
'color' => '@string',
'metaFields' => ['result' => 'array', 'type' => 'ProjectMeta'],
'parentTitle' => 'string',
@@ -538,6 +542,7 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
'visible' => 'bool',
'billable' => 'bool',
'project' => '@int',
'number' => '@int',
'color' => '@string',
'comment' => '@string',
];
@@ -549,6 +554,7 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
'visible' => 'bool',
'billable' => 'bool',
'project' => ['result' => 'object', 'type' => '@ProjectExpanded'],
'number' => '@int',
'color' => '@string',
'comment' => '@string',
];
@@ -561,6 +567,7 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
'visible' => 'bool',
'billable' => 'bool',
'project' => '@int',
'number' => '@int',
'color' => '@string',
'metaFields' => ['result' => 'array', 'type' => 'ProjectMeta'],
'parentTitle' => '@string',
@@ -576,6 +583,7 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
'visible' => 'bool',
'billable' => 'bool',
'project' => '@int',
'number' => '@int',
'color' => '@string',
'metaFields' => ['result' => 'array', 'type' => 'ProjectMeta'],
'parentTitle' => '@string',

View File

@@ -19,6 +19,7 @@ use App\Event\ActivityMetaDefinitionEvent;
use App\Event\ActivityUpdatePostEvent;
use App\Event\ActivityUpdatePreEvent;
use App\Repository\ActivityRepository;
use App\Tests\Mocks\SystemConfigurationFactory;
use App\Validator\ValidationFailedException;
use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -49,7 +50,9 @@ class ActivityServiceTest extends TestCase
$validator->method('validate')->willReturn(new ConstraintViolationList());
}
$service = new ActivityService($repository, $dispatcher, $validator);
$configuration = SystemConfigurationFactory::createStub(['activity' => []]);
$service = new ActivityService($repository, $configuration, $dispatcher, $validator);
return $service;
}

View File

@@ -425,15 +425,22 @@ class ConfigurationTest extends TestCase
],
'project' => [
'copy_teams_on_create' => false,
'number_format' => '{pc,4}',
'allow_duplicate_number' => false,
'choice_pattern' => '{name}',
],
'activity' => [
'allow_inline_create' => false,
'number_format' => '{ac,4}',
'allow_duplicate_number' => false,
'choice_pattern' => '{name}',
],
'customer' => [
'number_format' => '{cc,4}',
'rules' => [
'allow_duplicate_number' => false,
],
'choice_pattern' => '{name}',
],
'features' => [
'user_registration' => false,

View File

@@ -152,6 +152,7 @@ class ActivityTest extends AbstractEntityTest
['visible', 'boolean'],
['comment', 'string'],
['billable', 'boolean'],
['activity_number', 'string'],
];
self::assertCount(\count($expected), $columns);

View File

@@ -184,6 +184,7 @@ class ProjectTest extends AbstractEntityTest
['visible', 'boolean'],
['comment', 'string'],
['billable', 'boolean'],
['project_number', 'string'],
];
self::assertCount(\count($expected), $columns);

View File

@@ -0,0 +1,75 @@
<?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\Spreadsheet;
use App\Entity\Activity;
use App\Entity\ActivityMeta;
use App\Event\ActivityMetaDisplayEvent;
use App\Export\Spreadsheet\EntityWithMetaFieldsExporter;
use App\Export\Spreadsheet\Extractor\AnnotationExtractor;
use App\Export\Spreadsheet\Extractor\MetaFieldExtractor;
use App\Export\Spreadsheet\SpreadsheetExporter;
use App\Repository\Query\ActivityQuery;
use PHPUnit\Framework\TestCase;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* @covers \App\Export\Spreadsheet\EntityWithMetaFieldsExporter
*/
class ActivityExporterTest extends TestCase
{
public function testExport(): void
{
$dispatcher = $this->createMock(EventDispatcherInterface::class);
$dispatcher->expects(self::once())->method('dispatch')->willReturnCallback(function (ActivityMetaDisplayEvent $event) {
$event->addField((new ActivityMeta())->setName('foo meta')->setIsVisible(true));
$event->addField((new ActivityMeta())->setName('hidden meta')->setIsVisible(false));
$event->addField((new ActivityMeta())->setName('bar meta')->setIsVisible(true));
return $event;
});
$spreadsheetExporter = new SpreadsheetExporter($this->createMock(TranslatorInterface::class));
$annotationExtractor = new AnnotationExtractor();
$metaFieldExtractor = new MetaFieldExtractor($dispatcher);
$activity = new Activity();
$activity->setName('test activity');
$activity->setComment('Lorem Ipsum');
$activity->setBudget(123456.7890);
$activity->setTimeBudget(1234567890);
$activity->setColor('#ababab');
$activity->setVisible(false);
$activity->setNumber('AC-0815');
$activity->setMetaField((new ActivityMeta())->setName('foo meta')->setValue('some magic')->setIsVisible(true));
$activity->setMetaField((new ActivityMeta())->setName('hidden meta')->setValue('will not be seen')->setIsVisible(false));
$activity->setMetaField((new ActivityMeta())->setName('bar meta')->setValue('is happening')->setIsVisible(true));
$sut = new EntityWithMetaFieldsExporter($spreadsheetExporter, $annotationExtractor, $metaFieldExtractor);
$spreadsheet = $sut->export(Activity::class, [$activity], new ActivityMetaDisplayEvent(new ActivityQuery(), ActivityMetaDisplayEvent::EXPORT));
$worksheet = $spreadsheet->getActiveSheet();
$i = 0;
self::assertNull($worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('test activity', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals(123456.7890, $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('=1234567890/86400', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('#ababab', $worksheet->getCell([++$i, 2])->getValue());
self::assertFalse($worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('Lorem Ipsum', $worksheet->getCell([++$i, 2])->getValue());
self::assertTrue($worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('AC-0815', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('some magic', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('is happening', $worksheet->getCell([++$i, 2])->getValue());
}
}

View File

@@ -44,18 +44,18 @@ class AnnotatedObjectExporterTest extends TestCase
$worksheet = $spreadsheet->getActiveSheet();
$i = 0;
self::assertNull($worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertEquals('test project', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertEquals('A customer', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertEquals(1234567890, $worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertEquals('', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertEquals('', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertEquals('', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertEquals(123456.7890, $worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertEquals('=1234567890/86400', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertEquals('month', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertEquals('#ababab', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertFalse($worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertEquals('Lorem Ipsum', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertNull($worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('test project', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('A customer', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals(1234567890, $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals(123456.7890, $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('=1234567890/86400', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('month', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('#ababab', $worksheet->getCell([++$i, 2])->getValue());
self::assertFalse($worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('Lorem Ipsum', $worksheet->getCell([++$i, 2])->getValue());
}
}

View File

@@ -40,7 +40,7 @@ abstract class AbstractFormatterTest extends TestCase
$worksheet = $spreadsheet->getActiveSheet();
$sut->setFormattedValue($worksheet, 1, 1, $this->getActualValue());
$cell = $worksheet->getCellByColumnAndRow(1, 1);
$cell = $worksheet->getCell([1, 1]);
$this->assertCellValue($cell);
$this->assertCellStyle($worksheet->getStyleByColumnAndRow(1, 1));
}
@@ -53,7 +53,7 @@ abstract class AbstractFormatterTest extends TestCase
$worksheet = $spreadsheet->getActiveSheet();
$sut->setFormattedValue($worksheet, 1, 1, null);
$cell = $worksheet->getCellByColumnAndRow(1, 1);
$cell = $worksheet->getCell([1, 1]);
$this->assertNullValue($cell);
}

View File

@@ -0,0 +1,88 @@
<?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\Spreadsheet;
use App\Entity\Customer;
use App\Entity\CustomerMeta;
use App\Event\CustomerMetaDisplayEvent;
use App\Export\Spreadsheet\EntityWithMetaFieldsExporter;
use App\Export\Spreadsheet\Extractor\AnnotationExtractor;
use App\Export\Spreadsheet\Extractor\MetaFieldExtractor;
use App\Export\Spreadsheet\SpreadsheetExporter;
use App\Repository\Query\CustomerQuery;
use PHPUnit\Framework\TestCase;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* @covers \App\Export\Spreadsheet\EntityWithMetaFieldsExporter
*/
class CustomerExporterTest extends TestCase
{
public function testExport(): void
{
$dispatcher = $this->createMock(EventDispatcherInterface::class);
$dispatcher->expects(self::once())->method('dispatch')->willReturnCallback(function (CustomerMetaDisplayEvent $event) {
$event->addField((new CustomerMeta())->setName('foo meta')->setIsVisible(true));
$event->addField((new CustomerMeta())->setName('hidden meta')->setIsVisible(false));
$event->addField((new CustomerMeta())->setName('bar meta')->setIsVisible(true));
return $event;
});
$spreadsheetExporter = new SpreadsheetExporter($this->createMock(TranslatorInterface::class));
$annotationExtractor = new AnnotationExtractor();
$metaFieldExtractor = new MetaFieldExtractor($dispatcher);
$customer = new Customer('test customer');
$customer->setCompany('Acme Foo');
$customer->setVatId('DE0123456789');
$customer->setComment('Lorem Ipsum');
$customer->setBudget(123456.7890);
$customer->setTimeBudget(1234567890);
$customer->setColor('#ababab');
$customer->setVisible(false);
$customer->setNumber('CU-0815');
$customer->setMetaField((new CustomerMeta())->setName('foo meta')->setValue('some magic')->setIsVisible(true));
$customer->setMetaField((new CustomerMeta())->setName('hidden meta')->setValue('will not be seen')->setIsVisible(false));
$customer->setMetaField((new CustomerMeta())->setName('bar meta')->setValue('is happening')->setIsVisible(true));
$sut = new EntityWithMetaFieldsExporter($spreadsheetExporter, $annotationExtractor, $metaFieldExtractor);
$spreadsheet = $sut->export(Customer::class, [$customer], new CustomerMetaDisplayEvent(new CustomerQuery(), CustomerMetaDisplayEvent::EXPORT));
$worksheet = $spreadsheet->getActiveSheet();
$i = 0;
self::assertNull($worksheet->getCell([++$i, 2])->getValue()); // id
self::assertEquals('test customer', $worksheet->getCell([++$i, 2])->getValue()); // name
self::assertEquals('Acme Foo', $worksheet->getCell([++$i, 2])->getValue()); // company
self::assertEquals('CU-0815', $worksheet->getCell([++$i, 2])->getValue()); // number
self::assertEquals('DE0123456789', $worksheet->getCell([++$i, 2])->getValue()); // vatId
self::assertEquals(null, $worksheet->getCell([++$i, 2])->getValue()); // address
self::assertEquals(null, $worksheet->getCell([++$i, 2])->getValue()); // contact
self::assertEquals(null, $worksheet->getCell([++$i, 2])->getValue()); // email
self::assertEquals(null, $worksheet->getCell([++$i, 2])->getValue()); // phone
self::assertEquals(null, $worksheet->getCell([++$i, 2])->getValue()); // mobile
self::assertEquals(null, $worksheet->getCell([++$i, 2])->getValue()); // fax
self::assertEquals(null, $worksheet->getCell([++$i, 2])->getValue()); // homepage
self::assertEquals(null, $worksheet->getCell([++$i, 2])->getValue()); // country
self::assertEquals('EUR', $worksheet->getCell([++$i, 2])->getValue()); // currency
self::assertEquals(null, $worksheet->getCell([++$i, 2])->getValue()); // timezone
self::assertEquals('123456.789', $worksheet->getCell([++$i, 2])->getValue()); // budget
self::assertEquals('=1234567890/86400', $worksheet->getCell([++$i, 2])->getValue()); // timeBudget
self::assertEquals(null, $worksheet->getCell([++$i, 2])->getValue()); // budgetType
self::assertEquals('#ababab', $worksheet->getCell([++$i, 2])->getValue()); // color
self::assertFalse($worksheet->getCell([++$i, 2])->getValue()); // visible
self::assertEquals('Lorem Ipsum', $worksheet->getCell([++$i, 2])->getValue()); // comment
self::assertTrue($worksheet->getCell([++$i, 2])->getValue()); // billable
self::assertEquals('some magic', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('is happening', $worksheet->getCell([++$i, 2])->getValue());
}
}

View File

@@ -51,6 +51,7 @@ class EntityWithMetaFieldsExporterTest extends TestCase
$project->setTimeBudget(1234567890);
$project->setColor('#ababab');
$project->setVisible(false);
$project->setNumber('PRJ-0815');
$project->setMetaField((new ProjectMeta())->setName('foo meta')->setValue('some magic')->setIsVisible(true));
$project->setMetaField((new ProjectMeta())->setName('hidden meta')->setValue('will not be seen')->setIsVisible(false));
$project->setMetaField((new ProjectMeta())->setName('bar meta')->setValue('is happening')->setIsVisible(true));
@@ -60,21 +61,22 @@ class EntityWithMetaFieldsExporterTest extends TestCase
$worksheet = $spreadsheet->getActiveSheet();
$i = 0;
self::assertNull($worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertEquals('test project', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertEquals('A customer', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertEquals(1234567890, $worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertEquals('', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertEquals('', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertEquals('', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertEquals(123456.7890, $worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertEquals('=1234567890/86400', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertEquals('', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertEquals('#ababab', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertFalse($worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertEquals('Lorem Ipsum', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertTrue($worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertEquals('some magic', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertEquals('is happening', $worksheet->getCellByColumnAndRow(++$i, 2)->getValue());
self::assertNull($worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('test project', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('A customer', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals(1234567890, $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals(123456.7890, $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('=1234567890/86400', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('#ababab', $worksheet->getCell([++$i, 2])->getValue());
self::assertFalse($worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('Lorem Ipsum', $worksheet->getCell([++$i, 2])->getValue());
self::assertTrue($worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('PRJ-0815', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('some magic', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('is happening', $worksheet->getCell([++$i, 2])->getValue());
}
}

View File

@@ -0,0 +1,82 @@
<?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\Spreadsheet;
use App\Entity\Customer;
use App\Entity\Project;
use App\Entity\ProjectMeta;
use App\Event\ProjectMetaDisplayEvent;
use App\Export\Spreadsheet\EntityWithMetaFieldsExporter;
use App\Export\Spreadsheet\Extractor\AnnotationExtractor;
use App\Export\Spreadsheet\Extractor\MetaFieldExtractor;
use App\Export\Spreadsheet\SpreadsheetExporter;
use App\Repository\Query\ProjectQuery;
use PHPUnit\Framework\TestCase;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* @covers \App\Export\Spreadsheet\EntityWithMetaFieldsExporter
*/
class ProjectExporterTest extends TestCase
{
public function testExport(): void
{
$dispatcher = $this->createMock(EventDispatcherInterface::class);
$dispatcher->expects(self::once())->method('dispatch')->willReturnCallback(function (ProjectMetaDisplayEvent $event) {
$event->addField((new ProjectMeta())->setName('foo meta')->setIsVisible(true));
$event->addField((new ProjectMeta())->setName('hidden meta')->setIsVisible(false));
$event->addField((new ProjectMeta())->setName('bar meta')->setIsVisible(true));
return $event;
});
$spreadsheetExporter = new SpreadsheetExporter($this->createMock(TranslatorInterface::class));
$annotationExtractor = new AnnotationExtractor();
$metaFieldExtractor = new MetaFieldExtractor($dispatcher);
$project = new Project();
$project->setName('test project');
$project->setCustomer(new Customer('A customer'));
$project->setComment('Lorem Ipsum');
$project->setOrderNumber('1234567890');
$project->setBudget(123456.7890);
$project->setTimeBudget(1234567890);
$project->setColor('#ababab');
$project->setVisible(false);
$project->setNumber('PRJ-0815');
$project->setMetaField((new ProjectMeta())->setName('foo meta')->setValue('some magic')->setIsVisible(true));
$project->setMetaField((new ProjectMeta())->setName('hidden meta')->setValue('will not be seen')->setIsVisible(false));
$project->setMetaField((new ProjectMeta())->setName('bar meta')->setValue('is happening')->setIsVisible(true));
$sut = new EntityWithMetaFieldsExporter($spreadsheetExporter, $annotationExtractor, $metaFieldExtractor);
$spreadsheet = $sut->export(Project::class, [$project], new ProjectMetaDisplayEvent(new ProjectQuery(), ProjectMetaDisplayEvent::EXPORT));
$worksheet = $spreadsheet->getActiveSheet();
$i = 0;
self::assertNull($worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('test project', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('A customer', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals(1234567890, $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals(123456.7890, $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('=1234567890/86400', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('#ababab', $worksheet->getCell([++$i, 2])->getValue());
self::assertFalse($worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('Lorem Ipsum', $worksheet->getCell([++$i, 2])->getValue());
self::assertTrue($worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('PRJ-0815', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('some magic', $worksheet->getCell([++$i, 2])->getValue());
self::assertEquals('is happening', $worksheet->getCell([++$i, 2])->getValue());
}
}

View File

@@ -28,13 +28,13 @@ class SpreadsheetExporterTest extends TestCase
$sut->registerCellFormatter('foo', new class() implements CellFormatterInterface {
public function setFormattedValue(Worksheet $sheet, int $column, int $row, $value): void
{
$sheet->setCellValueByColumnAndRow($column, $row, '##' . $value . '##');
$sheet->setCellValue([$column, $row], '##' . $value . '##');
}
});
$sut->registerCellFormatter('bar', new class() implements CellFormatterInterface {
public function setFormattedValue(Worksheet $sheet, int $column, int $row, $value): void
{
$sheet->setCellValueByColumnAndRow($column, $row, '~' . $value . '~');
$sheet->setCellValue([$column, $row], '~' . $value . '~');
}
});
@@ -62,8 +62,8 @@ class SpreadsheetExporterTest extends TestCase
$worksheet = $spreadsheet->getActiveSheet();
self::assertEquals('##test project##', $worksheet->getCellByColumnAndRow(1, 2)->getValue());
self::assertEquals('~test project~', $worksheet->getCellByColumnAndRow(2, 2)->getValue());
self::assertFalse($worksheet->getCellByColumnAndRow(3, 2)->getValue());
self::assertEquals('##test project##', $worksheet->getCell([1, 2])->getValue());
self::assertEquals('~test project~', $worksheet->getCell([2, 2])->getValue());
self::assertFalse($worksheet->getCell([3, 2])->getValue());
}
}

View File

@@ -48,18 +48,18 @@ class UserExporterTest extends TestCase
$spreadsheet = $sut->export([$user], new UserPreferenceDisplayEvent(UserPreferenceDisplayEvent::EXPORT));
$worksheet = $spreadsheet->getActiveSheet();
self::assertNull($worksheet->getCellByColumnAndRow(1, 2)->getValue());
self::assertEquals('test user', $worksheet->getCellByColumnAndRow(2, 2)->getValue());
self::assertEquals('Another name', $worksheet->getCellByColumnAndRow(3, 2)->getValue());
self::assertEquals('Mr. Title', $worksheet->getCellByColumnAndRow(4, 2)->getValue());
self::assertEquals('test@example.com', $worksheet->getCellByColumnAndRow(5, 2)->getValue());
self::assertEquals('', $worksheet->getCellByColumnAndRow(6, 2)->getValue());
self::assertEquals('de', $worksheet->getCellByColumnAndRow(7, 2)->getValue());
self::assertEquals('Europe/Berlin', $worksheet->getCellByColumnAndRow(8, 2)->getValue());
self::assertFalse($worksheet->getCellByColumnAndRow(9, 2)->getValue());
self::assertEquals($date->format('Y-m-d H:i'), $worksheet->getCellByColumnAndRow(10, 2)->getFormattedValue());
self::assertEquals('ROLE_TEAMLEAD;ROLE_USER', $worksheet->getCellByColumnAndRow(11, 2)->getValue());
self::assertEquals('#ececec', $worksheet->getCellByColumnAndRow(12, 2)->getValue());
self::assertEquals('F-747864', $worksheet->getCellByColumnAndRow(13, 2)->getValue());
self::assertNull($worksheet->getCell([1, 2])->getValue());
self::assertEquals('test user', $worksheet->getCell([2, 2])->getValue());
self::assertEquals('Another name', $worksheet->getCell([3, 2])->getValue());
self::assertEquals('Mr. Title', $worksheet->getCell([4, 2])->getValue());
self::assertEquals('test@example.com', $worksheet->getCell([5, 2])->getValue());
self::assertEquals('', $worksheet->getCell([6, 2])->getValue());
self::assertEquals('de', $worksheet->getCell([7, 2])->getValue());
self::assertEquals('Europe/Berlin', $worksheet->getCell([8, 2])->getValue());
self::assertFalse($worksheet->getCell([9, 2])->getValue());
self::assertEquals($date->format('Y-m-d H:i'), $worksheet->getCell([10, 2])->getFormattedValue());
self::assertEquals('ROLE_TEAMLEAD;ROLE_USER', $worksheet->getCell([11, 2])->getValue());
self::assertEquals('#ececec', $worksheet->getCell([12, 2])->getValue());
self::assertEquals('F-747864', $worksheet->getCell([13, 2])->getValue());
}
}

View File

@@ -56,7 +56,7 @@ class ProjectServiceTest extends TestCase
$configuration = SystemConfigurationFactory::createStub(['project' => ['copy_teams_on_create' => $copyTeamsOnCreate]]);
return new ProjectService($configuration, $repository, $dispatcher, $validator);
return new ProjectService($repository, $configuration, $dispatcher, $validator);
}
public function testCannotSavePersistedProjectAsNew(): void

View File

@@ -0,0 +1,49 @@
<?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\Validator\Constraints;
use App\Configuration\ConfigLoaderInterface;
use App\Repository\ActivityRepository;
use App\Tests\Mocks\SystemConfigurationFactory;
use App\Validator\Constraints\Activity as ActivityConstraint;
use App\Validator\Constraints\ActivityValidator;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
/**
* @covers \App\Validator\Constraints\Activity
* @covers \App\Validator\Constraints\ActivityValidator
* @extends ConstraintValidatorTestCase<ActivityValidator>
*/
class ActivityValidatorTest extends ConstraintValidatorTestCase
{
protected function createValidator(): ActivityValidator
{
$loader = $this->createMock(ConfigLoaderInterface::class);
$config = SystemConfigurationFactory::create($loader, []);
$repository = $this->createMock(ActivityRepository::class);
return new ActivityValidator($config, $repository);
}
public function testConstraintIsInvalid(): void
{
$this->expectException(UnexpectedTypeException::class);
$this->validator->validate('foo', new NotBlank());
}
public function testGetTargets(): void
{
$constraint = new ActivityConstraint();
self::assertEquals('class', $constraint->getTargets());
}
}

View File

@@ -0,0 +1,49 @@
<?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\Validator\Constraints;
use App\Configuration\ConfigLoaderInterface;
use App\Repository\CustomerRepository;
use App\Tests\Mocks\SystemConfigurationFactory;
use App\Validator\Constraints\Customer as CustomerConstraint;
use App\Validator\Constraints\CustomerValidator;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
/**
* @covers \App\Validator\Constraints\Customer
* @covers \App\Validator\Constraints\CustomerValidator
* @extends ConstraintValidatorTestCase<CustomerValidator>
*/
class CustomerValidatorTest extends ConstraintValidatorTestCase
{
protected function createValidator(): CustomerValidator
{
$loader = $this->createMock(ConfigLoaderInterface::class);
$config = SystemConfigurationFactory::create($loader, []);
$repository = $this->createMock(CustomerRepository::class);
return new CustomerValidator($config, $repository);
}
public function testConstraintIsInvalid(): void
{
$this->expectException(UnexpectedTypeException::class);
$this->validator->validate('foo', new NotBlank());
}
public function testGetTargets(): void
{
$constraint = new CustomerConstraint();
self::assertEquals('class', $constraint->getTargets());
}
}

View File

@@ -9,7 +9,10 @@
namespace App\Tests\Validator\Constraints;
use App\Configuration\ConfigLoaderInterface;
use App\Entity\Project;
use App\Repository\ProjectRepository;
use App\Tests\Mocks\SystemConfigurationFactory;
use App\Validator\Constraints\Project as ProjectConstraint;
use App\Validator\Constraints\ProjectValidator;
use Symfony\Component\Validator\Constraints\NotBlank;
@@ -25,7 +28,11 @@ class ProjectValidatorTest extends ConstraintValidatorTestCase
{
protected function createValidator(): ProjectValidator
{
return new ProjectValidator();
$loader = $this->createMock(ConfigLoaderInterface::class);
$config = SystemConfigurationFactory::create($loader, []);
$repository = $this->createMock(ProjectRepository::class);
return new ProjectValidator($config, $repository);
}
public function testConstraintIsInvalid(): void