+ {% if qrCodeImage %}
+
+
+
+
+ {% endif %}
+ {{ form_start(form) }}
+
+ {{ form_label(form.iban) }}
+ {{ form_widget(form.iban) }}
+
+
{{ form_help(form.iban) }}
+
+
+ {{ form_errors(form.iban) }}
+
+
+
+ {{ form_label(form.dueDate) }}
+ {{ form_widget(form.dueDate) }}
+
+
{{ form_help(form.dueDate) }}
+
+
+ {{ form_errors(form.dueDate) }}
+
+
+
+ {{ form_label(form.message) }}
+ {{ form_widget(form.message) }}
+
+
{{ form_help(form.message) }}
+
+
+ {{ form_errors(form.message) }}
+
+
+ {# money #}
+
+
+
+ {{ form_label(form.money.amount) }}
+ {{ form_widget(form.money.amount) }}
+
+
{{ form_help(form.money.amount) }}
+
+
+ {{ form_errors(form.money.amount) }}
+
+
+
+ {{ form_label(form.money.currency) }}
+ {{ form_widget(form.money.currency) }}
+
+
{{ form_help(form.money.currency) }}
+
+
+ {{ form_errors(form.money.currency) }}
+
+
+
+
+ {# payment identification #}
+
+
+
+ {{ form_label(form.paymentIdentification.variableSymbol) }}
+ {{ form_widget(form.paymentIdentification.variableSymbol) }}
+
+
{{ form_help(form.paymentIdentification.variableSymbol) }}
+
+
+ {{ form_errors(form.paymentIdentification.variableSymbol) }}
+
+
+
+ {{ form_label(form.paymentIdentification.constantSymbol) }}
+ {{ form_widget(form.paymentIdentification.constantSymbol) }}
+
+
{{ form_help(form.paymentIdentification.constantSymbol) }}
+
+
+ {{ form_errors(form.paymentIdentification.constantSymbol) }}
+
+
+
+ {{ form_label(form.paymentIdentification.specificSymbol) }}
+ {{ form_widget(form.paymentIdentification.specificSymbol) }}
+
+
{{ form_help(form.paymentIdentification.specificSymbol) }}
+
+
+ {{ form_errors(form.paymentIdentification.specificSymbol) }}
+
+
+
+
+ {{ form_end(form) }}
+
+{% endblock %}
diff --git a/tests/Controller/IndexControllerTest.php b/tests/Controller/IndexControllerTest.php
new file mode 100644
index 0000000..9f98168
--- /dev/null
+++ b/tests/Controller/IndexControllerTest.php
@@ -0,0 +1,92 @@
+request('GET', '/');
+
+ $this->assertResponseIsSuccessful();
+ $this->assertSelectorExists('form');
+ }
+
+ public function testImageIsPresentAfterSubmitForm(): void {
+ $client = $this->generateClientForSubmitTest();
+ $response = $client->request('GET', '/');
+ $this->assertResponseIsSuccessful();
+ $form = $response->selectButton('Vygenerovat QR kód')->form();
+ $dt = new \DateTime('now+1 hour'); // In case of 23:59:59
+ $client->submit($form, [
+ 'qr_code' => [
+ 'iban' => 'CZ5508000000001234567899',
+ 'dueDate' => $dt->format('Y-m-d'),
+ 'message' => 'foo',
+ 'money' => [
+ 'currency' => 'CZK',
+ 'amount' => '100'
+ ],
+ 'paymentIdentification' => [
+ 'variableSymbol' => '123',
+ 'constantSymbol' => '123',
+ 'specificSymbol' => '123'
+ ]
+ ]
+ ]);
+
+ $this->assertResponseIsSuccessful();
+ $this->assertSelectorExists('form');
+ $this->assertSelectorExists('img');
+ }
+
+ public function testImageIsNotPresentAfterFailSubmitForm(): void {
+ $client = $this->generateClientForSubmitTest();
+ $response = $client->request('GET', '/');
+ $this->assertResponseIsSuccessful();
+ $form = $response->selectButton('Vygenerovat QR kód')->form();
+ $dt = new \DateTime('now+1 hour'); // In case of 23:59:59
+ $client->submit($form, [
+ 'qr_code' => [
+ 'iban' => 'IBAN_THAT_NOT_EXISTS',
+ 'dueDate' => $dt->format('Y-m-d'),
+ 'message' => 'foo',
+ 'money' => [
+ 'currency' => 'CZK',
+ 'amount' => '100'
+ ],
+ 'paymentIdentification' => [
+ 'variableSymbol' => '123',
+ 'constantSymbol' => '123',
+ 'specificSymbol' => '123'
+ ]
+ ]
+ ]);
+
+ $this->assertResponseIsUnprocessable();
+ $this->assertSelectorExists('form');
+ $this->assertSelectorNotExists('img');
+ }
+
+ private function generateClientForSubmitTest(): KernelBrowser
+ {
+ $mock = $this->createMock(QRCodeGeneratorInterface::class);
+ $mock->expects($this->any())
+ ->method('generateQRCodeFromEntity')
+ ->will($this->returnValue('foo'));
+
+
+ $client = static::createClient();
+ $client->disableReboot();
+
+ self::getContainer()->set('App\Service\QRCodeGeneratorInterface', $mock);
+
+ return $client;
+ }
+}
diff --git a/tests/Validator/BankPaymentIdentificationNumberValidatorTest.php b/tests/Validator/BankPaymentIdentificationNumberValidatorTest.php
new file mode 100644
index 0000000..d9e08e9
--- /dev/null
+++ b/tests/Validator/BankPaymentIdentificationNumberValidatorTest.php
@@ -0,0 +1,40 @@
+initialize($this->createExecutionContext(false));
+ $bankPaymentIdentificationValidator->validate($generatedValue, new BankPaymentIdentificationNumber(['message' => 'foo']));
+ }
+
+ private function successDp(): array {
+ return [['122'], ['1234567890'], ['1']];
+ }
+
+ /**
+ * @dataProvider failureDp
+ * @param string $generatedValue
+ * @return void
+ */
+ public function testFailure(string $generatedValue): void {
+ $bankPaymentIdentificationValidator = new BankPaymentIdentificationNumberValidator();
+ $bankPaymentIdentificationValidator->initialize($this->createExecutionContext(true));
+ $bankPaymentIdentificationValidator->validate($generatedValue, new BankPaymentIdentificationNumber(['message' => 'foo']));
+ }
+
+ private function failureDp(): array {
+ return [['122.b'], ['a.a'], ['a'], ['2.040'], ['2,a'], ['122.1'], ['12345678901']];
+ }
+}
diff --git a/tests/Validator/CurrencyValidatorTest.php b/tests/Validator/CurrencyValidatorTest.php
new file mode 100644
index 0000000..43192d1
--- /dev/null
+++ b/tests/Validator/CurrencyValidatorTest.php
@@ -0,0 +1,33 @@
+createCurrencyValidator();
+ $currencyValidator->initialize($this->createExecutionContext(false));
+
+ $currencyValidator->validate('USD', new Currency(['message' => 'foo']));
+ }
+
+ public function testFailure(): void {
+ $currencyValidator = $this->createCurrencyValidator();
+ $currencyValidator->initialize($this->createExecutionContext(true));
+ $currencyValidator->validate('EUR', new Currency(['message' => 'foo']));
+ }
+
+ private function createCurrencyValidator(): CurrencyValidator {
+ $mock = $this->createMock(CurrencyListerInterface::class);
+ $mock->expects($this->once())
+ ->method('getCurrencies')
+ ->will($this->returnValue(['USD', 'CZK']));
+
+ return new CurrencyValidator($mock);
+ }
+}
diff --git a/tests/Validator/MoneyValidatorTest.php b/tests/Validator/MoneyValidatorTest.php
new file mode 100644
index 0000000..a234620
--- /dev/null
+++ b/tests/Validator/MoneyValidatorTest.php
@@ -0,0 +1,40 @@
+initialize($this->createExecutionContext(false));
+ $moneyValidator->validate($generatedValue, new Money(['message' => 'foo']));
+ }
+
+ private function successDp(): array {
+ return [['122'], ['122.0'], ['122,00'], ['122'], ['2.05'], ['2,04']];
+ }
+
+ /**
+ * @dataProvider failureDp
+ * @param string $generatedValue
+ * @return void
+ */
+ public function testFailure(string $generatedValue): void {
+ $moneyValidator = new MoneyValidator();
+ $moneyValidator->initialize($this->createExecutionContext(true));
+ $moneyValidator->validate($generatedValue, new Money(['message' => 'foo']));
+ }
+
+ private function failureDp(): array {
+ return [['122.b'], ['a.a'], ['a'], ['2.040'], ['2,a']];
+ }
+}
diff --git a/tests/Validator/ValidatorTestCase.php b/tests/Validator/ValidatorTestCase.php
new file mode 100644
index 0000000..6d6f43d
--- /dev/null
+++ b/tests/Validator/ValidatorTestCase.php
@@ -0,0 +1,19 @@
+once() : $this->never();
+
+ $context = $this->createMock(ExecutionContextInterface::class);
+ $context->expects($expected)
+ ->method('buildViolation');
+
+ return $context;
+ }
+}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
new file mode 100644
index 0000000..3181151
--- /dev/null
+++ b/tests/bootstrap.php
@@ -0,0 +1,15 @@
+bootEnv(dirname(__DIR__).'/.env');
+}
+
+if ($_SERVER['APP_DEBUG']) {
+ umask(0000);
+}
diff --git a/translations/.gitignore b/translations/.gitignore
new file mode 100644
index 0000000..e69de29
diff --git a/translations/messages.cs.yaml b/translations/messages.cs.yaml
new file mode 100644
index 0000000..6bc48a6
--- /dev/null
+++ b/translations/messages.cs.yaml
@@ -0,0 +1,11 @@
+Due date: "Datum splatnosti"
+Message: "Zpráva pro přijemce"
+Amount: "Částka"
+Currency: "Měna"
+Variable symbol: "Variabilní symbol"
+Constant symbol: "Konstantní symbol"
+Specific symbol: "Specifický symbol"
+Generate qr code: "Vygenerovat QR kód"
+Iban: "IBAN"
+QR code generator: "Generátor bankovních QR kódů"
+You can generate another QR code here: "Další QR kód si můžete vygenerovat zde"
diff --git a/translations/validation_errors.cs.yaml b/translations/validation_errors.cs.yaml
new file mode 100644
index 0000000..2bbb0da
--- /dev/null
+++ b/translations/validation_errors.cs.yaml
@@ -0,0 +1,10 @@
+messages:
+ not_variable_symbol: "Neplatný variabilní symbol. Variabilní symbol musí být max. 10 číslic"
+ not_specific_symbol: "Neplatný specifický symbol. Specifický symbol musí být max. 10 číslic"
+ not_constant_symbol: "Neplatný konstantní symbol. Konstatní symbol musí být max. 10 číslic"
+ not_a_iban_number: "Neplatný formát IBAN"
+ not_valid_amount: "Neplatná částka"
+ invalid_date: "Neplatné datum. Datum musí být v budoucnosti nebo dnes"
+ fill_value: "Prosím vyplňte hodnotu"
+ scale_must_be_positive: "Číslo musí být > 0."
+ margin_must_be_positive: "Margin musí být > 0."