refactor configurations (#2626)

* composition instead of inheritance
* refactored some twig extensions to runtime extensions
This commit is contained in:
Kevin Papst
2021-06-26 13:03:54 +02:00
committed by GitHub
parent 3d1fba650b
commit 6d196879b4
22 changed files with 255 additions and 358 deletions

View File

@@ -48,7 +48,7 @@ class CalendarControllerTest extends ControllerBaseTest
$client = $this->getClientForAuthenticatedUser();
static::$kernel->getContainer()->set(SystemConfiguration::class, $config);
$this->request($client, '/calendar/');
$this->assertTrue($client->getResponse()->isSuccessful());
$this->assertSuccessResponse($client);
$crawler = $client->getCrawler();
$calendar = $crawler->filter('div#timesheet_calendar');
@@ -61,9 +61,35 @@ class CalendarControllerTest extends ControllerBaseTest
$this->assertStringContainsString("name: 'holidays_en'", $content);
}
protected function getDefaultSettings()
protected function getDefaultSettings(): array
{
return [
'theme' => [
'active_warning' => 3,
'box_color' => 'blue',
'select_type' => 'selectpicker',
'show_about' => true,
'chart' => [
'background_color' => '#3c8dbc',
'border_color' => '#3b8bba',
'grid_color' => 'rgba(0,0,0,.05)',
'height' => '200',
],
'branding' => [
'logo' => null,
'mini' => null,
'company' => null,
'title' => null,
'translation' => null,
],
'autocomplete_chars' => 3,
'tags_create' => true,
'calendar' => [
'background_color' => '#d2d6de'
],
'colors_limited' => true,
'color_choices' => 'Silver|#c0c0c0,Gray|#808080,Black|#000000,Maroon|#800000,Brown|#a52a2a,Red|#ff0000,Orange|#ffa500,Gold|#ffd700,Yellow|#ffff00,Peach|#ffdab9,Khaki|#f0e68c,Olive|#808000,Lime|#00ff00,Jelly|#9acd32,Green|#008000,Teal|#008080,Aqua|#00ffff,LightBlue|#add8e6,DeepSky|#00bfff,Dodger|#1e90ff,Blue|#0000ff,Navy|#000080,Purple|#800080,Fuchsia|#ff00ff,Violet|#ee82ee,Rose|#ffe4e1,Lavender|#E6E6FA'
],
'defaults' => [
'user' => [
'language' => 'en'

View File

@@ -18,6 +18,7 @@ use App\Tests\KernelTestTrait;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Test\Constraint as ResponseConstraint;
use Symfony\Component\HttpKernel\HttpKernelBrowser;
/**
@@ -161,6 +162,12 @@ abstract class ControllerBaseTest extends WebTestCase
);
}
protected function assertSuccessResponse(HttpKernelBrowser $client, string $message = '')
{
$response = $client->getResponse();
self::assertThat($response, new ResponseConstraint\ResponseIsSuccessful(), 'Response is not successful, got code: ' . $response->getStatusCode());
}
/**
* @param string $url
* @param string $method
@@ -381,26 +388,26 @@ abstract class ControllerBaseTest extends WebTestCase
* @param HttpKernelBrowser $client
* @param string $url
*/
protected function assertIsRedirect(HttpKernelBrowser $client, $url = null, $endsWith = true)
protected function assertIsRedirect(HttpKernelBrowser $client, $url = null)
{
self::assertTrue($client->getResponse()->isRedirect(), 'Response is not a redirect');
self::assertResponseRedirects();
if (null === $url) {
return;
}
$this->assertRedirectUrl($client, $url);
}
protected function assertRedirectUrl(HttpKernelBrowser $client, $url = null, $endsWith = true)
{
self::assertTrue($client->getResponse()->headers->has('Location'), 'Could not find "Location" header');
$location = $client->getResponse()->headers->get('Location');
if ($endsWith) {
self::assertStringEndsWith(
$url,
$client->getResponse()->headers->get('Location'),
'Redirect URL does not match'
);
self::assertStringEndsWith($url, $location, 'Redirect URL does not match');
} else {
self::assertStringContainsString(
$url,
$client->getResponse()->headers->get('Location'),
'Redirect URL does not match'
);
self::assertStringContainsString($url, $location, 'Redirect URL does not match');
}
}

View File

@@ -192,7 +192,8 @@ class InvoiceControllerTest extends ControllerBaseTest
$action = '/invoice/save-invoice/1/' . $template->getId() . '?' . http_build_query($urlParams);
$this->request($client, $action);
$this->assertIsRedirect($client, '/invoice/show?id=', false);
$this->assertIsRedirect($client);
$this->assertRedirectUrl($client, '/invoice/show?id=', false);
$client->followRedirect();
$this->assertDataTableRowCount($client, 'datatable_invoices', 1);