added invoice archive & configurable invoice numbers (#1541)
This commit is contained in:
@@ -321,12 +321,12 @@ abstract class ControllerBaseTest extends WebTestCase
|
||||
*/
|
||||
protected function assertIsRedirect(HttpKernelBrowser $client, $url = null)
|
||||
{
|
||||
self::assertTrue($client->getResponse()->isRedirect());
|
||||
self::assertTrue($client->getResponse()->isRedirect(), 'Response is not a redirect');
|
||||
if (null === $url) {
|
||||
return;
|
||||
}
|
||||
|
||||
self::assertTrue($client->getResponse()->headers->has('Location'));
|
||||
self::assertStringEndsWith($url, $client->getResponse()->headers->get('Location'));
|
||||
self::assertTrue($client->getResponse()->headers->has('Location'), 'Could not find "Location" header');
|
||||
self::assertStringEndsWith($url, $client->getResponse()->headers->get('Location'), 'Redirect URL does not match');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,12 +16,44 @@ use App\Form\Type\DateRangeType;
|
||||
use App\Tests\DataFixtures\InvoiceFixtures;
|
||||
use App\Tests\DataFixtures\TimesheetFixtures;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
*/
|
||||
class InvoiceControllerTest extends ControllerBaseTest
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$path = __DIR__ . '/../_data/invoices/';
|
||||
|
||||
if (is_dir($path)) {
|
||||
$files = glob($path . '*');
|
||||
foreach ($files as $file) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
$this->clearInvoiceFiles();
|
||||
}
|
||||
|
||||
private function clearInvoiceFiles()
|
||||
{
|
||||
$path = __DIR__ . '/../_data/invoices/';
|
||||
|
||||
if (is_dir($path)) {
|
||||
$files = glob($path . '*');
|
||||
foreach ($files as $file) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testIsSecure()
|
||||
{
|
||||
$this->assertUrlIsSecured('/invoice/');
|
||||
@@ -76,7 +108,6 @@ class InvoiceControllerTest extends ControllerBaseTest
|
||||
'company' => 'Company name',
|
||||
'renderer' => 'default',
|
||||
'calculator' => 'default',
|
||||
'numberGenerator' => 'default',
|
||||
]
|
||||
]);
|
||||
|
||||
@@ -111,7 +142,6 @@ class InvoiceControllerTest extends ControllerBaseTest
|
||||
$this->assertEquals($template->getCompany(), $values['company']);
|
||||
$this->assertEquals($template->getAddress(), $values['address']);
|
||||
$this->assertEquals($template->getPaymentTerms(), $values['paymentTerms']);
|
||||
$this->assertEquals($template->getNumberGenerator(), $values['numberGenerator']);
|
||||
}
|
||||
|
||||
public function testPrintAction()
|
||||
@@ -153,8 +183,8 @@ class InvoiceControllerTest extends ControllerBaseTest
|
||||
// no warning should be displayed
|
||||
$node = $client->getCrawler()->filter('div.callout.callout-warning.lead');
|
||||
$this->assertEquals(0, $node->count());
|
||||
// but the datatable with all timesheets
|
||||
$this->assertDataTableRowCount($client, 'datatable_invoice', 20);
|
||||
// but the datatable with all timesheets + 1 row for the total
|
||||
$this->assertDataTableRowCount($client, 'datatable_invoice', 21);
|
||||
|
||||
$form = $client->getCrawler()->filter('#invoice-print-form')->form();
|
||||
$node = $form->getFormNode();
|
||||
@@ -180,6 +210,92 @@ class InvoiceControllerTest extends ControllerBaseTest
|
||||
}
|
||||
}
|
||||
|
||||
public function testPrintActionAsAdminWithDownloadAndStatusChange()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
/** @var EntityManager $em */
|
||||
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
|
||||
|
||||
$fixture = new InvoiceFixtures();
|
||||
$this->importFixture($client, $fixture);
|
||||
|
||||
$begin = new \DateTime('first day of this month');
|
||||
$end = new \DateTime('last day of this month');
|
||||
$fixture = new TimesheetFixtures();
|
||||
$fixture
|
||||
->setUser($this->getUserByRole($em, User::ROLE_ADMIN))
|
||||
->setAmount(20)
|
||||
->setStartDate($begin)
|
||||
;
|
||||
$this->importFixture($client, $fixture);
|
||||
|
||||
$this->request($client, '/invoice/');
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$dateRange = $begin->format('Y-m-d') . DateRangeType::DATE_SPACER . $end->format('Y-m-d');
|
||||
|
||||
$form = $client->getCrawler()->filter('#invoice-print-form')->form();
|
||||
$node = $form->getFormNode();
|
||||
$node->setAttribute('action', $this->createUrl('/invoice/?preview='));
|
||||
$node->setAttribute('method', 'GET');
|
||||
$client->submit($form, [
|
||||
'template' => 1,
|
||||
'daterange' => $dateRange,
|
||||
'customer' => 1,
|
||||
]);
|
||||
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
// no warning should be displayed
|
||||
$node = $client->getCrawler()->filter('div.callout.callout-warning.lead');
|
||||
$this->assertEquals(0, $node->count());
|
||||
// but the datatable with all timesheets + 1 row for the total
|
||||
$this->assertDataTableRowCount($client, 'datatable_invoice', 21);
|
||||
|
||||
$form = $client->getCrawler()->filter('#invoice-print-form')->form();
|
||||
$node = $form->getFormNode();
|
||||
$node->setAttribute('action', $this->createUrl('/invoice/?create='));
|
||||
$node->setAttribute('method', 'GET');
|
||||
$client->submit($form, [
|
||||
'template' => 1,
|
||||
'daterange' => $dateRange,
|
||||
'customer' => 1,
|
||||
'project' => 1,
|
||||
'markAsExported' => 1,
|
||||
]);
|
||||
|
||||
$this->assertIsRedirect($client, '/invoice/show?id=1');
|
||||
$client->followRedirect();
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$this->assertHasFlashSuccess($client);
|
||||
|
||||
$this->assertHasDataTable($client);
|
||||
$this->assertDataTableRowCount($client, 'datatable_invoices', 1);
|
||||
|
||||
// make sure the invoice is saved
|
||||
$this->request($client, '/invoice/download/1');
|
||||
$response = $client->getResponse();
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
self::assertInstanceOf(BinaryFileResponse::class, $response);
|
||||
self::assertFileExists($response->getFile());
|
||||
|
||||
$this->request($client, '/invoice/change-status/1/pending');
|
||||
$this->assertIsRedirect($client, '/invoice/show');
|
||||
$client->followRedirect();
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$this->request($client, '/invoice/change-status/1/paid');
|
||||
$this->assertIsRedirect($client, '/invoice/show');
|
||||
$client->followRedirect();
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$this->request($client, '/invoice/change-status/1/new');
|
||||
$this->assertIsRedirect($client, '/invoice/show');
|
||||
$client->followRedirect();
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
}
|
||||
|
||||
public function testEditTemplateAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
@@ -196,7 +312,6 @@ class InvoiceControllerTest extends ControllerBaseTest
|
||||
'company' => 'Company name',
|
||||
'renderer' => 'default',
|
||||
'calculator' => 'default',
|
||||
'numberGenerator' => 'default',
|
||||
]
|
||||
]);
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class PermissionControllerTest extends ControllerBaseTest
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
$this->assertAccessIsGranted($client, '/admin/permissions');
|
||||
$this->assertHasDataTable($client);
|
||||
$this->assertDataTableRowCount($client, 'datatable_user_admin_permissions', 108);
|
||||
$this->assertDataTableRowCount($client, 'datatable_user_admin_permissions', 109);
|
||||
$this->assertPageActions($client, [
|
||||
'back' => $this->createUrl('/admin/user/'),
|
||||
'roles modal-ajax-form' => $this->createUrl('/admin/permissions/roles/create'),
|
||||
|
||||
@@ -68,6 +68,7 @@ class SystemConfigurationControllerTest extends ControllerBaseTest
|
||||
{
|
||||
return [
|
||||
['form[name=system_configuration_form_timesheet]', $this->createUrl('/admin/system-config/update/timesheet')],
|
||||
['form[name=system_configuration_form_invoice]', $this->createUrl('/admin/system-config/update/invoice')],
|
||||
['form[name=system_configuration_form_rounding]', $this->createUrl('/admin/system-config/update/rounding')],
|
||||
['form[name=system_configuration_form_form_customer]', $this->createUrl('/admin/system-config/update/form_customer')],
|
||||
['form[name=system_configuration_form_form_user]', $this->createUrl('/admin/system-config/update/form_user')],
|
||||
|
||||
Reference in New Issue
Block a user