Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove casting to int on increment ID which can be prefixed by a string #33369

Merged
merged 6 commits into from
Nov 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<?php foreach ($_invoices as $_invoice) : ?>
<div class="order-details-items invoice">
<div class="order-title">
<strong><?= $block->escapeHtml(__('Invoice #')) ?><?= (int) $_invoice->getIncrementId() ?></strong>
<strong><?= $block->escapeHtml(__('Invoice #')) ?><?= $block->escapeHtml($_invoice->getIncrementId()) ?></strong>
</div>
<div class="table-wrapper table-order-items invoice">
<table class="data table table-order-items invoice" id="my-invoice-table-<?= (int) $_invoice->getId() ?>">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public function testPrintInvoice(): void
$order = $this->orderFactory->create()->loadByIncrementId('100000555');
$invoice = $order->getInvoiceCollection()->getFirstItem();
$this->assertNotNull($invoice->getId());
$this->assertTrue(is_numeric($invoice->getIncrementId()));
$this->registerOrder($order);
$this->registerInvoice($invoice);
$blockHtml = $this->renderPrintInvoiceBlock();
Expand All @@ -125,11 +126,41 @@ public function testPrintInvoice(): void
Xpath::getElementsCountForXpath(
sprintf(
"//div[contains(@class, 'order-title')]/strong[contains(text(), '%s')]",
__('Invoice #%1', (int)$invoice->getIncrementId())
__('Invoice #%1', $invoice->getIncrementId())
),
$blockHtml
),
sprintf('Title for %s was not found.', __('Invoice #%1', (int)$invoice->getIncrementId()))
sprintf('Title for %s was not found.', __('Invoice #%1', $invoice->getIncrementId()))
);
$this->assertOrderInformation($order, $blockHtml);
}

/**
* @magentoDataFixture Magento/Sales/_files/invoices_for_items.php
*
* @return void
*/
public function testPrintInvoiceWithStringPrefix(): void
{
$order = $this->orderFactory->create()->loadByIncrementId('100000555');
$invoice = $order->getInvoiceCollection()->getFirstItem();
$this->assertNotNull($invoice->getId());
// set text prefix to increment id
$invoice->setIncrementId('prefix-' . $invoice->getIncrementId());
$this->assertFalse(is_numeric($invoice->getIncrementId()));
$this->registerOrder($order);
$this->registerInvoice($invoice);
$blockHtml = $this->renderPrintInvoiceBlock();
$this->assertEquals(
1,
Xpath::getElementsCountForXpath(
sprintf(
"//div[contains(@class, 'order-title')]/strong[contains(text(), '%s')]",
__('Invoice #%1', $invoice->getIncrementId())
),
$blockHtml
),
sprintf('Title for %s was not found.', __('Invoice #%1', $invoice->getIncrementId()))
);
$this->assertOrderInformation($order, $blockHtml);
}
Expand Down