improved calendar (#784)
This commit is contained in:
@@ -221,10 +221,10 @@ class ActivityControllerTest extends APIControllerBaseTest
|
||||
|
||||
protected function assertStructure(array $result, $full = true)
|
||||
{
|
||||
$expectedKeys = ['id', 'name', 'visible', 'project', 'hourlyRate', 'fixedRate'];
|
||||
$expectedKeys = ['id', 'name', 'visible', 'project', 'hourlyRate', 'fixedRate', 'color'];
|
||||
|
||||
if ($full) {
|
||||
$expectedKeys = array_merge($expectedKeys, ['comment', 'color']);
|
||||
$expectedKeys = array_merge($expectedKeys, ['comment']);
|
||||
}
|
||||
|
||||
$actual = array_keys($result);
|
||||
|
||||
@@ -164,11 +164,11 @@ class CustomerControllerTest extends APIControllerBaseTest
|
||||
|
||||
protected function assertStructure(array $result, $full = true)
|
||||
{
|
||||
$expectedKeys = ['id', 'name', 'visible', 'hourlyRate', 'fixedRate'];
|
||||
$expectedKeys = ['id', 'name', 'visible', 'hourlyRate', 'fixedRate', 'color'];
|
||||
|
||||
if ($full) {
|
||||
$expectedKeys = array_merge($expectedKeys, [
|
||||
'homepage', 'number', 'comment', 'company', 'contact', 'address', 'country', 'currency', 'phone', 'fax', 'mobile', 'email', 'timezone', 'color'
|
||||
'homepage', 'number', 'comment', 'company', 'contact', 'address', 'country', 'currency', 'phone', 'fax', 'mobile', 'email', 'timezone'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -214,13 +214,13 @@ class ProjectControllerTest extends APIControllerBaseTest
|
||||
protected function assertStructure(array $result, $full = true)
|
||||
{
|
||||
$expectedKeys = [
|
||||
'id', 'name', 'visible', 'customer', 'hourlyRate', 'fixedRate'
|
||||
'id', 'name', 'visible', 'customer', 'hourlyRate', 'fixedRate', 'color'
|
||||
];
|
||||
|
||||
if ($full) {
|
||||
$expectedKeys = array_merge(
|
||||
$expectedKeys,
|
||||
['comment', 'budget', 'orderNumber', 'color']
|
||||
['comment', 'budget', 'orderNumber']
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
class TimesheetControllerTest extends APIControllerBaseTest
|
||||
{
|
||||
public const DATE_FORMAT = 'Y-m-d H:i:s';
|
||||
public const DATE_FORMAT_HTML5 = 'Y-m-d\TH:i:s';
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
@@ -64,6 +65,19 @@ class TimesheetControllerTest extends APIControllerBaseTest
|
||||
$this->assertDefaultStructure($result[0], false);
|
||||
}
|
||||
|
||||
public function testGetCollectionFull()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$this->assertAccessIsGranted($client, '/api/timesheets', 'GET', ['full' => 'true']);
|
||||
$result = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertIsArray($result);
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals(10, count($result));
|
||||
$this->assertDefaultStructure($result[0], false);
|
||||
$this->assertHasSubresources($result[0]);
|
||||
}
|
||||
|
||||
public function testGetCollectionForOtherUser()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
|
||||
@@ -141,10 +155,11 @@ class TimesheetControllerTest extends APIControllerBaseTest
|
||||
'order' => 'DESC',
|
||||
'orderBy' => 'rate',
|
||||
'active' => 0,
|
||||
'begin' => $begin->format('Y-m-d H:i:s'),
|
||||
'end' => $end->format('Y-m-d H:i:s'),
|
||||
'begin' => $begin->format(self::DATE_FORMAT_HTML5),
|
||||
'end' => $end->format(self::DATE_FORMAT_HTML5),
|
||||
'exported' => 0,
|
||||
];
|
||||
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$this->assertAccessIsGranted($client, '/api/timesheets', 'GET', $query);
|
||||
$result = json_decode($client->getResponse()->getContent(), true);
|
||||
@@ -178,10 +193,11 @@ class TimesheetControllerTest extends APIControllerBaseTest
|
||||
$query = [
|
||||
'page' => 1,
|
||||
'size' => 50,
|
||||
'begin' => $begin->format('Y-m-d H:i:s'),
|
||||
'end' => $end->format('Y-m-d H:i:s'),
|
||||
'begin' => $begin->format(self::DATE_FORMAT_HTML5),
|
||||
'end' => $end->format(self::DATE_FORMAT_HTML5),
|
||||
'exported' => 1,
|
||||
];
|
||||
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$this->assertAccessIsGranted($client, '/api/timesheets', 'GET', $query);
|
||||
$result = json_decode($client->getResponse()->getContent(), true);
|
||||
@@ -194,10 +210,11 @@ class TimesheetControllerTest extends APIControllerBaseTest
|
||||
$query = [
|
||||
'page' => 1,
|
||||
'size' => 50,
|
||||
'begin' => $begin->format('Y-m-d H:i:s'),
|
||||
'end' => $end->format('Y-m-d H:i:s'),
|
||||
'begin' => $begin->format(self::DATE_FORMAT_HTML5),
|
||||
'end' => $end->format(self::DATE_FORMAT_HTML5),
|
||||
'exported' => 0,
|
||||
];
|
||||
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$this->assertAccessIsGranted($client, '/api/timesheets', 'GET', $query);
|
||||
$result = json_decode($client->getResponse()->getContent(), true);
|
||||
@@ -210,8 +227,8 @@ class TimesheetControllerTest extends APIControllerBaseTest
|
||||
$query = [
|
||||
'page' => 1,
|
||||
'size' => 50,
|
||||
'begin' => $begin->format('Y-m-d H:i:s'),
|
||||
'end' => $end->format('Y-m-d H:i:s'),
|
||||
'begin' => $begin->format(self::DATE_FORMAT_HTML5),
|
||||
'end' => $end->format(self::DATE_FORMAT_HTML5),
|
||||
];
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$this->assertAccessIsGranted($client, '/api/timesheets', 'GET', $query);
|
||||
@@ -482,7 +499,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
|
||||
$query = [
|
||||
'user' => 'all',
|
||||
'size' => 2,
|
||||
'begin' => $start->format(self::DATE_FORMAT),
|
||||
'begin' => $start->format(self::DATE_FORMAT_HTML5),
|
||||
];
|
||||
|
||||
$this->assertAccessIsGranted($client, '/api/timesheets/recent', 'GET', $query);
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
<?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\Calendar;
|
||||
|
||||
use App\Calendar\Config;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \App\Calendar\Config
|
||||
*/
|
||||
class ConfigTest extends TestCase
|
||||
{
|
||||
public function testConstruct()
|
||||
{
|
||||
$config = [
|
||||
'businessHours' => [
|
||||
'days' => [0, 99, 127],
|
||||
'begin' => '07:49',
|
||||
'end' => '19:27'
|
||||
],
|
||||
'day_limit' => 20,
|
||||
'week_numbers' => false,
|
||||
];
|
||||
|
||||
$sut = new Config($config);
|
||||
|
||||
$this->assertEquals([0, 99, 127], $sut->getBusinessDays());
|
||||
$this->assertEquals('07:49', $sut->getBusinessTimeBegin());
|
||||
$this->assertEquals('19:27', $sut->getBusinessTimeEnd());
|
||||
$this->assertEquals(20, $sut->getDayLimit());
|
||||
$this->assertFalse($sut->isShowWeekNumbers());
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
<?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\Calendar;
|
||||
|
||||
use App\Calendar\Config;
|
||||
use App\Calendar\Google;
|
||||
use App\Calendar\Service;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \App\Calendar\Service
|
||||
*/
|
||||
class ServiceTest extends TestCase
|
||||
{
|
||||
public function testConstruct()
|
||||
{
|
||||
$config = [
|
||||
'businessHours' => [
|
||||
'days' => [2, 4, 6],
|
||||
'begin' => '07:49',
|
||||
'end' => '19:27'
|
||||
],
|
||||
'day_limit' => 20,
|
||||
'week_numbers' => false,
|
||||
'google' => [
|
||||
'api_key' => 'wertwertwegsdfbdf243w567fg8ihuon',
|
||||
'sources' => [
|
||||
'holidays' => [
|
||||
'id' => 'de.german#holiday@group.v.calendar.google.com',
|
||||
'color' => '#ccc',
|
||||
],
|
||||
'holidays_en' => [
|
||||
'id' => 'en.german#holiday@group.v.calendar.google.com',
|
||||
'color' => '#fff',
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$sut = new Service($config);
|
||||
|
||||
$config = $sut->getConfig();
|
||||
$this->assertInstanceOf(Config::class, $config);
|
||||
$this->assertEquals([2, 4, 6], $config->getBusinessDays());
|
||||
|
||||
$google = $sut->getGoogle();
|
||||
$this->assertInstanceOf(Google::class, $google);
|
||||
$this->assertEquals('wertwertwegsdfbdf243w567fg8ihuon', $google->getApiKey());
|
||||
|
||||
$sources = $google->getSources();
|
||||
$this->assertEquals(2, count($sources));
|
||||
$this->assertEquals('holidays', $sources[0]->getId());
|
||||
$this->assertEquals('#ccc', $sources[0]->getColor());
|
||||
$this->assertEquals('holidays_en', $sources[1]->getId());
|
||||
$this->assertEquals('#fff', $sources[1]->getColor());
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
<?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\Calendar;
|
||||
|
||||
use App\Calendar\TimesheetEntity;
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\Tag;
|
||||
use App\Entity\Timesheet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \App\Calendar\TimesheetEntity
|
||||
*/
|
||||
class TimesheetEntityTest extends TestCase
|
||||
{
|
||||
public function testConstruct()
|
||||
{
|
||||
$activity = new Activity();
|
||||
$activity->setName('activity');
|
||||
|
||||
$customer = new Customer();
|
||||
$customer->setName('customer');
|
||||
|
||||
$project = new Project();
|
||||
$project->setName('project');
|
||||
$project->setCustomer($customer);
|
||||
|
||||
$timesheet = new Timesheet();
|
||||
$timesheet->setActivity($activity);
|
||||
$timesheet->setProject($project);
|
||||
$timesheet->addTag((new Tag())->setName('foo'));
|
||||
$timesheet->addTag((new Tag())->setName('bar'));
|
||||
|
||||
$sut = new TimesheetEntity($timesheet);
|
||||
|
||||
$this->assertEquals('customer', $sut->getCustomer());
|
||||
$this->assertEquals('project', $sut->getProject());
|
||||
$this->assertEquals('activity', $sut->getTitle());
|
||||
$this->assertEquals('foo, bar', $sut->getTags());
|
||||
|
||||
$sut->setId(13);
|
||||
$this->assertEquals(13, $sut->getId());
|
||||
|
||||
$date = new \DateTime('-13 hours');
|
||||
$sut->setStart($date);
|
||||
$this->assertEquals($date, $sut->getStart());
|
||||
|
||||
$date = new \DateTime('-3 hours');
|
||||
$sut->setEnd($date);
|
||||
$this->assertEquals($date, $sut->getEnd());
|
||||
|
||||
$sut->setTitle('sdfsdf');
|
||||
$this->assertEquals('sdfsdf', $sut->getTitle());
|
||||
|
||||
$sut->setCustomer('aaaaaaaa');
|
||||
$this->assertEquals('aaaaaaaa', $sut->getCustomer());
|
||||
|
||||
$sut->setProject('bbbbbbbbbb');
|
||||
$this->assertEquals('bbbbbbbbbb', $sut->getProject());
|
||||
|
||||
$sut->setActivity('cccccccc');
|
||||
$this->assertEquals('cccccccc', $sut->getActivity());
|
||||
|
||||
$sut->setTags('hello, world');
|
||||
$this->assertEquals('hello, world', $sut->getTags());
|
||||
|
||||
$this->assertNull($sut->getBorderColor());
|
||||
$sut->setBorderColor('#cccccc');
|
||||
$this->assertEquals('#cccccc', $sut->getBorderColor());
|
||||
|
||||
$this->assertNull($sut->getBackgroundColor());
|
||||
$sut->setBackgroundColor('#ffffff');
|
||||
$this->assertEquals('#ffffff', $sut->getBackgroundColor());
|
||||
|
||||
$sut->setDescription('foo-bar');
|
||||
$this->assertEquals('foo-bar', $sut->getDescription());
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,9 @@ use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \App\Command\RunCodestyleCommand
|
||||
* @covers \App\Command\RunCodestyleCommand
|
||||
* @covers \App\Command\BashExecutor
|
||||
* @covers \App\Command\BashResult
|
||||
* @group integration
|
||||
*/
|
||||
class RunCodestyleCommandTest extends KernelTestCase
|
||||
@@ -47,7 +49,7 @@ class RunCodestyleCommandTest extends KernelTestCase
|
||||
public function testSuccessCommandNoOptions()
|
||||
{
|
||||
$command = $this->assertSuccessCommand([]);
|
||||
$this->assertStringStartsWith('/vendor/bin/php-cs-fixer fix --dry-run --verbose --show-progress=none --format=txt', $command);
|
||||
$this->assertStringStartsWith('/vendor/bin/php-cs-fixer fix --dry-run --verbose --show-progress=none', $command);
|
||||
}
|
||||
|
||||
public function testSuccessCommandFix()
|
||||
@@ -56,16 +58,15 @@ class RunCodestyleCommandTest extends KernelTestCase
|
||||
$this->assertStringStartsWith('/vendor/bin/php-cs-fixer fix', $command);
|
||||
}
|
||||
|
||||
public function testSuccessCommandCheckstyle()
|
||||
public function testSuccessCommand()
|
||||
{
|
||||
$command = $this->assertSuccessCommand(['--checkstyle' => 'phpcs.txt']);
|
||||
$this->assertStringStartsWith('/vendor/bin/php-cs-fixer fix --dry-run --verbose --show-progress=none > ', $command);
|
||||
$this->assertStringEndsWith('phpcs.txt', $command);
|
||||
$command = $this->assertSuccessCommand([]);
|
||||
$this->assertStringStartsWith('/vendor/bin/php-cs-fixer fix --dry-run --verbose --show-progress=none', $command);
|
||||
}
|
||||
|
||||
protected function assertSuccessCommand(array $options)
|
||||
{
|
||||
$result = new BashResult(0, 'FooBar');
|
||||
$result = new BashResult(0);
|
||||
$this->executor->setResult($result);
|
||||
|
||||
$command = $this->application->find('kimai:codestyle');
|
||||
@@ -74,7 +75,6 @@ class RunCodestyleCommandTest extends KernelTestCase
|
||||
$commandTester->execute($inputs);
|
||||
|
||||
$output = $commandTester->getDisplay();
|
||||
$this->assertContains('FooBar', $output);
|
||||
$this->assertContains('[OK] All source files have proper code styles', $output);
|
||||
|
||||
return $this->executor->getCommand();
|
||||
@@ -82,7 +82,7 @@ class RunCodestyleCommandTest extends KernelTestCase
|
||||
|
||||
public function testFailureCommand()
|
||||
{
|
||||
$result = new BashResult(1, 'BarFoo');
|
||||
$result = new BashResult(1);
|
||||
$this->executor->setResult($result);
|
||||
|
||||
$command = $this->application->find('kimai:codestyle');
|
||||
@@ -91,7 +91,6 @@ class RunCodestyleCommandTest extends KernelTestCase
|
||||
$commandTester->execute($inputs);
|
||||
|
||||
$output = $commandTester->getDisplay();
|
||||
$this->assertContains('BarFoo', $output);
|
||||
$this->assertContains('[ERROR] Found problems while checking your code styles', $output);
|
||||
$this->assertContains('[ERROR] Found violations while checking code styles', $output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,9 @@ use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \App\Command\RunIntegrationTestsCommand
|
||||
* @covers \App\Command\RunIntegrationTestsCommand
|
||||
* @covers \App\Command\BashExecutor
|
||||
* @covers \App\Command\BashResult
|
||||
* @group integration
|
||||
*/
|
||||
class RunIntegrationTestsCommandTest extends RunUnitTestsCommandTest
|
||||
@@ -45,7 +47,7 @@ class RunIntegrationTestsCommandTest extends RunUnitTestsCommandTest
|
||||
|
||||
public function testSuccessCommand()
|
||||
{
|
||||
$result = new BashResult(0, 'FooBar');
|
||||
$result = new BashResult(0);
|
||||
$this->executor->setResult($result);
|
||||
|
||||
$command = $this->application->find('kimai:test-integration');
|
||||
@@ -54,16 +56,15 @@ class RunIntegrationTestsCommandTest extends RunUnitTestsCommandTest
|
||||
$commandTester->execute($inputs);
|
||||
|
||||
$output = $commandTester->getDisplay();
|
||||
$this->assertContains('FooBar', $output);
|
||||
$this->assertContains('[OK] All tests were successful', $output);
|
||||
|
||||
$this->assertStringStartsWith('/bin/phpunit --group integration', $this->executor->getCommand());
|
||||
$this->assertStringStartsWith('/vendor/bin/phpunit --group integration', $this->executor->getCommand());
|
||||
$this->assertContains($this->directory, $this->executor->getCommand());
|
||||
}
|
||||
|
||||
public function testFailureCommand()
|
||||
{
|
||||
$result = new BashResult(1, 'BarFoo');
|
||||
$result = new BashResult(1);
|
||||
$this->executor->setResult($result);
|
||||
|
||||
$command = $this->application->find('kimai:test-integration');
|
||||
@@ -72,10 +73,9 @@ class RunIntegrationTestsCommandTest extends RunUnitTestsCommandTest
|
||||
$commandTester->execute($inputs);
|
||||
|
||||
$output = $commandTester->getDisplay();
|
||||
$this->assertContains('BarFoo', $output);
|
||||
$this->assertContains('[ERROR] Found problems while running tests', $output);
|
||||
|
||||
$this->assertStringStartsWith('/bin/phpunit --group integration', $this->executor->getCommand());
|
||||
$this->assertStringStartsWith('/vendor/bin/phpunit --group integration', $this->executor->getCommand());
|
||||
$this->assertContains($this->directory, $this->executor->getCommand());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,9 @@ use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \App\Command\RunUnitTestsCommand
|
||||
* @covers \App\Command\RunUnitTestsCommand
|
||||
* @covers \App\Command\BashExecutor
|
||||
* @covers \App\Command\BashResult
|
||||
* @group integration
|
||||
*/
|
||||
class RunUnitTestsCommandTest extends KernelTestCase
|
||||
@@ -46,7 +48,7 @@ class RunUnitTestsCommandTest extends KernelTestCase
|
||||
|
||||
public function testSuccessCommand()
|
||||
{
|
||||
$result = new BashResult(0, 'FooBar');
|
||||
$result = new BashResult(0);
|
||||
$this->executor->setResult($result);
|
||||
|
||||
$command = $this->application->find('kimai:test-unit');
|
||||
@@ -55,16 +57,15 @@ class RunUnitTestsCommandTest extends KernelTestCase
|
||||
$commandTester->execute($inputs);
|
||||
|
||||
$output = $commandTester->getDisplay();
|
||||
$this->assertContains('FooBar', $output);
|
||||
$this->assertContains('[OK] All tests were successful', $output);
|
||||
|
||||
$this->assertStringStartsWith('/bin/phpunit --exclude-group integration', $this->executor->getCommand());
|
||||
$this->assertStringStartsWith('/vendor/bin/phpunit --exclude-group integration', $this->executor->getCommand());
|
||||
$this->assertContains($this->directory, $this->executor->getCommand());
|
||||
}
|
||||
|
||||
public function testFailureCommand()
|
||||
{
|
||||
$result = new BashResult(1, 'BarFoo');
|
||||
$result = new BashResult(1);
|
||||
$this->executor->setResult($result);
|
||||
|
||||
$command = $this->application->find('kimai:test-unit');
|
||||
@@ -73,10 +74,9 @@ class RunUnitTestsCommandTest extends KernelTestCase
|
||||
$commandTester->execute($inputs);
|
||||
|
||||
$output = $commandTester->getDisplay();
|
||||
$this->assertContains('BarFoo', $output);
|
||||
$this->assertContains('[ERROR] Found problems while running tests', $output);
|
||||
|
||||
$this->assertStringStartsWith('/bin/phpunit --exclude-group integration', $this->executor->getCommand());
|
||||
$this->assertStringStartsWith('/vendor/bin/phpunit --exclude-group integration', $this->executor->getCommand());
|
||||
$this->assertContains($this->directory, $this->executor->getCommand());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \App\Command\VersionCommand
|
||||
* @covers \App\Command\VersionCommand
|
||||
* @group integration
|
||||
*/
|
||||
class VersionCommandTest extends KernelTestCase
|
||||
|
||||
82
tests/Configuration/CalendarConfigurationTest.php
Normal file
82
tests/Configuration/CalendarConfigurationTest.php
Normal 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\Configuration;
|
||||
|
||||
use App\Configuration\CalendarConfiguration;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Configuration\CalendarConfiguration
|
||||
* @covers \App\Configuration\StringAccessibleConfigTrait
|
||||
*/
|
||||
class CalendarConfigurationTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @param array $settings
|
||||
* @param array $loaderSettings
|
||||
* @return CalendarConfiguration
|
||||
*/
|
||||
protected function getSut(array $settings, array $loaderSettings = [])
|
||||
{
|
||||
$loader = new TestConfigLoader($loaderSettings);
|
||||
|
||||
return new CalendarConfiguration($loader, $settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getDefaultSettings()
|
||||
{
|
||||
return [
|
||||
'businessHours' => [
|
||||
'days' => [2, 4, 6],
|
||||
'begin' => '07:49',
|
||||
'end' => '19:27'
|
||||
],
|
||||
'day_limit' => 20,
|
||||
'week_numbers' => false,
|
||||
'google' => [
|
||||
'api_key' => 'wertwertwegsdfbdf243w567fg8ihuon',
|
||||
'sources' => [
|
||||
'holidays' => [
|
||||
'id' => 'de.german#holiday@group.v.calendar.google.com',
|
||||
'color' => '#ccc',
|
||||
],
|
||||
'holidays_en' => [
|
||||
'id' => 'en.german#holiday@group.v.calendar.google.com',
|
||||
'color' => '#fff',
|
||||
],
|
||||
]
|
||||
],
|
||||
'weekends' => true,
|
||||
];
|
||||
}
|
||||
|
||||
public function testPrefix()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings(), []);
|
||||
$this->assertEquals('calendar', $sut->getPrefix());
|
||||
}
|
||||
|
||||
public function testConfigs()
|
||||
{
|
||||
$sut = $this->getSut($this->getDefaultSettings(), []);
|
||||
$this->assertEquals([2, 4, 6], $sut->getBusinessDays());
|
||||
$this->assertEquals('07:49', $sut->getBusinessTimeBegin());
|
||||
$this->assertEquals('19:27', $sut->getBusinessTimeEnd());
|
||||
$this->assertEquals(20, $sut->getDayLimit());
|
||||
$this->assertFalse($sut->isShowWeekNumbers());
|
||||
|
||||
$this->assertEquals('wertwertwegsdfbdf243w567fg8ihuon', $sut->getGoogleApiKey());
|
||||
$sources = $sut->getGoogleSources();
|
||||
$this->assertEquals(2, count($sources));
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Tests\DataFixtures\TimesheetFixtures;
|
||||
use App\Configuration\CalendarConfiguration;
|
||||
use App\Tests\Configuration\TestConfigLoader;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \App\Controller\CalendarController
|
||||
@@ -30,69 +30,59 @@ class CalendarControllerTest extends ControllerBaseTest
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$crawler = $client->getCrawler();
|
||||
$calendar = $crawler->filter('div#calendar');
|
||||
$calendar = $crawler->filter('div#timesheet_calendar');
|
||||
$this->assertEquals(1, $calendar->count());
|
||||
}
|
||||
|
||||
public function testCalendarEntriesAction()
|
||||
public function testCalendarActionWithGoogleSource()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
|
||||
$fixture = new TimesheetFixtures();
|
||||
$fixture->setAmount(10);
|
||||
$fixture->setUser($this->getUserByRole($em, User::ROLE_USER));
|
||||
$fixture->setStartDate('2017-05-01');
|
||||
$this->importFixture($em, $fixture);
|
||||
|
||||
$this->request($client, '/calendar/user');
|
||||
$response = $client->getResponse();
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
$json = json_decode($response->getContent(), true);
|
||||
$this->assertIsArray($json);
|
||||
$this->assertEmpty($json);
|
||||
}
|
||||
|
||||
public function testCalendarEntriesActionWithStartAndEndDate()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
|
||||
$fixture = new TimesheetFixtures();
|
||||
$fixture->setAmount(10);
|
||||
$fixture->setUser($this->getUserByRole($em, User::ROLE_USER));
|
||||
$fixture->setStartDate('2017-05-01');
|
||||
$this->importFixture($em, $fixture);
|
||||
$loader = new TestConfigLoader([]);
|
||||
$config = new CalendarConfiguration($loader, $this->getDefaultSettings());
|
||||
|
||||
$client = $this->getClientForAuthenticatedUser();
|
||||
$this->request($client, '/calendar/user?start=2017-05-01&end=2017-05-30');
|
||||
$response = $client->getResponse();
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
$json = json_decode($response->getContent(), true);
|
||||
$this->assertIsArray($json);
|
||||
$this->assertNotEmpty($json);
|
||||
$this->assertEquals(10, count($json));
|
||||
foreach ($json as $result) {
|
||||
$this->assertIsArray($result);
|
||||
$this->assertCalendarStructure($result);
|
||||
}
|
||||
$client->getContainer()->set(CalendarConfiguration::class, $config);
|
||||
$this->request($client, '/calendar/');
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$crawler = $client->getCrawler();
|
||||
$calendar = $crawler->filter('div#timesheet_calendar');
|
||||
$this->assertEquals(1, $calendar->count());
|
||||
|
||||
$content = $client->getResponse()->getContent();
|
||||
$this->assertContains("googleCalendarId: 'de.german#holiday@group.v.calendar.google.com',", $content);
|
||||
$this->assertContains("name: 'holidays'", $content);
|
||||
$this->assertContains("googleCalendarId: 'en.german#holiday@group.v.calendar.google.com',", $content);
|
||||
$this->assertContains("name: 'holidays_en'", $content);
|
||||
}
|
||||
|
||||
protected function assertCalendarStructure(array $result)
|
||||
protected function getDefaultSettings()
|
||||
{
|
||||
$this->assertArrayHasKey('id', $result);
|
||||
$this->assertArrayHasKey('start', $result);
|
||||
$this->assertArrayHasKey('title', $result);
|
||||
$this->assertArrayHasKey('description', $result);
|
||||
$this->assertArrayHasKey('customer', $result);
|
||||
$this->assertArrayHasKey('project', $result);
|
||||
$this->assertArrayHasKey('activity', $result);
|
||||
$this->assertArrayHasKey('borderColor', $result);
|
||||
$this->assertArrayHasKey('backgroundColor', $result);
|
||||
|
||||
if (isset($result['end'])) {
|
||||
$this->assertNull($result['borderColor']);
|
||||
$this->assertNull($result['backgroundColor']);
|
||||
}
|
||||
return [
|
||||
'businessHours' => [
|
||||
'days' => [2, 4, 6],
|
||||
'begin' => '07:49',
|
||||
'end' => '19:27'
|
||||
],
|
||||
'visibleHours' => [
|
||||
'begin' => '07:49',
|
||||
'end' => '19:27'
|
||||
],
|
||||
'day_limit' => 20,
|
||||
'week_numbers' => false,
|
||||
'google' => [
|
||||
'api_key' => 'wertwertwegsdfbdf243w567fg8ihuon',
|
||||
'sources' => [
|
||||
'holidays' => [
|
||||
'id' => 'de.german#holiday@group.v.calendar.google.com',
|
||||
'color' => '#ccc',
|
||||
],
|
||||
'holidays_en' => [
|
||||
'id' => 'en.german#holiday@group.v.calendar.google.com',
|
||||
'color' => '#fff',
|
||||
],
|
||||
]
|
||||
],
|
||||
'weekends' => true,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,9 +49,10 @@ class SystemConfigurationControllerTest extends ControllerBaseTest
|
||||
public function getTestDataForms()
|
||||
{
|
||||
return [
|
||||
['#system_configuration_form_timesheet', $this->createUrl('/admin/system-config/timesheet')],
|
||||
['#system_configuration_form_form_customer', $this->createUrl('/admin/system-config/customer')],
|
||||
['#system_configuration_form_theme', $this->createUrl('/admin/system-config/theme')],
|
||||
['form[name=system_configuration_form_timesheet]', $this->createUrl('/admin/system-config/update/timesheet')],
|
||||
['form[name=system_configuration_form_form_customer]', $this->createUrl('/admin/system-config/update/form_customer')],
|
||||
['form[name=system_configuration_form_theme]', $this->createUrl('/admin/system-config/update/theme')],
|
||||
['form[name=system_configuration_form_calendar]', $this->createUrl('/admin/system-config/update/calendar')],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -64,12 +65,12 @@ class SystemConfigurationControllerTest extends ControllerBaseTest
|
||||
$this->assertEquals(false, $configService->find('timesheet.markdown_content'));
|
||||
$this->assertEquals('default', $configService->find('timesheet.mode'));
|
||||
$this->assertEquals(true, $configService->find('timesheet.rules.allow_future_times'));
|
||||
$this->assertEquals(3, $configService->find('timesheet.active_entries.hard_limit'));
|
||||
$this->assertEquals(1, $configService->find('timesheet.active_entries.hard_limit'));
|
||||
$this->assertEquals(1, $configService->find('timesheet.active_entries.soft_limit'));
|
||||
|
||||
$form = $client->getCrawler()->filter('#system_configuration_form_timesheet')->form();
|
||||
$form = $client->getCrawler()->filter('form[name=system_configuration_form_timesheet]')->form();
|
||||
$client->submit($form, [
|
||||
'system_configuration_form' => [
|
||||
'system_configuration_form_timesheet' => [
|
||||
'configuration' => [
|
||||
['name' => 'timesheet.mode', 'value' => 'duration_only'],
|
||||
['name' => 'timesheet.markdown_content', 'value' => 1],
|
||||
@@ -98,9 +99,9 @@ class SystemConfigurationControllerTest extends ControllerBaseTest
|
||||
$this->assertFormHasValidationError(
|
||||
User::ROLE_SUPER_ADMIN,
|
||||
'/admin/system-config/',
|
||||
'#system_configuration_form_timesheet',
|
||||
'form[name=system_configuration_form_timesheet]',
|
||||
[
|
||||
'system_configuration_form' => [
|
||||
'system_configuration_form_timesheet' => [
|
||||
'configuration' => [
|
||||
['name' => 'timesheet.mode', 'value' => 'foo'],
|
||||
['name' => 'timesheet.markdown_content', 'value' => 1],
|
||||
@@ -111,9 +112,9 @@ class SystemConfigurationControllerTest extends ControllerBaseTest
|
||||
]
|
||||
],
|
||||
[
|
||||
'#system_configuration_form_configuration_0_value', // mode
|
||||
'#system_configuration_form_configuration_3_value', // hard_limit
|
||||
'#system_configuration_form_configuration_4_value', // soft_limit
|
||||
'#system_configuration_form_timesheet_configuration_0_value', // mode
|
||||
'#system_configuration_form_timesheet_configuration_3_value', // hard_limit
|
||||
'#system_configuration_form_timesheet_configuration_4_value', // soft_limit
|
||||
],
|
||||
true
|
||||
);
|
||||
@@ -129,9 +130,9 @@ class SystemConfigurationControllerTest extends ControllerBaseTest
|
||||
$this->assertEquals('DE', $configService->find('defaults.customer.country'));
|
||||
$this->assertEquals('EUR', $configService->find('defaults.customer.currency'));
|
||||
|
||||
$form = $client->getCrawler()->filter('#system_configuration_form_form_customer')->form();
|
||||
$form = $client->getCrawler()->filter('form[name=system_configuration_form_form_customer]')->form();
|
||||
$client->submit($form, [
|
||||
'system_configuration_form' => [
|
||||
'system_configuration_form_form_customer' => [
|
||||
'configuration' => [
|
||||
['name' => 'defaults.customer.timezone', 'value' => 'Atlantic/Canary'],
|
||||
['name' => 'defaults.customer.country', 'value' => 'BB'],
|
||||
@@ -156,9 +157,9 @@ class SystemConfigurationControllerTest extends ControllerBaseTest
|
||||
$this->assertFormHasValidationError(
|
||||
User::ROLE_SUPER_ADMIN,
|
||||
'/admin/system-config/',
|
||||
'#system_configuration_form_form_customer',
|
||||
'form[name=system_configuration_form_form_customer]',
|
||||
[
|
||||
'system_configuration_form' => [
|
||||
'system_configuration_form_form_customer' => [
|
||||
'configuration' => [
|
||||
['name' => 'defaults.customer.timezone', 'value' => 'XX'],
|
||||
['name' => 'defaults.customer.country', 'value' => 1],
|
||||
@@ -167,9 +168,124 @@ class SystemConfigurationControllerTest extends ControllerBaseTest
|
||||
]
|
||||
],
|
||||
[
|
||||
'#system_configuration_form_configuration_0_value',
|
||||
'#system_configuration_form_configuration_1_value',
|
||||
'#system_configuration_form_configuration_2_value',
|
||||
'#system_configuration_form_form_customer_configuration_0_value',
|
||||
'#system_configuration_form_form_customer_configuration_1_value',
|
||||
'#system_configuration_form_form_customer_configuration_2_value',
|
||||
],
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
public function testUpdateThemeConfig()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
$this->assertAccessIsGranted($client, '/admin/system-config/');
|
||||
|
||||
$configService = $client->getContainer()->get(SystemConfiguration::class);
|
||||
$this->assertNull($configService->find('theme.select_type'));
|
||||
|
||||
$form = $client->getCrawler()->filter('form[name=system_configuration_form_theme]')->form();
|
||||
$client->submit($form, [
|
||||
'system_configuration_form_theme' => [
|
||||
'configuration' => [
|
||||
['name' => 'theme.select_type', 'value' => '1'],
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
$this->assertIsRedirect($client, $this->createUrl('/admin/system-config/'));
|
||||
$client->followRedirect();
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
$this->assertHasFlashSaveSuccess($client);
|
||||
|
||||
$configService = $client->getContainer()->get(SystemConfiguration::class);
|
||||
$this->assertEquals('selectpicker', $configService->find('theme.select_type'));
|
||||
}
|
||||
|
||||
public function testUpdateThemeConfigValidation()
|
||||
{
|
||||
$this->assertFormHasValidationError(
|
||||
User::ROLE_SUPER_ADMIN,
|
||||
'/admin/system-config/',
|
||||
'form[name=system_configuration_form_theme]',
|
||||
[
|
||||
'system_configuration_form_theme' => [
|
||||
'configuration' => [
|
||||
['name' => 'theme.select_type', 'value' => 'foo'],
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
'#system_configuration_form_theme_configuration_0_value',
|
||||
],
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
public function testUpdateCalendarConfig()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
$this->assertAccessIsGranted($client, '/admin/system-config/');
|
||||
|
||||
$configService = $client->getContainer()->get(SystemConfiguration::class);
|
||||
$this->assertTrue($configService->find('calendar.week_numbers'));
|
||||
$this->assertTrue($configService->find('calendar.weekends'));
|
||||
$this->assertEquals('08:00', $configService->find('calendar.businessHours.begin'));
|
||||
$this->assertEquals('20:00', $configService->find('calendar.businessHours.end'));
|
||||
$this->assertEquals('00:00', $configService->find('calendar.visibleHours.begin'));
|
||||
$this->assertEquals('24:00', $configService->find('calendar.visibleHours.end'));
|
||||
|
||||
$form = $client->getCrawler()->filter('form[name=system_configuration_form_calendar]')->form();
|
||||
$client->submit($form, [
|
||||
'system_configuration_form_calendar' => [
|
||||
'configuration' => [
|
||||
['name' => 'calendar.week_numbers', 'value' => false],
|
||||
['name' => 'calendar.weekends', 'value' => false],
|
||||
['name' => 'calendar.businessHours.begin', 'value' => '10:00'],
|
||||
['name' => 'calendar.businessHours.end', 'value' => '16:00'],
|
||||
['name' => 'calendar.visibleHours.begin', 'value' => '05:17'],
|
||||
['name' => 'calendar.visibleHours.end', 'value' => '21:43'],
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
$this->assertIsRedirect($client, $this->createUrl('/admin/system-config/'));
|
||||
$client->followRedirect();
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
$this->assertHasFlashSaveSuccess($client);
|
||||
|
||||
$configService = $client->getContainer()->get(SystemConfiguration::class);
|
||||
$this->assertFalse($configService->find('calendar.week_numbers'));
|
||||
$this->assertFalse($configService->find('calendar.weekends'));
|
||||
$this->assertEquals('10:00', $configService->find('calendar.businessHours.begin'));
|
||||
$this->assertEquals('16:00', $configService->find('calendar.businessHours.end'));
|
||||
$this->assertEquals('05:17', $configService->find('calendar.visibleHours.begin'));
|
||||
$this->assertEquals('21:43', $configService->find('calendar.visibleHours.end'));
|
||||
}
|
||||
|
||||
public function testUpdateCalendarConfigValidation()
|
||||
{
|
||||
$this->assertFormHasValidationError(
|
||||
User::ROLE_SUPER_ADMIN,
|
||||
'/admin/system-config/',
|
||||
'form[name=system_configuration_form_calendar]',
|
||||
[
|
||||
'system_configuration_form_calendar' => [
|
||||
'configuration' => [
|
||||
['name' => 'calendar.week_numbers', 'value' => 'foo'],
|
||||
['name' => 'calendar.weekends', 'value' => 'bar'],
|
||||
['name' => 'calendar.businessHours.begin', 'value' => '25:13'],
|
||||
['name' => 'calendar.businessHours.end', 'value' => null],
|
||||
['name' => 'calendar.visibleHours.begin', 'value' => 'aa:bb'],
|
||||
['name' => 'calendar.visibleHours.end', 'value' => ''],
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
'#system_configuration_form_calendar_configuration_2_value',
|
||||
'#system_configuration_form_calendar_configuration_3_value',
|
||||
'#system_configuration_form_calendar_configuration_4_value',
|
||||
'#system_configuration_form_calendar_configuration_5_value',
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
@@ -35,7 +35,7 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
$this->assertHasNoEntriesWithFilter($client);
|
||||
|
||||
$result = $client->getCrawler()->filter('div.breadcrumb div.box-tools div.btn-group a.btn');
|
||||
$this->assertEquals(5, count($result));
|
||||
$this->assertEquals(4, count($result));
|
||||
|
||||
foreach ($result as $item) {
|
||||
$this->assertContains('btn btn-default', $item->getAttribute('class'));
|
||||
|
||||
@@ -21,6 +21,7 @@ use App\Repository\Query\InvoiceQuery;
|
||||
|
||||
/**
|
||||
* @covers \App\Invoice\Calculator\ActivityInvoiceCalculator
|
||||
* @covers \App\Invoice\Calculator\AbstractMergedCalculator
|
||||
* @covers \App\Invoice\Calculator\AbstractCalculator
|
||||
*/
|
||||
class ActivityInvoiceCalculatorTest extends AbstractCalculatorTest
|
||||
|
||||
@@ -21,6 +21,7 @@ use App\Repository\Query\InvoiceQuery;
|
||||
|
||||
/**
|
||||
* @covers \App\Invoice\Calculator\ShortInvoiceCalculator
|
||||
* @covers \App\Invoice\Calculator\AbstractMergedCalculator
|
||||
* @covers \App\Invoice\Calculator\AbstractCalculator
|
||||
*/
|
||||
class ShortInvoiceCalculatorTest extends AbstractCalculatorTest
|
||||
|
||||
@@ -21,6 +21,7 @@ use App\Repository\Query\InvoiceQuery;
|
||||
|
||||
/**
|
||||
* @covers \App\Invoice\Calculator\UserInvoiceCalculator
|
||||
* @covers \App\Invoice\Calculator\AbstractMergedCalculator
|
||||
* @covers \App\Invoice\Calculator\AbstractCalculator
|
||||
*/
|
||||
class UserInvoiceCalculatorTest extends AbstractCalculatorTest
|
||||
|
||||
Reference in New Issue
Block a user