getResponse()->getContent());
+ $option = $client->getCrawler()->filterXPath("//select[@id='user']/option[@selected]");
+ self::assertEquals(4, $option->attr('value'));
+ }
+
+ public function testUserMonthReport()
+ {
+ $client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
+ $this->importReportingFixture(User::ROLE_USER);
+ $this->assertAccessIsGranted($client, '/reporting/month_by_user?user=4&date=12999119191');
self::assertStringContainsString('
count());
}
public function testMonthlyUsersReport()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
+ $this->importReportingFixture(User::ROLE_TEAMLEAD);
$this->assertAccessIsGranted($client, '/reporting/monthly_users_list');
self::assertStringContainsString('
count());
}
}
diff --git a/tests/Entity/ActivityTest.php b/tests/Entity/ActivityTest.php
index 10dbf8fc..288ece92 100644
--- a/tests/Entity/ActivityTest.php
+++ b/tests/Entity/ActivityTest.php
@@ -9,6 +9,7 @@
namespace App\Tests\Entity;
+use App\Constants;
use App\Entity\Activity;
use App\Entity\ActivityMeta;
use App\Entity\Project;
@@ -58,6 +59,9 @@ class ActivityTest extends TestCase
$this->assertInstanceOf(Activity::class, $sut->setColor('#fffccc'));
$this->assertEquals('#fffccc', $sut->getColor());
+ $this->assertInstanceOf(Activity::class, $sut->setColor(Constants::DEFAULT_COLOR));
+ $this->assertNull($sut->getColor());
+
$this->assertInstanceOf(Activity::class, $sut->setBudget(12345.67));
$this->assertEquals(12345.67, $sut->getBudget());
diff --git a/tests/Entity/CustomerTest.php b/tests/Entity/CustomerTest.php
index 559588b6..72a89672 100644
--- a/tests/Entity/CustomerTest.php
+++ b/tests/Entity/CustomerTest.php
@@ -9,6 +9,7 @@
namespace App\Tests\Entity;
+use App\Constants;
use App\Entity\Customer;
use App\Entity\CustomerMeta;
use App\Entity\Team;
@@ -72,6 +73,9 @@ class CustomerTest extends TestCase
self::assertInstanceOf(Customer::class, $sut->setColor('#fffccc'));
self::assertEquals('#fffccc', $sut->getColor());
+ self::assertInstanceOf(Customer::class, $sut->setColor(Constants::DEFAULT_COLOR));
+ self::assertNull($sut->getColor());
+
self::assertInstanceOf(Customer::class, $sut->setCompany('test company'));
self::assertEquals('test company', $sut->getCompany());
diff --git a/tests/Entity/ProjectTest.php b/tests/Entity/ProjectTest.php
index d1298521..49964554 100644
--- a/tests/Entity/ProjectTest.php
+++ b/tests/Entity/ProjectTest.php
@@ -9,6 +9,7 @@
namespace App\Tests\Entity;
+use App\Constants;
use App\Entity\Customer;
use App\Entity\Project;
use App\Entity\ProjectMeta;
@@ -82,6 +83,9 @@ class ProjectTest extends TestCase
self::assertInstanceOf(Project::class, $sut->setColor('#fffccc'));
self::assertEquals('#fffccc', $sut->getColor());
+ self::assertInstanceOf(Project::class, $sut->setColor(Constants::DEFAULT_COLOR));
+ self::assertNull($sut->getColor());
+
self::assertInstanceOf(Project::class, $sut->setVisible(false));
self::assertFalse($sut->isVisible());
diff --git a/tests/Reporting/AbstractDateByUserTest.php b/tests/Reporting/AbstractDateByUserTest.php
new file mode 100644
index 00000000..46cfac3a
--- /dev/null
+++ b/tests/Reporting/AbstractDateByUserTest.php
@@ -0,0 +1,43 @@
+createSut();
+ self::assertNull($sut->getDate());
+ self::assertNull($sut->getUser());
+ }
+
+ public function testSetter()
+ {
+ $date = new \DateTime('2019-05-27');
+ $user = new User();
+ $user->setAlias('sdfsdfdsdf');
+
+ $sut = $this->createSut();
+ self::assertInstanceOf(DateByUser::class, $sut->setDate($date));
+ self::assertInstanceOf(DateByUser::class, $sut->setUser($user));
+
+ self::assertSame($date, $sut->getDate());
+ self::assertSame($user, $sut->getUser());
+ }
+}
diff --git a/tests/Reporting/MonthByUserTest.php b/tests/Reporting/MonthByUserTest.php
new file mode 100644
index 00000000..651d16e1
--- /dev/null
+++ b/tests/Reporting/MonthByUserTest.php
@@ -0,0 +1,25 @@
+createDateTimeFactory(self::TEST_TIMEZONE);
+ $this->assertEquals(self::TEST_TIMEZONE, $sut->getTimezone()->getName());
+ }
+
+ public function testGetTimezoneWithFallbackTimezone()
+ {
+ $sut = $this->createDateTimeFactory();
+ $this->assertEquals(date_default_timezone_get(), $sut->getTimezone()->getName());
+ }
+
+ public function testGetStartOfMonth()
+ {
+ $expected = new DateTime('now', new DateTimeZone(self::TEST_TIMEZONE));
+
+ $sut = $this->createDateTimeFactory(self::TEST_TIMEZONE);
+ $dateTime = $sut->getStartOfMonth();
+ $this->assertEquals(0, $dateTime->format('H'));
+ $this->assertEquals(0, $dateTime->format('i'));
+ $this->assertEquals(0, $dateTime->format('s'));
+ $this->assertEquals(1, $dateTime->format('d'));
+ $this->assertEquals($expected->format('m'), $dateTime->format('m'));
+ $this->assertEquals($expected->format('Y'), $dateTime->format('Y'));
+ $this->assertEquals(self::TEST_TIMEZONE, $dateTime->getTimezone()->getName());
+ }
+
+ public function testGetEndOfMonth()
+ {
+ $expected = new DateTime('last day of this month', new DateTimeZone(self::TEST_TIMEZONE));
+
+ $sut = $this->createDateTimeFactory(self::TEST_TIMEZONE);
+ $dateTime = $sut->getEndOfMonth();
+ $this->assertEquals(23, $dateTime->format('H'));
+ $this->assertEquals(59, $dateTime->format('i'));
+ $this->assertEquals(59, $dateTime->format('s'));
+ $this->assertEquals($expected->format('d'), $dateTime->format('d'));
+ $this->assertEquals($expected->format('m'), $dateTime->format('m'));
+ $this->assertEquals($expected->format('Y'), $dateTime->format('Y'));
+ $this->assertEquals(self::TEST_TIMEZONE, $dateTime->getTimezone()->getName());
+ }
+
+ public function testGetStartOfWeek()
+ {
+ $expected = new DateTime('2018-07-26 16:47:31', new DateTimeZone(self::TEST_TIMEZONE));
+
+ $sut = $this->createDateTimeFactory(self::TEST_TIMEZONE);
+ $dateTime = $sut->getStartOfWeek($expected);
+
+ $this->assertEquals(0, $dateTime->format('H'));
+ $this->assertEquals(0, $dateTime->format('i'));
+ $this->assertEquals(0, $dateTime->format('s'));
+ $this->assertEquals(23, $dateTime->format('d'));
+ $this->assertEquals(1, $dateTime->format('N'));
+ $this->assertEquals('Monday', $dateTime->format('l'));
+ $this->assertEquals($expected->format('m'), $dateTime->format('m'));
+ $this->assertEquals($expected->format('Y'), $dateTime->format('Y'));
+ $this->assertEquals(self::TEST_TIMEZONE, $dateTime->getTimezone()->getName());
+
+ $expected = new DateTime('now', new DateTimeZone(self::TEST_TIMEZONE));
+ $dateTime = $sut->getStartOfWeek();
+
+ $this->assertEquals(0, $dateTime->format('H'));
+ $this->assertEquals(0, $dateTime->format('i'));
+ $this->assertEquals(0, $dateTime->format('s'));
+ $this->assertEquals(1, $dateTime->format('N'));
+ $this->assertEquals('Monday', $dateTime->format('l'));
+ $this->assertEquals($expected->format('m'), $dateTime->format('m'));
+ $this->assertEquals($expected->format('Y'), $dateTime->format('Y'));
+ $this->assertEquals(self::TEST_TIMEZONE, $dateTime->getTimezone()->getName());
+ }
+
+ public function testGetEndOfWeek()
+ {
+ $expected = new DateTime('2018-07-26 16:47:31', new DateTimeZone(self::TEST_TIMEZONE));
+
+ $sut = $this->createDateTimeFactory(self::TEST_TIMEZONE);
+ $dateTime = $sut->getEndOfWeek($expected);
+
+ $this->assertEquals(23, $dateTime->format('H'));
+ $this->assertEquals(59, $dateTime->format('i'));
+ $this->assertEquals(59, $dateTime->format('s'));
+ $this->assertEquals(29, $dateTime->format('d'));
+ $this->assertEquals(7, $dateTime->format('N'));
+ $this->assertEquals('Sunday', $dateTime->format('l'));
+ $this->assertEquals($expected->format('m'), $dateTime->format('m'));
+ $this->assertEquals($expected->format('Y'), $dateTime->format('Y'));
+ $this->assertEquals(self::TEST_TIMEZONE, $dateTime->getTimezone()->getName());
+
+ $expected = new DateTime('now', new DateTimeZone(self::TEST_TIMEZONE));
+ $dateTime = $sut->getEndOfWeek();
+
+ $this->assertEquals(23, $dateTime->format('H'));
+ $this->assertEquals(59, $dateTime->format('i'));
+ $this->assertEquals(59, $dateTime->format('s'));
+ $this->assertEquals(7, $dateTime->format('N'));
+ $this->assertEquals('Sunday', $dateTime->format('l'));
+ $this->assertEquals($expected->format('m'), $dateTime->format('m'));
+ $this->assertEquals($expected->format('Y'), $dateTime->format('Y'));
+ $this->assertEquals(self::TEST_TIMEZONE, $dateTime->getTimezone()->getName());
+ }
+
+ public function testCreateDateTime()
+ {
+ $sut = $this->createDateTimeFactory(self::TEST_TIMEZONE);
+ $dateTime = $sut->createDateTime('2015-07-24 13:45:21');
+ $this->assertEquals(13, $dateTime->format('H'));
+ $this->assertEquals(45, $dateTime->format('i'));
+ $this->assertEquals(21, $dateTime->format('s'));
+ $this->assertEquals('24', $dateTime->format('d'));
+ $this->assertEquals('07', $dateTime->format('m'));
+ $this->assertEquals('2015', $dateTime->format('Y'));
+ $this->assertEquals(self::TEST_TIMEZONE, $dateTime->getTimezone()->getName());
+ }
+
+ public function testCreateDateTimeWithDefaultValue()
+ {
+ $expected = new DateTime('now', new DateTimeZone(self::TEST_TIMEZONE));
+
+ $sut = $this->createDateTimeFactory(self::TEST_TIMEZONE);
+ $dateTime = $sut->createDateTime();
+ $difference = $expected->getTimestamp() - $dateTime->getTimestamp();
+ // poor test, but there shouldn't be more than 2 seconds between the creation of two DateTime objects
+ $this->assertTrue(2 >= $difference);
+ }
+}
diff --git a/tests/Timesheet/UserDateTimeFactoryTest.php b/tests/Timesheet/UserDateTimeFactoryTest.php
index ad37f44f..678db403 100644
--- a/tests/Timesheet/UserDateTimeFactoryTest.php
+++ b/tests/Timesheet/UserDateTimeFactoryTest.php
@@ -14,80 +14,27 @@ use App\Timesheet\UserDateTimeFactory;
use PHPUnit\Framework\TestCase;
/**
+ * @covers \App\Timesheet\DateTimeFactory
* @covers \App\Timesheet\UserDateTimeFactory
*/
class UserDateTimeFactoryTest extends TestCase
{
- public const TEST_TIMEZONE = 'Europe/London';
+ public const TEST_TIMEZONE = 'Africa/Asmara';
- protected function createDateTimeFactory(?string $timezone = null): UserDateTimeFactory
+ protected function createUserDateTimeFactory(?string $timezone = null): UserDateTimeFactory
{
return (new UserDateTimeFactoryFactory($this))->create($timezone);
}
public function testGetTimezone()
{
- $sut = $this->createDateTimeFactory(self::TEST_TIMEZONE);
+ $sut = $this->createUserDateTimeFactory(self::TEST_TIMEZONE);
$this->assertEquals(self::TEST_TIMEZONE, $sut->getTimezone()->getName());
}
public function testGetTimezoneWithFallbackTimezone()
{
- $sut = $this->createDateTimeFactory();
+ $sut = $this->createUserDateTimeFactory();
$this->assertEquals(date_default_timezone_get(), $sut->getTimezone()->getName());
}
-
- public function testGetStartOfMonth()
- {
- $expected = new \DateTime('now', new \DateTimeZone(self::TEST_TIMEZONE));
-
- $sut = $this->createDateTimeFactory(self::TEST_TIMEZONE);
- $dateTime = $sut->getStartOfMonth();
- $this->assertEquals(0, $dateTime->format('H'));
- $this->assertEquals(0, $dateTime->format('i'));
- $this->assertEquals(0, $dateTime->format('s'));
- $this->assertEquals(1, $dateTime->format('d'));
- $this->assertEquals($expected->format('m'), $dateTime->format('m'));
- $this->assertEquals($expected->format('Y'), $dateTime->format('Y'));
- $this->assertEquals(self::TEST_TIMEZONE, $dateTime->getTimezone()->getName());
- }
-
- public function testGetEndOfMonth()
- {
- $expected = new \DateTime('last day of this month', new \DateTimeZone(self::TEST_TIMEZONE));
-
- $sut = $this->createDateTimeFactory(self::TEST_TIMEZONE);
- $dateTime = $sut->getEndOfMonth();
- $this->assertEquals(23, $dateTime->format('H'));
- $this->assertEquals(59, $dateTime->format('i'));
- $this->assertEquals(59, $dateTime->format('s'));
- $this->assertEquals($expected->format('d'), $dateTime->format('d'));
- $this->assertEquals($expected->format('m'), $dateTime->format('m'));
- $this->assertEquals($expected->format('Y'), $dateTime->format('Y'));
- $this->assertEquals(self::TEST_TIMEZONE, $dateTime->getTimezone()->getName());
- }
-
- public function testCreateDateTime()
- {
- $sut = $this->createDateTimeFactory(self::TEST_TIMEZONE);
- $dateTime = $sut->createDateTime('2015-07-24 13:45:21');
- $this->assertEquals(13, $dateTime->format('H'));
- $this->assertEquals(45, $dateTime->format('i'));
- $this->assertEquals(21, $dateTime->format('s'));
- $this->assertEquals('24', $dateTime->format('d'));
- $this->assertEquals('07', $dateTime->format('m'));
- $this->assertEquals('2015', $dateTime->format('Y'));
- $this->assertEquals(self::TEST_TIMEZONE, $dateTime->getTimezone()->getName());
- }
-
- public function testCreateDateTimeWithDefaultValue()
- {
- $expected = new \DateTime('now', new \DateTimeZone(self::TEST_TIMEZONE));
-
- $sut = $this->createDateTimeFactory(self::TEST_TIMEZONE);
- $dateTime = $sut->createDateTime();
- $difference = $expected->getTimestamp() - $dateTime->getTimestamp();
- // poor test, but there shouldn't be more than 2 seconds between the creation of two DateTime objects
- $this->assertTrue(2 >= $difference);
- }
}
diff --git a/tests/Twig/DateExtensionsTest.php b/tests/Twig/DateExtensionsTest.php
index f20b81f0..9c1b743f 100644
--- a/tests/Twig/DateExtensionsTest.php
+++ b/tests/Twig/DateExtensionsTest.php
@@ -139,20 +139,27 @@ class DateExtensionsTest extends TestCase
/**
* @dataProvider getMonthNameTestData
*/
- public function testMonthName(string $locale, string $date, string $expectedName)
+ public function testMonthName(string $locale, string $date, string $expectedName, bool $withYear = false)
{
$sut = $this->getSut($locale, []);
- self::assertEquals($expectedName, $sut->monthName(new \DateTime($date)));
+ self::assertEquals($expectedName, $sut->monthName(new \DateTime($date), $withYear));
}
public function getMonthNameTestData()
{
return [
- ['de', '2020-07-09 23:59:59', 'Juli'],
- ['en', '2020-07-09 23:59:59', 'July'],
- ['de', 'January 2016', 'Januar'],
- ['en', 'January 2016', 'January'],
- ['en', '2016-12-23', 'December'],
+ ['de', '2020-07-09 23:59:59', 'Juli', false],
+ ['en', '2020-07-09 23:59:59', 'July', false],
+ ['de', 'January 2016', 'Januar', false],
+ ['en', 'January 2016', 'January', false],
+ ['en', '2016-12-23', 'December', false],
+ ['ru', '2016-12-23', 'декабрь', false],
+ ['de', '2020-07-09 23:59:59', 'Juli 2020', true],
+ ['en', '2020-07-09 23:59:59', 'July 2020', true],
+ ['de', 'January 2016', 'Januar 2016', true],
+ ['en', 'January 2016', 'January 2016', true],
+ ['en', '2015-12-23', 'December 2015', true],
+ ['ru', '2015-12-23', 'декабрь 2015', true],
];
}
diff --git a/tests/Twig/ExtensionsTest.php b/tests/Twig/ExtensionsTest.php
index a58bf4cd..bbe8fe51 100644
--- a/tests/Twig/ExtensionsTest.php
+++ b/tests/Twig/ExtensionsTest.php
@@ -9,6 +9,9 @@
namespace App\Tests\Twig;
+use App\Entity\Activity;
+use App\Entity\Customer;
+use App\Entity\Project;
use App\Entity\User;
use App\Twig\Extensions;
use PHPUnit\Framework\TestCase;
@@ -27,7 +30,7 @@ class ExtensionsTest extends TestCase
public function testGetFilters()
{
- $filters = ['docu_link', 'multiline_indent'];
+ $filters = ['docu_link', 'multiline_indent', 'color'];
$sut = $this->getSut();
$twigFilters = $sut->getFilters();
$this->assertCount(\count($filters), $twigFilters);
@@ -116,4 +119,39 @@ sdfsdf' . PHP_EOL . "\n" .
$sut = $this->getSut();
self::assertEquals(implode("\n", $expected), $sut->multilineIndent($string, $indent));
}
+
+ public function testColor()
+ {
+ $sut = $this->getSut();
+
+ $globalActivity = new Activity();
+ self::assertNull($sut->color($globalActivity));
+
+ $globalActivity->setColor('#000001');
+ self::assertEquals('#000001', $sut->color($globalActivity));
+
+ $customer = new Customer();
+ self::assertNull($sut->color($customer));
+
+ $customer->setColor('#000004');
+ self::assertEquals('#000004', $sut->color($customer));
+
+ $project = new Project();
+ self::assertNull($sut->color($project));
+
+ $project->setCustomer($customer);
+ self::assertEquals('#000004', $sut->color($project));
+
+ $project->setColor('#000003');
+ self::assertEquals('#000003', $sut->color($project));
+
+ $activity = new Activity();
+ self::assertNull($sut->color($activity));
+
+ $activity->setProject($project);
+ self::assertEquals('#000003', $sut->color($activity));
+
+ $activity->setColor('#000002');
+ self::assertEquals('#000002', $sut->color($activity));
+ }
}
diff --git a/tests/Twig/ReportingExtensionTest.php b/tests/Twig/ReportingExtensionTest.php
index ee155be7..6216d5fe 100644
--- a/tests/Twig/ReportingExtensionTest.php
+++ b/tests/Twig/ReportingExtensionTest.php
@@ -57,6 +57,6 @@ class ReportingExtensionTest extends TestCase
$sut = $this->getSut(true);
$reports = $sut->getAvailableReports(new User());
self::assertIsArray($reports);
- self::assertCount(2, $reports);
+ self::assertCount(3, $reports);
}
}
diff --git a/translations/messages.nl.xlf b/translations/messages.nl.xlf
index 420cf2f7..49fe1c7d 100644
--- a/translations/messages.nl.xlf
+++ b/translations/messages.nl.xlf
@@ -648,6 +648,10 @@
+
+ stats.workingTimeWeek
+ Kalenderweek %week%
+
stats.durationToday
Prestaties vandaag
diff --git a/translations/reporting.de.xlf b/translations/reporting.de.xlf
index f17fd1d2..0d11fa3c 100644
--- a/translations/reporting.de.xlf
+++ b/translations/reporting.de.xlf
@@ -6,6 +6,10 @@
reporting.title
Reporting
+
+ report_user_week
+ Wochenansicht für einen Benutzer
+
report_user_month
Monatsansicht für einen Benutzer
diff --git a/translations/reporting.en.xlf b/translations/reporting.en.xlf
index 2bf56be2..af7e1c36 100644
--- a/translations/reporting.en.xlf
+++ b/translations/reporting.en.xlf
@@ -6,6 +6,10 @@
reporting.title
Reporting
+
+ report_user_week
+ Weekly view for one user
+
report_user_month
Monthly view for one user
diff --git a/translations/reporting.nl.xlf b/translations/reporting.nl.xlf
new file mode 100644
index 00000000..0178ef23
--- /dev/null
+++ b/translations/reporting.nl.xlf
@@ -0,0 +1,23 @@
+
+
+
+
+
+ reporting.title
+ Rapporten
+
+
+ report_user_week
+ Weekoverzicht voor een user
+
+
+ report_user_month
+ Maandoverzicht voor een user
+
+
+ report_monthly_users
+ Maandoverzicht voor alle users
+
+
+
+