improved calendar (#784)

This commit is contained in:
Kevin Papst
2019-05-19 16:16:20 +02:00
committed by GitHub
parent 1903d6fb77
commit d2ad87d09c
66 changed files with 1030 additions and 1190 deletions

View File

@@ -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,
];
}
}