improved calendar (#784)
This commit is contained in:
@@ -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'));
|
||||
|
||||
Reference in New Issue
Block a user