diff --git a/src/Resources/views/Invoice/Admin/_downloadButton.html.twig b/src/Resources/views/Invoice/Admin/_downloadButton.html.twig
new file mode 100644
index 00000000..068b8cc6
--- /dev/null
+++ b/src/Resources/views/Invoice/Admin/_downloadButton.html.twig
@@ -0,0 +1,5 @@
+{% import '@SyliusUi/Macro/buttons.html.twig' as buttons %}
+
+{% set path = path('sylius_invoicing_plugin_admin_invoice_download', {'id': invoice.id}) %}
+
+{{ buttons.default(path, 'sylius_invoicing_plugin.ui.download_invoice'|trans, invoice.id, 'download', 'blue') }}
diff --git a/src/Resources/views/Invoice/Admin/_resendButton.html.twig b/src/Resources/views/Invoice/Admin/_resendButton.html.twig
new file mode 100644
index 00000000..e6f57e3b
--- /dev/null
+++ b/src/Resources/views/Invoice/Admin/_resendButton.html.twig
@@ -0,0 +1,5 @@
+{% import '@SyliusUi/Macro/buttons.html.twig' as buttons %}
+
+{% set path = path('sylius_invoicing_plugin_admin_invoice_resend', {'id': invoice.id}) %}
+
+{{ buttons.default(path, 'sylius_invoicing_plugin.ui.resend_invoice'|trans, invoice.id, 'send') }}
diff --git a/src/Resources/views/Invoice/Show/_backButton.html.twig b/src/Resources/views/Invoice/Show/_backButton.html.twig
new file mode 100644
index 00000000..03096ac8
--- /dev/null
+++ b/src/Resources/views/Invoice/Show/_backButton.html.twig
@@ -0,0 +1,5 @@
+{% import '@SyliusUi/Macro/buttons.html.twig' as buttons %}
+
+{% set path = path('sylius_invoicing_plugin_admin_invoice_index') %}
+
+{{ buttons.default(path, '', 'back', 'arrow alternate circle left outline') }}
diff --git a/src/Resources/views/Invoice/show.html.twig b/src/Resources/views/Invoice/show.html.twig
index a3ad226a..7fc4d914 100644
--- a/src/Resources/views/Invoice/show.html.twig
+++ b/src/Resources/views/Invoice/show.html.twig
@@ -2,8 +2,6 @@
{% import '@SyliusAdmin/Common/Macro/money.html.twig' as money %}
-{% import '@SyliusUi/Macro/buttons.html.twig' as buttons %}
-
{% block title %}{{ 'sylius.ui.invoice'|trans ~ ' ' ~ invoice.number }} {{ parent() }}{% endblock %}
{% block content %}
@@ -13,14 +11,7 @@
{% include '@SyliusInvoicingPlugin/Invoice/Show/_breadcrumb.html.twig' %}
- {% set path = path('sylius_invoicing_plugin_admin_invoice_index') %}
- {{ buttons.default(path, '', 'back', 'arrow alternate circle left outline') }}
-
- {% set path = path('sylius_invoicing_plugin_admin_invoice_download', {'id': invoice.id}) %}
- {{ buttons.default(path, 'sylius_invoicing_plugin.ui.download_invoice'|trans, invoice.id, 'download', 'blue') }}
-
- {% set path = path('sylius_invoicing_plugin_admin_invoice_resend', {'id': invoice.id}) %}
- {{ buttons.default(path, 'sylius_invoicing_plugin.ui.resend_invoice'|trans, invoice.id, 'send') }}
+ {{ sylius_template_event('sylius_invoicing.admin.invoice.buttons', _context) }}
diff --git a/src/Resources/views/Order/Admin/_invoices.html.twig b/src/Resources/views/Order/Admin/_invoices.html.twig
index e817e746..119e7ff6 100644
--- a/src/Resources/views/Order/Admin/_invoices.html.twig
+++ b/src/Resources/views/Order/Admin/_invoices.html.twig
@@ -24,11 +24,7 @@
- {% set path = path('sylius_invoicing_plugin_admin_invoice_download', { 'id': invoice.id }) %}
- {{ buttons.default(path, 'sylius_invoicing_plugin.ui.download_invoice'|trans, invoice.id, 'download', 'blue') }}
-
- {% set path = path('sylius_invoicing_plugin_admin_invoice_resend', { 'id': invoice.id }) %}
- {{ buttons.default(path, 'sylius_invoicing_plugin.ui.resend_invoice'|trans, invoice.id, 'send') }}
+ {{ sylius_template_event('sylius_invoicing.admin.order.invoices.list.actions.buttons', _context) }}
|
diff --git a/src/Resources/views/Order/Shop/_downloadButton.html.twig b/src/Resources/views/Order/Shop/_downloadButton.html.twig
new file mode 100644
index 00000000..84aeccdb
--- /dev/null
+++ b/src/Resources/views/Order/Shop/_downloadButton.html.twig
@@ -0,0 +1,5 @@
+{% import '@SyliusUi/Macro/buttons.html.twig' as buttons %}
+
+{% set path = path('sylius_invoicing_plugin_shop_invoice_download', { 'id': invoice.id }) %}
+
+{{ buttons.default(path, 'sylius_invoicing_plugin.ui.download_invoice'|trans, invoice.id, 'download') }}
diff --git a/src/Resources/views/Order/Shop/_invoices.html.twig b/src/Resources/views/Order/Shop/_invoices.html.twig
index dbfd4f83..92375c69 100644
--- a/src/Resources/views/Order/Shop/_invoices.html.twig
+++ b/src/Resources/views/Order/Shop/_invoices.html.twig
@@ -1,5 +1,3 @@
-{% import '@SyliusUi/Macro/buttons.html.twig' as buttons %}
-
@@ -20,9 +18,7 @@
{{ invoice.issuedAt|format_date }}
- {% set path = path('sylius_invoicing_plugin_shop_invoice_download', { 'id': invoice.id }) %}
-
- {{ buttons.default(path, 'sylius_invoicing_plugin.ui.download_invoice'|trans, invoice.id, 'download') }}
+ {{ sylius_template_event('sylius_invoicing.shop.order.invoices.list.actions', _context) }}
|
{% endfor %}
diff --git a/src/Ui/Action/DownloadInvoiceAction.php b/src/Ui/Action/DownloadInvoiceAction.php
index b9cec6f3..32013403 100644
--- a/src/Ui/Action/DownloadInvoiceAction.php
+++ b/src/Ui/Action/DownloadInvoiceAction.php
@@ -24,24 +24,20 @@
final class DownloadInvoiceAction
{
- private InvoiceRepositoryInterface $invoiceRepository;
-
- private AuthorizationCheckerInterface $authorizationChecker;
-
- private InvoiceFileProviderInterface $invoiceFilePathProvider;
-
public function __construct(
- InvoiceRepositoryInterface $invoiceRepository,
- AuthorizationCheckerInterface $authorizationChecker,
- InvoiceFileProviderInterface $invoiceFilePathProvider
+ private InvoiceRepositoryInterface $invoiceRepository,
+ private AuthorizationCheckerInterface $authorizationChecker,
+ private InvoiceFileProviderInterface $invoiceFilePathProvider,
+ private bool $hasEnabledPdfFileGenerator = true
) {
- $this->invoiceRepository = $invoiceRepository;
- $this->authorizationChecker = $authorizationChecker;
- $this->invoiceFilePathProvider = $invoiceFilePathProvider;
}
public function __invoke(string $id): Response
{
+ if (!$this->hasEnabledPdfFileGenerator) {
+ return new Response('', Response::HTTP_NOT_FOUND);
+ }
+
/** @var InvoiceInterface|null $invoice */
$invoice = $this->invoiceRepository->find($id);
Assert::notNull($invoice);
diff --git a/tests/Application/etc/sylius_invoicing_pdf_generation_disabled.yaml b/tests/Application/etc/sylius_invoicing_pdf_generation_disabled.yaml
new file mode 100644
index 00000000..a6ad576c
--- /dev/null
+++ b/tests/Application/etc/sylius_invoicing_pdf_generation_disabled.yaml
@@ -0,0 +1,3 @@
+sylius_invoicing:
+ pdf_generator:
+ enabled: false
diff --git a/tests/Behat/Context/Hook/InvoicesContext.php b/tests/Behat/Context/Hook/InvoicesContext.php
index f3f91846..08c161d3 100644
--- a/tests/Behat/Context/Hook/InvoicesContext.php
+++ b/tests/Behat/Context/Hook/InvoicesContext.php
@@ -8,11 +8,8 @@
final class InvoicesContext implements Context
{
- private string $invoicesSavePath;
-
- public function __construct(string $invoicesSavePath)
+ public function __construct(private string $invoicesSavePath)
{
- $this->invoicesSavePath = $invoicesSavePath;
}
/**
@@ -20,6 +17,10 @@ public function __construct(string $invoicesSavePath)
*/
public function clearInvoicesPath(): void
{
+ if (!is_dir($this->invoicesSavePath)) {
+ return;
+ }
+
foreach (scandir($this->invoicesSavePath) as $file) {
if (is_file($this->invoicesSavePath.'/'.$file)) {
unlink($this->invoicesSavePath.'/'.$file);
diff --git a/tests/Behat/Context/Ui/Admin/ManagingInvoicesContext.php b/tests/Behat/Context/Ui/Admin/ManagingInvoicesContext.php
index 3d3f03ab..e324a793 100644
--- a/tests/Behat/Context/Ui/Admin/ManagingInvoicesContext.php
+++ b/tests/Behat/Context/Ui/Admin/ManagingInvoicesContext.php
@@ -335,4 +335,20 @@ public function itShouldBeUnpaid(): void
{
Assert::false($this->showPage->isPaid());
}
+
+ /**
+ * @Then I should not be able to download the first invoice
+ */
+ public function iShouldNotBeAbleToDownloadTheFirstInvoice(): void
+ {
+ Assert::false($this->orderShowPage->hasDownloadButtonForInvoice());
+ }
+
+ /**
+ * @Then I should not be able to download the invoice
+ */
+ public function iShouldNotBeAbleToDownloadTheInvoice(): void
+ {
+ Assert::false($this->showPage->hasDownloadButton());
+ }
}
diff --git a/tests/Behat/Context/Ui/Shop/CustomerBrowsingInvoicesContext.php b/tests/Behat/Context/Ui/Shop/CustomerBrowsingInvoicesContext.php
index a8a34d1c..1f2dafdd 100644
--- a/tests/Behat/Context/Ui/Shop/CustomerBrowsingInvoicesContext.php
+++ b/tests/Behat/Context/Ui/Shop/CustomerBrowsingInvoicesContext.php
@@ -66,4 +66,12 @@ public function invoiceForOrderShouldNotBeDownloaded(string $orderNumber): void
Assert::false($this->downloadInvoicePage->isOpen(['id' => $invoice->id()]));
}
+
+ /**
+ * @Then I should not be able to download the first invoice
+ */
+ public function iShouldNotBeAbleToDownloadTheFirstInvoice(): void
+ {
+ Assert::false($this->orderShowPage->hasDownloadButtonForInvoice());
+ }
}
diff --git a/tests/Behat/Page/Admin/Invoice/ShowPage.php b/tests/Behat/Page/Admin/Invoice/ShowPage.php
index 955b644f..24d0f428 100644
--- a/tests/Behat/Page/Admin/Invoice/ShowPage.php
+++ b/tests/Behat/Page/Admin/Invoice/ShowPage.php
@@ -163,6 +163,11 @@ public function isPaid(): bool
return str_contains($this->getElement('paid')->getHtml(), 'Yes');
}
+ public function hasDownloadButton(): bool
+ {
+ return $this->getDocument()->hasLink('Download');
+ }
+
protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
diff --git a/tests/Behat/Page/Admin/Invoice/ShowPageInterface.php b/tests/Behat/Page/Admin/Invoice/ShowPageInterface.php
index 6fba6dce..603b4b31 100644
--- a/tests/Behat/Page/Admin/Invoice/ShowPageInterface.php
+++ b/tests/Behat/Page/Admin/Invoice/ShowPageInterface.php
@@ -56,4 +56,6 @@ public function resend(): void;
public function goBack(): void;
public function isPaid(): bool;
+
+ public function hasDownloadButton(): bool;
}
diff --git a/tests/Behat/Page/Admin/Order/ShowPage.php b/tests/Behat/Page/Admin/Order/ShowPage.php
index b270981f..35487045 100644
--- a/tests/Behat/Page/Admin/Order/ShowPage.php
+++ b/tests/Behat/Page/Admin/Order/ShowPage.php
@@ -50,6 +50,13 @@ public function isPdfFileDownloaded(): bool
;
}
+ public function hasDownloadButtonForInvoice(): bool
+ {
+ $invoice = $this->getFirstInvoice();
+
+ return $invoice->hasLink('Download');
+ }
+
protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
diff --git a/tests/Behat/Page/Admin/Order/ShowPageInterface.php b/tests/Behat/Page/Admin/Order/ShowPageInterface.php
index 6147fea4..6e148852 100644
--- a/tests/Behat/Page/Admin/Order/ShowPageInterface.php
+++ b/tests/Behat/Page/Admin/Order/ShowPageInterface.php
@@ -17,4 +17,6 @@ public function downloadFirstInvoice(): void;
public function resendFirstInvoice(): void;
public function isPdfFileDownloaded(): bool;
+
+ public function hasDownloadButtonForInvoice(): bool;
}
diff --git a/tests/Behat/Page/Shop/Order/ShowPage.php b/tests/Behat/Page/Shop/Order/ShowPage.php
index efbd3355..57bac4a1 100644
--- a/tests/Behat/Page/Shop/Order/ShowPage.php
+++ b/tests/Behat/Page/Shop/Order/ShowPage.php
@@ -31,6 +31,13 @@ public function isPdfFileDownloaded(): bool
;
}
+ public function hasDownloadButtonForInvoice(): bool
+ {
+ $invoice = $this->getFirstInvoice();
+
+ return $invoice->hasLink('Download');
+ }
+
protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
diff --git a/tests/Behat/Page/Shop/Order/ShowPageInterface.php b/tests/Behat/Page/Shop/Order/ShowPageInterface.php
index 4666a8c6..acf4097a 100644
--- a/tests/Behat/Page/Shop/Order/ShowPageInterface.php
+++ b/tests/Behat/Page/Shop/Order/ShowPageInterface.php
@@ -7,6 +7,8 @@
interface ShowPageInterface
{
public function downloadFirstInvoice(): void;
-
+
public function isPdfFileDownloaded(): bool;
+
+ public function hasDownloadButtonForInvoice(): bool;
}
diff --git a/tests/Behat/Resources/suites/admin/managing_invoices.yml b/tests/Behat/Resources/suites/admin/managing_invoices.yml
index 040d565e..28aab16f 100644
--- a/tests/Behat/Resources/suites/admin/managing_invoices.yml
+++ b/tests/Behat/Resources/suites/admin/managing_invoices.yml
@@ -61,7 +61,7 @@ default:
- Tests\Sylius\InvoicingPlugin\Behat\Context\Setup\OrderContext
filters:
- tags: "@managing_invoices && @ui"
+ tags: "@managing_invoices&&@ui"
managing_invoices_application:
contexts:
@@ -102,7 +102,7 @@ default:
- Tests\Sylius\InvoicingPlugin\Behat\Context\Application\ManagingInvoicesContext
filters:
- tags: "@managing_invoices && @application"
+ tags: "@managing_invoices&&@application"
managing_invoices_cli:
contexts:
@@ -157,4 +157,4 @@ default:
- Tests\Sylius\InvoicingPlugin\Behat\Context\Cli\InvoicesGenerationContext
filters:
- tags: "@managing_invoices && @cli"
+ tags: "@managing_invoices&&@cli"
diff --git a/tests/Behat/Resources/suites/customer.yml b/tests/Behat/Resources/suites/customer.yml
index 990c67ae..48e01c5e 100644
--- a/tests/Behat/Resources/suites/customer.yml
+++ b/tests/Behat/Resources/suites/customer.yml
@@ -52,7 +52,7 @@ default:
- Tests\Sylius\InvoicingPlugin\Behat\Context\Ui\Shop\CustomerBrowsingInvoicesContext
filters:
- tags: "@customer_browsing_invoices && @ui"
+ tags: "@customer_browsing_invoices&&@ui"
customer_browsing_invoices_application:
contexts:
- sylius.behat.context.hook.doctrine_orm
@@ -94,4 +94,4 @@ default:
- sylius.behat.context.transform.shared_storage
filters:
- tags: "@customer_browsing_invoices && @application"
+ tags: "@customer_browsing_invoices&&@application"
diff --git a/tests/Unit/DependencyInjection/SyliusInvoicingConfigurationTest.php b/tests/DependencyInjection/SyliusInvoicingConfigurationTest.php
similarity index 62%
rename from tests/Unit/DependencyInjection/SyliusInvoicingConfigurationTest.php
rename to tests/DependencyInjection/SyliusInvoicingConfigurationTest.php
index 5c48b473..a2371c4a 100644
--- a/tests/Unit/DependencyInjection/SyliusInvoicingConfigurationTest.php
+++ b/tests/DependencyInjection/SyliusInvoicingConfigurationTest.php
@@ -11,7 +11,7 @@
declare(strict_types=1);
-namespace Tests\Sylius\InvoicingPlugin\Unit\DependencyInjection;
+namespace Tests\Sylius\InvoicingPlugin\DependencyInjection;
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
use PHPUnit\Framework\TestCase;
@@ -27,7 +27,7 @@ public function it_does_not_define_any_allowed_files_by_default(): void
$this->assertProcessedConfigurationEquals(
[[]],
['pdf_generator' => ['allowed_files' => []]],
- 'pdf_generator'
+ 'pdf_generator.allowed_files'
);
}
@@ -37,7 +37,27 @@ public function it_allows_to_define_allowed_files(): void
$this->assertProcessedConfigurationEquals(
[['pdf_generator' => ['allowed_files' => ['swans.png', 'product.png']]]],
['pdf_generator' => ['allowed_files' => ['swans.png', 'product.png']]],
- 'pdf_generator'
+ 'pdf_generator.allowed_files'
+ );
+ }
+
+ /** @test */
+ public function it_has_enabled_pdf_generator_by_default(): void
+ {
+ $this->assertProcessedConfigurationEquals(
+ [],
+ ['pdf_generator' => ['enabled' => true]],
+ 'pdf_generator.enabled'
+ );
+ }
+
+ /** @test */
+ public function it_allows_to_disable_pdf_generator(): void
+ {
+ $this->assertProcessedConfigurationEquals(
+ [['pdf_generator' => ['enabled' => false]]],
+ ['pdf_generator' => ['enabled' => false]],
+ 'pdf_generator.enabled'
);
}
diff --git a/tests/DependencyInjection/SyliusInvoicingExtensionTest.php b/tests/DependencyInjection/SyliusInvoicingExtensionTest.php
index 91b7bc63..aa9764ee 100644
--- a/tests/DependencyInjection/SyliusInvoicingExtensionTest.php
+++ b/tests/DependencyInjection/SyliusInvoicingExtensionTest.php
@@ -91,6 +91,19 @@ public function it_loads_allowed_files_for_pdf_generator_configuration(): void
);
}
+ /** @test */
+ public function it_prepends_configuration_with_enabled_pdf_generator(): void
+ {
+ $this->container->prependExtensionConfig(
+ 'sylius_invoicing',
+ ['pdf_generator' => ['enabled' => false]]
+ );
+
+ $this->prepend();
+
+ $this->assertContainerBuilderHasParameter('sylius_invoicing.pdf_generator.enabled', false);
+ }
+
/** @test */
public function it_prepends_configuration_with_invoice_resource_services(): void
{