2024-01-17 16:10:43 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace App\Tests\Controller;
|
|
|
|
|
2024-01-18 21:08:07 +00:00
|
|
|
use App\Service\QRCodeProviderInterface;
|
2024-01-17 16:10:43 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|
|
|
|
|
|
|
class IndexControllerTest extends WebTestCase
|
|
|
|
{
|
|
|
|
public function testFormIsPresentAfterLoadHomepage(): void
|
|
|
|
{
|
|
|
|
$client = static::createClient();
|
|
|
|
$client->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
|
|
|
|
{
|
2024-01-18 21:08:07 +00:00
|
|
|
$mock = $this->createMock(QRCodeProviderInterface::class);
|
2024-01-17 16:10:43 +00:00
|
|
|
$mock->expects($this->any())
|
|
|
|
->method('generateQRCodeFromEntity')
|
|
|
|
->will($this->returnValue('foo'));
|
|
|
|
|
|
|
|
|
|
|
|
$client = static::createClient();
|
|
|
|
$client->disableReboot();
|
|
|
|
|
2024-01-18 21:08:07 +00:00
|
|
|
self::getContainer()->set('App\Service\QRCodeProviderInterface', $mock);
|
2024-01-17 16:10:43 +00:00
|
|
|
|
|
|
|
return $client;
|
|
|
|
}
|
|
|
|
}
|