init
This commit is contained in:
+89
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract test case to test positions of a module's total collectors as compared to other collectors
|
||||
*/
|
||||
namespace Magento\Sales\Model;
|
||||
|
||||
abstract class AbstractCollectorPositionsTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @param string $collectorCode
|
||||
* @param string $configType
|
||||
* @param array $before
|
||||
* @param array $after
|
||||
*
|
||||
* @dataProvider collectorPositionDataProvider
|
||||
*/
|
||||
public function testCollectorPosition($collectorCode, $configType, array $before, array $after)
|
||||
{
|
||||
$allCollectors = self::_getConfigCollectors($configType);
|
||||
$collectorCodes = array_keys($allCollectors);
|
||||
$collectorPos = array_search($collectorCode, $collectorCodes);
|
||||
$this->assertNotFalse($collectorPos, "'{$collectorCode}' total collector is not found");
|
||||
|
||||
foreach ($before as $compareWithCode) {
|
||||
$compareWithPos = array_search($compareWithCode, $collectorCodes);
|
||||
if ($compareWithPos === false) {
|
||||
continue;
|
||||
}
|
||||
$this->assertLessThan(
|
||||
$compareWithPos,
|
||||
$collectorPos,
|
||||
"The '{$collectorCode}' collector must go before '{$compareWithCode}'"
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($after as $compareWithCode) {
|
||||
$compareWithPos = array_search($compareWithCode, $collectorCodes);
|
||||
if ($compareWithPos === false) {
|
||||
continue;
|
||||
}
|
||||
$this->assertGreaterThan(
|
||||
$compareWithPos,
|
||||
$collectorPos,
|
||||
"The '{$collectorCode}' collector must go after '{$compareWithCode}'"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array of total collectors for the designated $configType
|
||||
*
|
||||
* @var string $configType
|
||||
* @throws \InvalidArgumentException
|
||||
* @return array
|
||||
*/
|
||||
protected static function _getConfigCollectors($configType)
|
||||
{
|
||||
switch ($configType) {
|
||||
case 'quote':
|
||||
$configClass = \Magento\Quote\Model\Quote\Address\Total\Collector::class;
|
||||
$methodGetCollectors = 'getCollectors';
|
||||
break;
|
||||
case 'invoice':
|
||||
$configClass = \Magento\Sales\Model\Order\Invoice\Config::class;
|
||||
$methodGetCollectors = 'getTotalModels';
|
||||
break;
|
||||
case 'creditmemo':
|
||||
$configClass = \Magento\Sales\Model\Order\Creditmemo\Config::class;
|
||||
$methodGetCollectors = 'getTotalModels';
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException('Unknown config type: ' . $configType);
|
||||
}
|
||||
$config = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create($configClass);
|
||||
return $config->{$methodGetCollectors}();
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider with the data to verify
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function collectorPositionDataProvider();
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Sales\Model\Convert;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Class OrderTest
|
||||
*/
|
||||
class OrderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/** @var Order */
|
||||
protected $_model;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_model = Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Convert\Order::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/order.php
|
||||
*/
|
||||
public function testConvertToCreditmemo()
|
||||
{
|
||||
/** @var \Magento\Sales\Model\Order $order */
|
||||
$order = Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Order::class);
|
||||
$order->loadByIncrementId('100000001');
|
||||
//MAGETWO-45612 fix
|
||||
$order->setBaseShippingAmount(5);
|
||||
$this->assertNull($this->_model->toCreditmemo($order)->getBaseShippingAmount());
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Sales\Model\CronJob;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use \Magento\Sales\Model\Order;
|
||||
|
||||
class CleanExpiredOrdersTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoConfigFixture default sales/orders/delete_pending_after 0
|
||||
* @magentoConfigFixture current_store sales/orders/delete_pending_after 0
|
||||
* @magentoDataFixture Magento/Sales/_files/order_pending_payment.php
|
||||
*/
|
||||
public function testExecute()
|
||||
{
|
||||
/** @var CleanExpiredOrders $job */
|
||||
$job = Bootstrap::getObjectManager()->create(\Magento\Sales\Model\CronJob\CleanExpiredOrders::class);
|
||||
$job->execute();
|
||||
|
||||
/** @var Order $order */
|
||||
$order = Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Order::class);
|
||||
$order->load('100000001', 'increment_id');
|
||||
$this->assertEquals(Order::STATE_CANCELED, $order->getStatus());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Sales\Model;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteria;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Framework\App\ResourceConnection;
|
||||
use Magento\Framework\DB\Adapter\AdapterInterface;
|
||||
use Magento\Sales\Api\Data\OrderInterface;
|
||||
use Magento\Sales\Api\OrderRepositoryInterface;
|
||||
use Magento\Sales\Model\ResourceModel\Grid as AbstractGrid;
|
||||
use Magento\Sales\Model\ResourceModel\Order\Grid;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
|
||||
/**
|
||||
* Class for testing asynchronous inserts into grid.
|
||||
*/
|
||||
class GridAsyncInsertTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManager
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var GridAsyncInsert
|
||||
*/
|
||||
private $gridAsyncInsert;
|
||||
|
||||
/**
|
||||
* @var AdapterInterface
|
||||
*/
|
||||
private $connection;
|
||||
|
||||
/**
|
||||
* @var OrderRepositoryInterface
|
||||
*/
|
||||
private $orderRepository;
|
||||
|
||||
/**
|
||||
* @var AbstractGrid
|
||||
*/
|
||||
private $grid;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var ResourceConnection $resourceConnection */
|
||||
$resourceConnection = $this->objectManager->get(ResourceConnection::class);
|
||||
$this->connection = $resourceConnection->getConnection('sales');
|
||||
$this->orderRepository = $this->objectManager->get(OrderRepositoryInterface::class);
|
||||
$this->grid = $this->objectManager->get(Grid::class);
|
||||
|
||||
$this->gridAsyncInsert = $this->objectManager->create(
|
||||
GridAsyncInsert::class,
|
||||
[
|
||||
'entityGrid' => $this->grid,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a case when order's grid should be updated asynchronously.
|
||||
*
|
||||
* @magentoConfigFixture default/dev/grid/async_indexing 1
|
||||
* @magentoDataFixture Magento/Sales/_files/order.php
|
||||
* @return void
|
||||
*/
|
||||
public function testExecuteAsyncUpdateOrderGrid()
|
||||
{
|
||||
$order = $this->getOrder('100000001');
|
||||
$this->performUpdateAssertions($order);
|
||||
|
||||
// to un-sync main table and grid table need to wait at least one second
|
||||
sleep(1);
|
||||
$order->setStatus('complete');
|
||||
$this->orderRepository->save($order);
|
||||
|
||||
$gridRow = $this->getGridRow($order->getEntityId());
|
||||
self::assertNotEquals($order->getStatus(), $gridRow['status']);
|
||||
|
||||
$this->gridAsyncInsert->asyncInsert();
|
||||
$this->performUpdateAssertions($order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads order entity by provided order increment ID.
|
||||
*
|
||||
* @param string $incrementId
|
||||
* @return OrderInterface
|
||||
*/
|
||||
private function getOrder(string $incrementId) : OrderInterface
|
||||
{
|
||||
/** @var SearchCriteria $searchCriteria */
|
||||
$searchCriteria = $this->objectManager->get(SearchCriteriaBuilder::class)
|
||||
->addFilter('increment_id', $incrementId)
|
||||
->create();
|
||||
|
||||
$items = $this->orderRepository->getList($searchCriteria)
|
||||
->getItems();
|
||||
|
||||
return array_pop($items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets row from `sales_order_grid` table by order's ID.
|
||||
*
|
||||
* @param int $entityId
|
||||
* @return array
|
||||
*/
|
||||
private function getGridRow(int $entityId) : array
|
||||
{
|
||||
$tableName = $this->grid->getGridTable();
|
||||
$select = $this->connection->select()
|
||||
->from($tableName)
|
||||
->where($tableName . '.entity_id = ?', $entityId);
|
||||
|
||||
return $this->connection->fetchRow($select);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform assertions for updating grid test.
|
||||
*
|
||||
* @param OrderInterface $order
|
||||
* @return void
|
||||
*/
|
||||
private function performUpdateAssertions(OrderInterface $order)
|
||||
{
|
||||
$gridRow = $this->getGridRow($order->getEntityId());
|
||||
|
||||
self::assertEquals($order->getStatus(), $gridRow['status']);
|
||||
self::assertEquals($order->getUpdatedAt(), $gridRow['updated_at']);
|
||||
}
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Sales\Model;
|
||||
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Sales\Api\Data\InvoiceInterface;
|
||||
use Magento\Sales\Api\Data\InvoiceSearchResultInterface;
|
||||
use Magento\Sales\Model\Order\Email\Container\InvoiceIdentity;
|
||||
use Magento\Sales\Model\Order\Email\Sender\InvoiceSender;
|
||||
use Magento\Sales\Model\Spi\InvoiceResourceInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Mail\Template\TransportBuilderMock;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Checks sending emails to customers after creation/modification of invoice.
|
||||
*
|
||||
* @see \Magento\Sales\Model\EmailSenderHandler
|
||||
*/
|
||||
class InvoiceEmailSenderHandlerTest extends TestCase
|
||||
{
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var InvoiceSearchResultInterface */
|
||||
private $entityCollection;
|
||||
|
||||
/** @var EmailSenderHandler */
|
||||
private $emailSenderHandler;
|
||||
|
||||
/** @var InvoiceIdentity */
|
||||
private $invoiceIdentity;
|
||||
|
||||
/** @var InvoiceSender */
|
||||
private $invoiceSender;
|
||||
|
||||
/** @var InvoiceResourceInterface */
|
||||
private $entityResource;
|
||||
|
||||
/** @var TransportBuilderMock */
|
||||
private $transportBuilderMock;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->invoiceIdentity = $this->objectManager->get(InvoiceIdentity::class);
|
||||
$this->invoiceSender = $this->objectManager->get(InvoiceSender::class);
|
||||
$this->entityResource = $this->objectManager->get(InvoiceResourceInterface::class);
|
||||
$this->entityCollection = $this->objectManager->create(InvoiceSearchResultInterface::class);
|
||||
$this->emailSenderHandler = $this->objectManager->create(
|
||||
EmailSenderHandler::class,
|
||||
[
|
||||
'emailSender' => $this->invoiceSender,
|
||||
'entityResource' => $this->entityResource,
|
||||
'entityCollection' => $this->entityCollection,
|
||||
'identityContainer' => $this->invoiceIdentity,
|
||||
]
|
||||
);
|
||||
$this->transportBuilderMock = $this->objectManager->get(TransportBuilderMock::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation disabled
|
||||
* @magentoDataFixture Magento/Sales/_files/invoice_list_different_stores.php
|
||||
* @magentoConfigFixture default/sales_email/general/async_sending 1
|
||||
* @magentoConfigFixture fixture_second_store_store sales_email/invoice/enabled 0
|
||||
* @return void
|
||||
*/
|
||||
public function testInvoiceEmailSenderExecute(): void
|
||||
{
|
||||
$invoiceCollection = clone $this->entityCollection;
|
||||
$invoiceCollection->addFieldToFilter('send_email', ['eq' => 1]);
|
||||
$invoiceCollection->addFieldToFilter(InvoiceInterface::EMAIL_SENT, ['null' => true]);
|
||||
$this->emailSenderHandler->sendEmails();
|
||||
$this->assertEquals(1, $invoiceCollection->getTotalCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation disabled
|
||||
* @magentoDataFixture Magento/Sales/_files/invoice_with_send_email_flag.php
|
||||
* @magentoConfigFixture default/sales_email/general/async_sending 1
|
||||
* @return void
|
||||
*/
|
||||
public function testSendEmailsCheckEmailReceived(): void
|
||||
{
|
||||
$invoiceCollection = clone $this->entityCollection;
|
||||
$this->emailSenderHandler->sendEmails();
|
||||
/** @var InvoiceInterface $invoice */
|
||||
$invoice = $invoiceCollection->getFirstItem();
|
||||
$this->assertNotNull($invoice->getId());
|
||||
$message = $this->transportBuilderMock->getSentMessage();
|
||||
$this->assertNotNull($message, 'The message is expected to be received');
|
||||
$subject = __('Invoice for your %1 order', $invoice->getStore()->getFrontendName())->render();
|
||||
$this->assertEquals($message->getSubject(), $subject);
|
||||
$this->assertStringContainsString(
|
||||
sprintf(
|
||||
"Your Invoice #%s for Order #%s",
|
||||
$invoice->getIncrementId(),
|
||||
$invoice->getOrder()->getIncrementId()
|
||||
),
|
||||
$message->getBody()->getParts()[0]->getRawContent()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Sales\Model\Order\Address;
|
||||
|
||||
use Magento\Config\Model\Config\Factory;
|
||||
use Magento\Config\Model\ResourceModel\Config as ConfigResourceModel;
|
||||
use Magento\Framework\App\Config;
|
||||
use Magento\Framework\Locale\TranslatedLists;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Sales\Model\Order\Address as OrderAddress;
|
||||
use Magento\Sales\Model\Order\Address\Renderer as OrderAddressRenderer;
|
||||
use Magento\Store\Model\Store;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test for \Magento\Sales\Model\Order\Address\Renderer.
|
||||
*/
|
||||
class RendererTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var OrderAddressRenderer
|
||||
*/
|
||||
private $orderAddressRenderer;
|
||||
|
||||
/**
|
||||
* @var ConfigResourceModel
|
||||
*/
|
||||
private $configResourceModel;
|
||||
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* Set up
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->orderAddressRenderer = $this->objectManager->get(OrderAddressRenderer::class);
|
||||
$this->configResourceModel = $this->objectManager->get(ConfigResourceModel::class);
|
||||
$this->config = $this->objectManager->get(Config::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/order_fixture_store.php
|
||||
* @magentoDbIsolation disabled
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testFormat()
|
||||
{
|
||||
$addressTemplates = [
|
||||
'text' => 'text_customized',
|
||||
'oneline' => 'oneline_customized',
|
||||
'html' => 'html_customized',
|
||||
'pdf' => 'pdf_customized',
|
||||
];
|
||||
|
||||
/** @var Store $store */
|
||||
$store = $this->objectManager->create(Store::class);
|
||||
$storeId = $store->load('fixturestore')->getStoreId();
|
||||
|
||||
$this->configResourceModel->saveConfig(
|
||||
'customer/address_templates/text',
|
||||
$addressTemplates['text'],
|
||||
'stores',
|
||||
$storeId
|
||||
);
|
||||
$this->configResourceModel->saveConfig(
|
||||
'customer/address_templates/oneline',
|
||||
$addressTemplates['oneline'],
|
||||
'stores',
|
||||
$storeId
|
||||
);
|
||||
$this->configResourceModel->saveConfig(
|
||||
'customer/address_templates/html',
|
||||
$addressTemplates['html'],
|
||||
'stores',
|
||||
$storeId
|
||||
);
|
||||
$this->configResourceModel->saveConfig(
|
||||
'customer/address_templates/pdf',
|
||||
$addressTemplates['pdf'],
|
||||
'stores',
|
||||
$storeId
|
||||
);
|
||||
$this->config->clean();
|
||||
|
||||
/** @var Order $order */
|
||||
$order = $this->objectManager->create(Order::class)
|
||||
->loadByIncrementId('100000004');
|
||||
|
||||
/** @var OrderAddress $address */
|
||||
$address = $order->getBillingAddress();
|
||||
|
||||
$this->assertEquals($addressTemplates['text'], $this->orderAddressRenderer->format($address, 'text'));
|
||||
$this->assertEquals($addressTemplates['oneline'], $this->orderAddressRenderer->format($address, 'oneline'));
|
||||
$this->assertEquals($addressTemplates['html'], $this->orderAddressRenderer->format($address, 'html'));
|
||||
$this->assertEquals($addressTemplates['pdf'], $this->orderAddressRenderer->format($address, 'pdf'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify customer address attributes (e.g. Company) are respecting website scope configuration.
|
||||
*
|
||||
* @magentoDataFixture Magento/Store/_files/second_website_with_store_group_and_store.php
|
||||
* @magentoDataFixture Magento/Sales/_files/order_on_second_website.php
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoDbIsolation disabled
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testFormatNonDisplayedCompanyField()
|
||||
{
|
||||
$storeManager = $this->objectManager->get(StoreManagerInterface::class);
|
||||
$website = $storeManager->getWebsites(false, true)['test'];
|
||||
$configData = [
|
||||
'section' => 'customer',
|
||||
'website' => $website->getId(),
|
||||
'store' => null,
|
||||
'groups' => [
|
||||
'address' => [
|
||||
'fields' => [
|
||||
'company_show' => ['value' => ''],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
$configFactory = $this->objectManager->get(Factory::class);
|
||||
$config = $configFactory->create(['data' => $configData]);
|
||||
$config->save();
|
||||
$orderFixtureStore = $this->objectManager->create(Order::class)->loadByIncrementId('100000001');
|
||||
$address = $orderFixtureStore->getBillingAddress();
|
||||
self::assertStringNotContainsString('Test Company', $this->orderAddressRenderer->format($address, 'html'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Order country will be translated to locale on which was placed an order
|
||||
*
|
||||
* @magentoDbIsolation disabled
|
||||
* @magentoDataFixture Magento/Sales/_files/order_fixture_store.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRenderOrderAddressCountry(): void
|
||||
{
|
||||
/** @var TranslatedLists $localeResolver */
|
||||
$this->objectManager->create(TranslatedLists::class, ['locale' => 'ko_KR']);
|
||||
|
||||
/** @var Order $order */
|
||||
$order = $this->objectManager->create(Order::class)
|
||||
->loadByIncrementId('100000004');
|
||||
|
||||
/** @var OrderAddress $address */
|
||||
$address = $order->getBillingAddress();
|
||||
|
||||
$this->assertStringContainsString(
|
||||
'United States',
|
||||
$this->orderAddressRenderer->format($address, 'html')
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Sales\Model\Order;
|
||||
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Sales\Api\Data\OrderAddressInterface;
|
||||
use Magento\Sales\Api\OrderAddressRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Framework\Api\FilterBuilder;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Framework\Api\SortOrderBuilder;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Class AddressRepositoryTest
|
||||
*/
|
||||
class AddressRepositoryTest extends TestCase
|
||||
{
|
||||
/** @var AddressRepository */
|
||||
protected $repository;
|
||||
|
||||
/** @var SortOrderBuilder */
|
||||
private $sortOrderBuilder;
|
||||
|
||||
/** @var FilterBuilder */
|
||||
private $filterBuilder;
|
||||
|
||||
/** @var SearchCriteriaBuilder */
|
||||
private $searchCriteriaBuilder;
|
||||
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->repository = $this->objectManager->get(AddressRepository::class);
|
||||
$this->searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class);
|
||||
$this->filterBuilder = $this->objectManager->get(FilterBuilder::class);
|
||||
$this->sortOrderBuilder = $this->objectManager->get(SortOrderBuilder::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for get list with multiple filters and sorting
|
||||
*
|
||||
* @return void
|
||||
* @magentoDataFixture Magento/Sales/_files/address_list.php
|
||||
*/
|
||||
public function testGetListWithMultipleFiltersAndSorting(): void
|
||||
{
|
||||
$filter1 = $this->filterBuilder
|
||||
->setField('postcode')
|
||||
->setConditionType('neq')
|
||||
->setValue('ZX0789A')
|
||||
->create();
|
||||
$filter2 = $this->filterBuilder
|
||||
->setField('address_type')
|
||||
->setValue('billing')
|
||||
->create();
|
||||
$filter3 = $this->filterBuilder
|
||||
->setField('city')
|
||||
->setValue('Ena4ka')
|
||||
->create();
|
||||
$sortOrder = $this->sortOrderBuilder
|
||||
->setField('region_id')
|
||||
->setDirection('DESC')
|
||||
->create();
|
||||
|
||||
$this->searchCriteriaBuilder->addFilters([$filter1]);
|
||||
$this->searchCriteriaBuilder->addFilters([$filter2, $filter3]);
|
||||
$this->searchCriteriaBuilder->addSortOrder($sortOrder);
|
||||
$searchCriteria = $this->searchCriteriaBuilder->create();
|
||||
/** @var \Magento\Sales\Api\Data\OrderAddressSearchResultInterface $result */
|
||||
$result = $this->repository->getList($searchCriteria);
|
||||
$items = $result->getItems();
|
||||
$this->assertCount(2, $items);
|
||||
$this->assertEquals('ZX0789', array_shift($items)->getPostcode());
|
||||
$this->assertEquals('47676', array_shift($items)->getPostcode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for formatting custom sales address multi-attribute
|
||||
*
|
||||
* @return void
|
||||
* @magentoDataFixture Magento/Sales/_files/order_address_with_multi_attribute.php
|
||||
*/
|
||||
public function testFormatSalesAddressCustomMultiAttribute(): void
|
||||
{
|
||||
$address = $this->objectManager->get(OrderAddressInterface::class)
|
||||
->load('multiattribute@example.com', 'email');
|
||||
$address->setData('fixture_address_multiselect_attribute', ['dog', 'cat']);
|
||||
$address->setData('fixture_address_multiline_attribute', ['dog', 'cat']);
|
||||
|
||||
$this->objectManager->get(OrderAddressRepositoryInterface::class)
|
||||
->save($address);
|
||||
$this->assertEquals('dog,cat', $address->getData('fixture_address_multiselect_attribute'));
|
||||
$this->assertEquals('dog'.PHP_EOL.'cat', $address->getData('fixture_address_multiline_attribute'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Sales\Model\Order;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
class AddressTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/** @var Address */
|
||||
protected $_model;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_model = Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Order\Address::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/order.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_address.php
|
||||
*/
|
||||
public function testSave()
|
||||
{
|
||||
/** @var \Magento\Sales\Model\Order $order */
|
||||
$order = Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Order::class);
|
||||
$order->loadByIncrementId('100000001');
|
||||
$this->_model->setOrder($order);
|
||||
$this->_model->setEmail('co@co.co');
|
||||
$this->_model->setPostcode('12345');
|
||||
$this->_model->setLastname('LastName');
|
||||
$this->_model->setStreet('Street');
|
||||
$this->_model->setCity('City');
|
||||
$this->_model->setTelephone('123-45-67');
|
||||
$this->_model->setCountryId(1);
|
||||
$this->_model->setFirstname('FirstName');
|
||||
$this->_model->setAddressType('billing');
|
||||
$this->_model->setRegionId(1);
|
||||
$this->_model->save();
|
||||
$this->assertEquals($order->getId(), $this->_model->getParentId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Sales\Model\Order;
|
||||
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Quote\Model\QuoteIdMask;
|
||||
use Magento\Sales\Model\OrderRepository;
|
||||
use Magento\Quote\Model\QuoteIdMaskFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Quote\Api\GuestCartManagementInterface;
|
||||
use Magento\Checkout\Model\Session as CheckoutSession;
|
||||
|
||||
/**
|
||||
* Class BackOrderTest
|
||||
*
|
||||
* Integration test to ensure that when the stockState->checkQuoteItemQty call
|
||||
* returns a quantity to be backordered, that this value is added to the QuoteItem
|
||||
* and saved into the OrderItem
|
||||
*/
|
||||
class BackOrderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var QuoteIdMaskFactory
|
||||
*/
|
||||
private $quoteIdMaskFactory;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->quoteIdMaskFactory = $this->objectManager->get(QuoteIdMaskFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/quote_with_backorder.php
|
||||
* @return void
|
||||
*/
|
||||
public function testCreateOrderWithBackorders()
|
||||
{
|
||||
/** @var Quote $quote */
|
||||
$quote = $this->objectManager->create(Quote::class);
|
||||
$quote->load('test01', 'reserved_order_id');
|
||||
|
||||
/** @var CheckoutSession $checkoutSession */
|
||||
$checkoutSession = $this->objectManager->get(CheckoutSession::class);
|
||||
$checkoutSession->setQuoteId($quote->getId());
|
||||
|
||||
/** @var QuoteIdMask $quoteIdMask */
|
||||
$quoteIdMask = $this->quoteIdMaskFactory->create();
|
||||
$quoteIdMask->load($quote->getId(), 'quote_id');
|
||||
$cartId = $quoteIdMask->getMaskedId();
|
||||
|
||||
/** @var GuestCartManagementInterface $cartManagement */
|
||||
$cartManagement = $this->objectManager->get(GuestCartManagementInterface::class);
|
||||
$orderId = $cartManagement->placeOrder($cartId);
|
||||
|
||||
//The order should have 10 backordered items
|
||||
/** @var Order $order */
|
||||
$order = $this->objectManager->get(OrderRepository::class)->get($orderId);
|
||||
$this->assertNotNull($order);
|
||||
$orderitem = $order->getAllItems()[0];
|
||||
$this->assertEquals($orderitem->getQtyBackordered(), 10);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Sales\Model\Order;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Sales\Model\Order\Config
|
||||
*/
|
||||
class ConfigTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManager
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
private $orderConfig;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->orderConfig = $this->objectManager->create(Config::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Correct display of the list of "Order States" after assigning
|
||||
* the state "complete" to a custom order status.
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/order_status_assign_state_complete.php
|
||||
*/
|
||||
public function testCorrectCompleteStatusInStatesList()
|
||||
{
|
||||
$allStates = $this->orderConfig->getStates();
|
||||
/** @var Status $completeStatus */
|
||||
$completeStatus = $this->objectManager->create(Status::class)
|
||||
->load(\Magento\Sales\Model\Order::STATE_COMPLETE);
|
||||
$completeState = $allStates[$completeStatus->getStatus()];
|
||||
|
||||
$this->assertEquals($completeStatus->getLabel(), $completeState->getText());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Mask Status For Area
|
||||
*
|
||||
* @param string $code
|
||||
* @param string $expected
|
||||
* @dataProvider dataProviderForTestMaskStatusForArea
|
||||
*/
|
||||
public function testMaskStatusForArea(string $code, string $expected)
|
||||
{
|
||||
$result = $this->orderConfig->getStatusFrontendLabel($code);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function dataProviderForTestMaskStatusForArea()
|
||||
{
|
||||
return [
|
||||
['fraud', 'Suspected Fraud'],
|
||||
['processing', 'Processing'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Sales\Model\Order;
|
||||
|
||||
use Magento\Checkout\Model\Session as CheckoutSession;
|
||||
use Magento\Framework\Data\Form\FormKey;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Quote\Api\GuestCartManagementInterface;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Quote\Model\QuoteIdMask;
|
||||
use Magento\Quote\Model\QuoteIdMaskFactory;
|
||||
use Magento\Sales\Model\OrderRepository;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Mail\Template\TransportBuilderMock;
|
||||
use PHPUnit\Framework\Constraint\StringContains;
|
||||
|
||||
/**
|
||||
* Class verifies order creation.
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class CreateTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var TransportBuilderMock
|
||||
*/
|
||||
private $transportBuilder;
|
||||
|
||||
/**
|
||||
* @var QuoteIdMaskFactory
|
||||
*/
|
||||
private $quoteIdMaskFactory;
|
||||
|
||||
/**
|
||||
* @var FormKey
|
||||
*/
|
||||
private $formKey;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->transportBuilder = $this->objectManager->get(TransportBuilderMock::class);
|
||||
$this->quoteIdMaskFactory = $this->objectManager->get(QuoteIdMaskFactory::class);
|
||||
$this->formKey = $this->objectManager->get(FormKey::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/guest_quote_with_addresses.php
|
||||
* @return void
|
||||
*/
|
||||
public function testSendEmailOnOrderPlace(): void
|
||||
{
|
||||
/** @var Quote $quote */
|
||||
$quote = $this->objectManager->create(Quote::class);
|
||||
$quote->load('guest_quote', 'reserved_order_id');
|
||||
|
||||
$checkoutSession = $this->objectManager->get(CheckoutSession::class);
|
||||
$checkoutSession->setQuoteId($quote->getId());
|
||||
|
||||
/** @var QuoteIdMask $quoteIdMask */
|
||||
$quoteIdMask = $this->quoteIdMaskFactory->create();
|
||||
$quoteIdMask->load($quote->getId(), 'quote_id');
|
||||
$cartId = $quoteIdMask->getMaskedId();
|
||||
|
||||
/** @var GuestCartManagementInterface $cartManagement */
|
||||
$cartManagement = $this->objectManager->get(GuestCartManagementInterface::class);
|
||||
$orderId = $cartManagement->placeOrder($cartId);
|
||||
$order = $this->objectManager->get(OrderRepository::class)->get($orderId);
|
||||
|
||||
$message = $this->transportBuilder->getSentMessage();
|
||||
$subject = __('Your %1 order confirmation', $order->getStore()->getFrontendName())->render();
|
||||
$assert = $this->logicalAnd(
|
||||
new StringContains($order->getBillingAddress()->getName()),
|
||||
new StringContains(
|
||||
'Thank you for your order from ' . $order->getStore()->getFrontendName()
|
||||
),
|
||||
new StringContains(
|
||||
"Your Order <span class=\"no-link\">#{$order->getIncrementId()}</span>"
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals($message->getSubject(), $subject);
|
||||
$this->assertThat($message->getBody()->getParts()[0]->getRawContent(), $assert);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Sales\Model\Order;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Sales\Api\InvoiceRepositoryInterface;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Test for CreditmemoFactory class.
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class CreditmemoFactoryTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Placeholder for order item id field.
|
||||
*/
|
||||
const ORDER_ITEM_ID_PLACEHOLDER = 'id_item_';
|
||||
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var CreditmemoFactory
|
||||
*/
|
||||
private $creditmemoFactory;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->creditmemoFactory = $this->objectManager->create(CreditmemoFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a case when creditmemo created from the order.
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/order_with_bundle_and_invoiced.php
|
||||
* @dataProvider createByOrderDataProvider
|
||||
* @param array $creditmemoData
|
||||
* @param int $expectedQty
|
||||
*/
|
||||
public function testCreateByOrder(array $creditmemoData, $expectedQty)
|
||||
{
|
||||
$order = $this->getOrder('100000001');
|
||||
$creditmemoData = $this->prepareCreditMemoData($order, $creditmemoData);
|
||||
$creditmemo = $this->creditmemoFactory->createByOrder($order, $creditmemoData);
|
||||
self::assertEquals($expectedQty, $creditmemo->getTotalQty(), 'Creditmemo has wrong total qty.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function createByOrderDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'creditmemoData' => [
|
||||
'qtys' => [
|
||||
self::ORDER_ITEM_ID_PLACEHOLDER . '2' => 2,
|
||||
self::ORDER_ITEM_ID_PLACEHOLDER . '3' => 10,
|
||||
],
|
||||
],
|
||||
'expectedQty' => 12,
|
||||
],
|
||||
[
|
||||
'creditmemoData' => [
|
||||
'qtys' => [
|
||||
self::ORDER_ITEM_ID_PLACEHOLDER . '1' => 2,
|
||||
self::ORDER_ITEM_ID_PLACEHOLDER . '2' => 2,
|
||||
self::ORDER_ITEM_ID_PLACEHOLDER . '3' => 10,
|
||||
],
|
||||
],
|
||||
'expectedQty' => 14,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a case when creditmemo created from the invoice.
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/invoice_with_bundle.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCreateByInvoice()
|
||||
{
|
||||
$invoice = $this->getInvoice('100000001');
|
||||
$creditmemo = $this->creditmemoFactory->createByInvoice($invoice);
|
||||
self::assertEquals(14, $creditmemo->getTotalQty(), 'Creditmemo has wrong total qty.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare Creditmemo data.
|
||||
*
|
||||
* @param Order $order
|
||||
* @param array $creditmemoData
|
||||
* @return array
|
||||
*/
|
||||
private function prepareCreditMemoData(Order $order, array $creditmemoData): array
|
||||
{
|
||||
$result = [];
|
||||
$orderItems = $order->getAllItems();
|
||||
foreach ($creditmemoData['qtys'] as $key => $item) {
|
||||
$result[$orderItems[$this->prepareOrderItemKey($key)]->getId()] = $item;
|
||||
}
|
||||
$creditmemoData['qtys'] = $result;
|
||||
|
||||
return $creditmemoData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare order item key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return int
|
||||
*/
|
||||
private function prepareOrderItemKey($key)
|
||||
{
|
||||
return str_replace(self::ORDER_ITEM_ID_PLACEHOLDER, '', $key) - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves order by increment ID.
|
||||
*
|
||||
* @param string $incrementId
|
||||
* @return Order
|
||||
*/
|
||||
private function getOrder(string $incrementId): Order
|
||||
{
|
||||
/** @var Order $order */
|
||||
$order = $this->objectManager->create(Order::class);
|
||||
$order->loadByIncrementId($incrementId);
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves invoice by increment ID.
|
||||
*
|
||||
* @param string $incrementId
|
||||
* @return Invoice
|
||||
*/
|
||||
private function getInvoice(string $incrementId): Invoice
|
||||
{
|
||||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class);
|
||||
$searchCriteria = $searchCriteriaBuilder
|
||||
->addFilter('increment_id', $incrementId)
|
||||
->create();
|
||||
/** @var InvoiceRepositoryInterface $repository */
|
||||
$repository = $this->objectManager->get(InvoiceRepositoryInterface::class);
|
||||
$items = $repository->getList($searchCriteria)->getItems();
|
||||
|
||||
return array_pop($items);
|
||||
}
|
||||
}
|
||||
+215
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Sales\Model\Order\Email\Sender;
|
||||
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\Customer\Model\ResourceModel\CustomerRepository;
|
||||
use Magento\Framework\App\Area;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Sales\Model\Order\Creditmemo;
|
||||
use Magento\Sales\Model\Order\Email\Container\CreditmemoIdentity;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Magento\TestFramework\ErrorLog\Logger;
|
||||
|
||||
class CreditmemoSenderTest extends TestCase
|
||||
{
|
||||
private const NEW_CUSTOMER_EMAIL = 'new.customer@example.com';
|
||||
private const OLD_CUSTOMER_EMAIL = 'customer@example.com';
|
||||
private const ORDER_EMAIL = 'customer@example.com';
|
||||
|
||||
/**
|
||||
* @var CustomerRepository
|
||||
*/
|
||||
private $customerRepository;
|
||||
|
||||
/** @var Logger */
|
||||
private $logger;
|
||||
|
||||
/** @var int */
|
||||
private $minErrorDefaultValue;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->customerRepository = Bootstrap::getObjectManager()->get(CustomerRepositoryInterface::class);
|
||||
$this->logger = Bootstrap::getObjectManager()->get(Logger::class);
|
||||
|
||||
$reflection = new \ReflectionClass(get_class($this->logger));
|
||||
$reflectionProperty = $reflection->getProperty('minimumErrorLevel');
|
||||
$reflectionProperty->setAccessible(true);
|
||||
$this->minErrorDefaultValue = $reflectionProperty->getValue($this->logger);
|
||||
$reflectionProperty->setValue($this->logger, 400);
|
||||
$this->logger->clearMessages();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/order.php
|
||||
*/
|
||||
public function testSend()
|
||||
{
|
||||
Bootstrap::getInstance()->loadArea(Area::AREA_FRONTEND);
|
||||
$order = Bootstrap::getObjectManager()->create(Order::class);
|
||||
$order->loadByIncrementId('100000001');
|
||||
$order->setCustomerEmail('customer@example.com');
|
||||
|
||||
$creditmemo = Bootstrap::getObjectManager()->create(Creditmemo::class);
|
||||
$creditmemo->setOrder($order);
|
||||
|
||||
$this->assertEmpty($creditmemo->getEmailSent());
|
||||
|
||||
$creditmemoSender = Bootstrap::getObjectManager()->create(CreditmemoSender::class);
|
||||
$result = $creditmemoSender->send($creditmemo, true);
|
||||
$this->assertEmpty($this->logger->getMessages());
|
||||
|
||||
$this->assertTrue($result);
|
||||
$this->assertNotEmpty($creditmemo->getEmailSent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that when a customer email is modified, the credit memo is sent to the new email
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/order_with_customer.php
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
public function testSendWhenCustomerEmailWasModified()
|
||||
{
|
||||
$customer = $this->customerRepository->getById(1);
|
||||
$customer->setEmail(self::NEW_CUSTOMER_EMAIL);
|
||||
$this->customerRepository->save($customer);
|
||||
|
||||
$order = $this->createOrder();
|
||||
$creditmemo = $this->createCreditmemo($order);
|
||||
|
||||
$this->assertEmpty($creditmemo->getEmailSent());
|
||||
|
||||
$craditmemoIdentity = $this->createCreditMemoIdentity();
|
||||
$creditmemoSender = $this->createCreditMemoSender($craditmemoIdentity);
|
||||
$result = $creditmemoSender->send($creditmemo, true);
|
||||
$this->assertEmpty($this->logger->getMessages());
|
||||
|
||||
$this->assertEquals(self::NEW_CUSTOMER_EMAIL, $craditmemoIdentity->getCustomerEmail());
|
||||
$this->assertTrue($result);
|
||||
$this->assertNotEmpty($creditmemo->getEmailSent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that when a customer email is not modified, the credit memo is sent to the old customer email
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/order_with_customer.php
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
public function testSendWhenCustomerEmailWasNotModified()
|
||||
{
|
||||
$order = $this->createOrder();
|
||||
$creditmemo = $this->createCreditmemo($order);
|
||||
|
||||
$this->assertEmpty($creditmemo->getEmailSent());
|
||||
|
||||
$craditmemoIdentity = $this->createCreditMemoIdentity();
|
||||
$creditmemoSender = $this->createCreditMemoSender($craditmemoIdentity);
|
||||
$result = $creditmemoSender->send($creditmemo, true);
|
||||
$this->assertEmpty($this->logger->getMessages());
|
||||
|
||||
$this->assertEquals(self::OLD_CUSTOMER_EMAIL, $craditmemoIdentity->getCustomerEmail());
|
||||
$this->assertTrue($result);
|
||||
$this->assertNotEmpty($creditmemo->getEmailSent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that when an order has not customer the credit memo is sent to the order email
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/order.php
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
public function testSendWithoutCustomer()
|
||||
{
|
||||
$order = $this->createOrder();
|
||||
$creditmemo = $this->createCreditmemo($order);
|
||||
|
||||
$this->assertEmpty($creditmemo->getEmailSent());
|
||||
|
||||
$creditmemoIdentity = $this->createCreditMemoIdentity();
|
||||
$creditmemoSender = $this->createCreditMemoSender($creditmemoIdentity);
|
||||
$result = $creditmemoSender->send($creditmemo, true);
|
||||
$this->assertEmpty($this->logger->getMessages());
|
||||
|
||||
$this->assertEquals(self::ORDER_EMAIL, $creditmemoIdentity->getCustomerEmail());
|
||||
$this->assertTrue($result);
|
||||
$this->assertNotEmpty($creditmemo->getEmailSent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify order will be marked send email on non default store in case default store order email sent is disabled.
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/order_fixture_store.php
|
||||
* @magentoConfigFixture default/sales_email/creditmemo/enabled 0
|
||||
* @magentoConfigFixture default/sales_email/general/async_sending 1
|
||||
* @magentoConfigFixture fixturestore/sales_email/creditmemo/enabled 1
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testSendCreditmemeoEmailFromNonDefaultStore()
|
||||
{
|
||||
$storeManager = Bootstrap::getObjectManager()->get(StoreManagerInterface::class);
|
||||
$store = $storeManager->getStore('fixturestore');
|
||||
$order = Bootstrap::getObjectManager()->create(Order::class);
|
||||
$order->loadByIncrementIdAndStoreId('100000001', $store->getId());
|
||||
$order->setCustomerEmail('customer@example.com');
|
||||
$creditmemo = Bootstrap::getObjectManager()->create(Creditmemo::class);
|
||||
$creditmemo->setOrder($order);
|
||||
$creditmemoSender = Bootstrap::getObjectManager()->create(CreditmemoSender::class);
|
||||
$result = $creditmemoSender->send($creditmemo);
|
||||
$this->assertEmpty($this->logger->getMessages());
|
||||
$this->assertFalse($result);
|
||||
$this->assertTrue($creditmemo->getSendEmail());
|
||||
}
|
||||
|
||||
private function createCreditmemo(Order $order): Creditmemo
|
||||
{
|
||||
$creditmemo = Bootstrap::getObjectManager()->create(Creditmemo::class);
|
||||
$creditmemo->setOrder($order);
|
||||
return $creditmemo;
|
||||
}
|
||||
|
||||
private function createOrder(): Order
|
||||
{
|
||||
$order = Bootstrap::getObjectManager()->create(Order::class);
|
||||
$order->loadByIncrementId('100000001');
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
private function createCreditMemoIdentity(): CreditmemoIdentity
|
||||
{
|
||||
return Bootstrap::getObjectManager()->create(CreditmemoIdentity::class);
|
||||
}
|
||||
|
||||
private function createCreditMemoSender(CreditmemoIdentity $creditmemoIdentity): CreditmemoSender
|
||||
{
|
||||
return Bootstrap::getObjectManager()
|
||||
->create(
|
||||
CreditmemoSender::class,
|
||||
[
|
||||
'identityContainer' => $creditmemoIdentity,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$reflectionProperty = new \ReflectionProperty(get_class($this->logger), 'minimumErrorLevel');
|
||||
$reflectionProperty->setAccessible(true);
|
||||
$reflectionProperty->setValue($this->logger, $this->minErrorDefaultValue);
|
||||
}
|
||||
}
|
||||
+259
@@ -0,0 +1,259 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Sales\Model\Order\Email\Sender;
|
||||
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Sales\Api\Data\InvoiceInterface;
|
||||
use Magento\Sales\Api\Data\InvoiceInterfaceFactory;
|
||||
use Magento\Sales\Api\Data\OrderInterface;
|
||||
use Magento\Sales\Api\Data\OrderInterfaceFactory;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Sales\Model\Order\Email\Container\InvoiceIdentity;
|
||||
use Magento\Sales\Model\Order\Invoice;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Mail\Template\TransportBuilderMock;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Magento\TestFramework\ErrorLog\Logger;
|
||||
|
||||
/**
|
||||
* Checks the sending of order invoice email to the customer.
|
||||
*
|
||||
* @see \Magento\Sales\Model\Order\Email\Sender\InvoiceSender
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class InvoiceSenderTest extends TestCase
|
||||
{
|
||||
private const NEW_CUSTOMER_EMAIL = 'new.customer@example.com';
|
||||
private const OLD_CUSTOMER_EMAIL = 'customer@example.com';
|
||||
private const ORDER_EMAIL = 'customer@example.com';
|
||||
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var CustomerRepositoryInterface */
|
||||
private $customerRepository;
|
||||
|
||||
/** @var InvoiceSender */
|
||||
private $invoiceSender;
|
||||
|
||||
/** @var TransportBuilderMock */
|
||||
private $transportBuilderMock;
|
||||
|
||||
/** @var OrderInterfaceFactory */
|
||||
private $orderFactory;
|
||||
|
||||
/** @var InvoiceInterfaceFactory */
|
||||
private $invoiceFactory;
|
||||
|
||||
/** @var InvoiceIdentity */
|
||||
private $invoiceIdentity;
|
||||
|
||||
/** @var Logger */
|
||||
private $logger;
|
||||
|
||||
/** @var int */
|
||||
private $minErrorDefaultValue;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->customerRepository = $this->objectManager->get(CustomerRepositoryInterface::class);
|
||||
$this->invoiceSender = $this->objectManager->get(InvoiceSender::class);
|
||||
$this->transportBuilderMock = $this->objectManager->get(TransportBuilderMock::class);
|
||||
$this->orderFactory = $this->objectManager->get(OrderInterfaceFactory::class);
|
||||
$this->invoiceFactory = $this->objectManager->get(InvoiceInterfaceFactory::class);
|
||||
$this->invoiceIdentity = $this->objectManager->get(InvoiceIdentity::class);
|
||||
$this->logger = $this->objectManager->get(Logger::class);
|
||||
|
||||
$reflection = new \ReflectionClass(get_class($this->logger));
|
||||
$reflectionProperty = $reflection->getProperty('minimumErrorLevel');
|
||||
$reflectionProperty->setAccessible(true);
|
||||
$this->minErrorDefaultValue = $reflectionProperty->getValue($this->logger);
|
||||
$reflectionProperty->setValue($this->logger, 400);
|
||||
$this->logger->clearMessages();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/order.php
|
||||
* @magentoAppArea frontend
|
||||
* @return void
|
||||
*/
|
||||
public function testSend(): void
|
||||
{
|
||||
$order = $this->getOrder('100000001');
|
||||
$order->setCustomerEmail('customer@example.com');
|
||||
$invoice = $this->createInvoice($order);
|
||||
$invoice->setTotalQty(1);
|
||||
$invoice->setBaseSubtotal(50);
|
||||
$invoice->setBaseTaxAmount(10);
|
||||
$invoice->setBaseShippingAmount(5);
|
||||
|
||||
$this->assertEmpty($invoice->getEmailSent());
|
||||
$result = $this->invoiceSender->send($invoice, true);
|
||||
$this->assertEmpty($this->logger->getMessages());
|
||||
|
||||
$this->assertTrue($result);
|
||||
$this->assertNotEmpty($invoice->getEmailSent());
|
||||
$this->assertEquals($invoice->getBaseSubtotal(), $order->getBaseSubtotal());
|
||||
$this->assertEquals($invoice->getBaseTaxAmount(), $order->getBaseTaxAmount());
|
||||
$this->assertEquals($invoice->getBaseShippingAmount(), $order->getBaseShippingAmount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that when a customer email is modified, the invoice is sent to the new email
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/order_with_customer.php
|
||||
* @magentoAppArea frontend
|
||||
* @return void
|
||||
*/
|
||||
public function testSendWhenCustomerEmailWasModified(): void
|
||||
{
|
||||
$customer = $this->customerRepository->getById(1);
|
||||
$customer->setEmail(self::NEW_CUSTOMER_EMAIL);
|
||||
$this->customerRepository->save($customer);
|
||||
$order = $this->getOrder('100000001');
|
||||
$invoice = $this->createInvoice($order);
|
||||
|
||||
$this->assertEmpty($invoice->getEmailSent());
|
||||
$result = $this->invoiceSender->send($invoice, true);
|
||||
$this->assertEmpty($this->logger->getMessages());
|
||||
|
||||
$this->assertEquals(self::NEW_CUSTOMER_EMAIL, $this->invoiceIdentity->getCustomerEmail());
|
||||
$this->assertTrue($result);
|
||||
$this->assertNotEmpty($invoice->getEmailSent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that when a customer email is not modified, the invoice is sent to the old customer email
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/order_with_customer.php
|
||||
* @magentoAppArea frontend
|
||||
* @return void
|
||||
*/
|
||||
public function testSendWhenCustomerEmailWasNotModified(): void
|
||||
{
|
||||
$order = $this->getOrder('100000001');
|
||||
$invoice = $this->createInvoice($order);
|
||||
|
||||
$this->assertEmpty($invoice->getEmailSent());
|
||||
$result = $this->invoiceSender->send($invoice, true);
|
||||
$this->assertEmpty($this->logger->getMessages());
|
||||
|
||||
$this->assertEquals(self::OLD_CUSTOMER_EMAIL, $this->invoiceIdentity->getCustomerEmail());
|
||||
$this->assertTrue($result);
|
||||
$this->assertNotEmpty($invoice->getEmailSent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that when an order has not customer the invoice is sent to the order email
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/order.php
|
||||
* @magentoAppArea frontend
|
||||
* @return void
|
||||
*/
|
||||
public function testSendWithoutCustomer(): void
|
||||
{
|
||||
$order = $this->getOrder('100000001');
|
||||
$invoice = $this->createInvoice($order);
|
||||
|
||||
$this->assertEmpty($invoice->getEmailSent());
|
||||
$result = $this->invoiceSender->send($invoice, true);
|
||||
$this->assertEmpty($this->logger->getMessages());
|
||||
|
||||
$this->assertEquals(self::ORDER_EMAIL, $this->invoiceIdentity->getCustomerEmail());
|
||||
$this->assertTrue($result);
|
||||
$this->assertNotEmpty($invoice->getEmailSent());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/invoice.php
|
||||
* @magentoConfigFixture default/sales_email/general/async_sending 1
|
||||
* @return void
|
||||
*/
|
||||
public function testSendWithAsyncSendingEnabled(): void
|
||||
{
|
||||
$order = $this->getOrder('100000001');
|
||||
/** @var Invoice $invoice */
|
||||
$invoice = $order->getInvoiceCollection()
|
||||
->addAttributeToFilter(InvoiceInterface::ORDER_ID, $order->getID())
|
||||
->getFirstItem();
|
||||
$result = $this->invoiceSender->send($invoice);
|
||||
$this->assertEmpty($this->logger->getMessages());
|
||||
$this->assertFalse($result);
|
||||
$invoice = $order->getInvoiceCollection()->clear()->getFirstItem();
|
||||
$this->assertEmpty($invoice->getEmailSent());
|
||||
$this->assertEquals('1', $invoice->getSendEmail());
|
||||
$this->assertNull(
|
||||
$this->transportBuilderMock->getSentMessage(),
|
||||
'The message is not expected to be received.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify invoice will be marked send email on non default store in case default store email sent is disabled.
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/order_fixture_store.php
|
||||
* @magentoConfigFixture sales_email/general/async_sending 1
|
||||
* @magentoConfigFixture default_store sales_email/invoice/enabled 0
|
||||
* @magentoConfigFixture fixturestore_store sales_email/invoice/enabled 1
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testSendInvoiceEmailFromNonDefaultStore()
|
||||
{
|
||||
$order = Bootstrap::getObjectManager()->create(Order::class);
|
||||
$order->loadByIncrementId('100000004');
|
||||
$order->setCustomerEmail('customer@example.com');
|
||||
$invoice = $this->createInvoice($order);
|
||||
$result = $this->invoiceSender->send($invoice);
|
||||
$this->assertEmpty($this->logger->getMessages());
|
||||
$this->assertFalse($result);
|
||||
$this->assertTrue($invoice->getSendEmail());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create invoice and set order
|
||||
*
|
||||
* @param OrderInterface $order
|
||||
* @return InvoiceInterface
|
||||
*/
|
||||
private function createInvoice(OrderInterface $order): InvoiceInterface
|
||||
{
|
||||
/** @var Invoice $invoice */
|
||||
$invoice = $this->invoiceFactory->create();
|
||||
$invoice->setOrder($order);
|
||||
|
||||
return $invoice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get order by increment_id
|
||||
*
|
||||
* @param string $incrementId
|
||||
* @return OrderInterface
|
||||
*/
|
||||
private function getOrder(string $incrementId): OrderInterface
|
||||
{
|
||||
return $this->orderFactory->create()->loadByIncrementId($incrementId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$reflectionProperty = new \ReflectionProperty(get_class($this->logger), 'minimumErrorLevel');
|
||||
$reflectionProperty->setAccessible(true);
|
||||
$reflectionProperty->setValue($this->logger, $this->minErrorDefaultValue);
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Sales\Model\Order\Email\Sender;
|
||||
|
||||
use Magento\Framework\App\Area;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class OrderSenderTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var OrderSender
|
||||
*/
|
||||
private $orderSender;
|
||||
|
||||
/**
|
||||
* @inheirtDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->orderSender = Bootstrap::getObjectManager()->create(OrderSender::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/order.php
|
||||
*/
|
||||
public function testSendNewOrderEmail()
|
||||
{
|
||||
Bootstrap::getInstance()->loadArea(Area::AREA_FRONTEND);
|
||||
$order = Bootstrap::getObjectManager()->create(Order::class);
|
||||
$order->loadByIncrementId('100000001');
|
||||
$order->setCustomerEmail('customer@example.com');
|
||||
|
||||
$this->assertEmpty($order->getEmailSent());
|
||||
|
||||
$result = $this->orderSender->send($order);
|
||||
|
||||
$this->assertTrue($result);
|
||||
|
||||
$this->assertNotEmpty($order->getEmailSent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify order will be marked send email on non default store in case default store order email sent is disabled.
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/order_fixture_store.php
|
||||
* @magentoConfigFixture sales_email/general/async_sending 1
|
||||
* @magentoConfigFixture default_store sales_email/order/enabled 0
|
||||
* @magentoConfigFixture fixturestore_store sales_email/order/enabled 1
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testSendOrderEmailFromNonDefaultStore()
|
||||
{
|
||||
$order = Bootstrap::getObjectManager()->create(Order::class);
|
||||
$order->loadByIncrementId('100000004');
|
||||
$order->setCustomerEmail('customer@example.com');
|
||||
$result = $this->orderSender->send($order);
|
||||
$this->assertFalse($result);
|
||||
$this->assertTrue($order->getSendEmail());
|
||||
}
|
||||
}
|
||||
+199
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Sales\Model\Order\Email\Sender;
|
||||
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\Customer\Model\ResourceModel\CustomerRepository;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Sales\Model\Order\Email\Container\ShipmentIdentity;
|
||||
use Magento\Sales\Model\Order\Shipment;
|
||||
use Magento\Sales\Model\Order\ShipmentFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
*
|
||||
* @deprecated since ShipmentSender is deprecated
|
||||
* @see \Magento\Sales\Model\Order\Email\Sender\ShipmentSender
|
||||
*/
|
||||
class ShipmentSenderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private const NEW_CUSTOMER_EMAIL = 'new.customer@example.com';
|
||||
private const OLD_CUSTOMER_EMAIL = 'customer@example.com';
|
||||
private const ORDER_EMAIL = 'customer@example.com';
|
||||
|
||||
/**
|
||||
* @var CustomerRepository
|
||||
*/
|
||||
private $customerRepository;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->customerRepository = Bootstrap::getObjectManager()
|
||||
->get(CustomerRepositoryInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/order.php
|
||||
*/
|
||||
public function testSend()
|
||||
{
|
||||
Bootstrap::getObjectManager()->get(\Magento\Framework\App\State::class)->setAreaCode('frontend');
|
||||
$order = Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Order::class);
|
||||
$order->loadByIncrementId('100000001');
|
||||
$order->setCustomerEmail('customer@example.com');
|
||||
|
||||
$shipment = Bootstrap::getObjectManager()->get(ShipmentFactory::class)->create($order);
|
||||
|
||||
$this->assertEmpty($shipment->getEmailSent());
|
||||
|
||||
$orderSender = Bootstrap::getObjectManager()
|
||||
->create(\Magento\Sales\Model\Order\Email\Sender\ShipmentSender::class);
|
||||
$result = $orderSender->send($shipment, true);
|
||||
|
||||
$this->assertTrue($result);
|
||||
|
||||
$this->assertNotEmpty($shipment->getEmailSent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that when a customer email is modified, the shipment is sent to the new email
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/order_with_customer.php
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
public function testSendWhenCustomerEmailWasModified()
|
||||
{
|
||||
$customer = $this->customerRepository->getById(1);
|
||||
$customer->setEmail(self::NEW_CUSTOMER_EMAIL);
|
||||
$this->customerRepository->save($customer);
|
||||
|
||||
$order = $this->createOrder();
|
||||
$shipment = $this->createShipment($order);
|
||||
$shipmentIdentity = $this->createShipmentEntity();
|
||||
$shipmentSender = $this->createShipmentSender($shipmentIdentity);
|
||||
|
||||
$this->assertEmpty($shipment->getEmailSent());
|
||||
$result = $shipmentSender->send($shipment, true);
|
||||
|
||||
$this->assertEquals(self::NEW_CUSTOMER_EMAIL, $shipmentIdentity->getCustomerEmail());
|
||||
$this->assertTrue($result);
|
||||
$this->assertNotEmpty($shipment->getEmailSent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that when a customer email is not modified, the shipment is sent to the old customer email
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/order_with_customer.php
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
public function testSendWhenCustomerEmailWasNotModified()
|
||||
{
|
||||
$order = $this->createOrder();
|
||||
$shipment = $this->createShipment($order);
|
||||
$shipmentIdentity = $this->createShipmentEntity();
|
||||
$shipmentSender = $this->createShipmentSender($shipmentIdentity);
|
||||
|
||||
$this->assertEmpty($shipment->getEmailSent());
|
||||
$result = $shipmentSender->send($shipment, true);
|
||||
|
||||
$this->assertEquals(self::OLD_CUSTOMER_EMAIL, $shipmentIdentity->getCustomerEmail());
|
||||
$this->assertTrue($result);
|
||||
$this->assertNotEmpty($shipment->getEmailSent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that when an order has not customer the shipment is sent to the order email
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/order.php
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
public function testSendWithoutCustomer()
|
||||
{
|
||||
$order = $this->createOrder();
|
||||
$shipment = $this->createShipment($order);
|
||||
|
||||
/** @var ShipmentIdentity $shipmentIdentity */
|
||||
$shipmentIdentity = $this->createShipmentEntity();
|
||||
/** @var ShipmentSender $shipmentSender */
|
||||
$shipmentSender = $this->createShipmentSender($shipmentIdentity);
|
||||
|
||||
$this->assertEmpty($shipment->getEmailSent());
|
||||
$result = $shipmentSender->send($shipment, true);
|
||||
|
||||
$this->assertEquals(self::ORDER_EMAIL, $shipmentIdentity->getCustomerEmail());
|
||||
$this->assertTrue($result);
|
||||
$this->assertNotEmpty($shipment->getEmailSent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the correctness and stability of set/get packages of shipment
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/order.php
|
||||
*/
|
||||
public function testPackages()
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$objectManager->get(\Magento\Framework\App\State::class)->setAreaCode('frontend');
|
||||
$order = $objectManager->create(\Magento\Sales\Model\Order::class);
|
||||
$order->loadByIncrementId('100000001');
|
||||
$order->setCustomerEmail('customer@example.com');
|
||||
$items = [];
|
||||
foreach ($order->getItems() as $item) {
|
||||
$items[$item->getId()] = $item->getQtyOrdered();
|
||||
}
|
||||
/** @var \Magento\Sales\Model\Order\Shipment $shipment */
|
||||
$shipment = $objectManager->get(ShipmentFactory::class)->create($order, $items);
|
||||
$packages = [['1'], ['2']];
|
||||
$shipment->setPackages($packages);
|
||||
$this->assertEquals($packages, $shipment->getPackages());
|
||||
$shipment->save();
|
||||
$shipment->save();
|
||||
$shipment->load($shipment->getId());
|
||||
$this->assertEquals($packages, $shipment->getPackages());
|
||||
}
|
||||
|
||||
private function createShipment(Order $order): Shipment
|
||||
{
|
||||
$shipment = Bootstrap::getObjectManager()->create(
|
||||
Shipment::class
|
||||
);
|
||||
$shipment->setOrder($order);
|
||||
|
||||
return $shipment;
|
||||
}
|
||||
|
||||
private function createOrder(): Order
|
||||
{
|
||||
$order = Bootstrap::getObjectManager()
|
||||
->create(Order::class);
|
||||
$order->loadByIncrementId('100000001');
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
private function createShipmentEntity(): ShipmentIdentity
|
||||
{
|
||||
return Bootstrap::getObjectManager()->create(
|
||||
ShipmentIdentity::class
|
||||
);
|
||||
}
|
||||
|
||||
private function createShipmentSender(ShipmentIdentity $shipmentIdentity): ShipmentSender
|
||||
{
|
||||
return Bootstrap::getObjectManager()
|
||||
->create(
|
||||
ShipmentSender::class,
|
||||
[
|
||||
'identityContainer' => $shipmentIdentity,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Sales\Model\Order\Invoice;
|
||||
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use Magento\Framework\App\Config\MutableScopeConfigInterface;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Sales\Model\Order\Invoice\GetLogoFile
|
||||
*/
|
||||
class GetLogoFileTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private const XML_PATH_SALES_IDENTITY_LOGO_HTML = 'sales/identity/logo_html';
|
||||
private const DUMP_IMAGE = 'my_dump_logo.png';
|
||||
|
||||
/**
|
||||
* @var ObjectManager
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var MutableScopeConfigInterface
|
||||
*/
|
||||
private $scopeConfig;
|
||||
|
||||
/**
|
||||
* @var GetLogoFile
|
||||
*/
|
||||
private $getLogoFile;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->scopeConfig = $this->objectManager->get(MutableScopeConfigInterface::class);
|
||||
$this->getLogoFile = $this->objectManager->get(GetLogoFile::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that GetLogoFile return image after Admin configuration is changed
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExecute(): void
|
||||
{
|
||||
$this->assertNull($this->getLogoFile->execute());
|
||||
|
||||
$this->applyImage();
|
||||
|
||||
$this->assertIsString($this->getLogoFile->execute());
|
||||
$this->assertStringContainsString(self::DUMP_IMAGE, $this->getLogoFile->execute());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Invoice Custom Logo HTML Image configuration
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function applyImage(): void
|
||||
{
|
||||
$this->scopeConfig->setValue(
|
||||
self::XML_PATH_SALES_IDENTITY_LOGO_HTML,
|
||||
self::DUMP_IMAGE,
|
||||
ScopeInterface::SCOPE_STORE
|
||||
);
|
||||
}
|
||||
}
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Sales\Model\Order\Invoice\Sender;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Sales\Api\Data\InvoiceInterface;
|
||||
use Magento\Sales\Api\Data\OrderInterface;
|
||||
use Magento\Sales\Api\OrderRepositoryInterface;
|
||||
use Magento\Sales\Model\ResourceModel\Order\Invoice\CollectionFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Magento\Sales\Model\Order\Invoice\Sender\EmailSender;
|
||||
use Magento\TestFramework\Mail\Template\TransportBuilderMock;
|
||||
|
||||
/**
|
||||
* Test Order\Invoice\Sender\EmailSender model
|
||||
*
|
||||
* @see \Magento\Sales\Model\Order\Invoice\Sender\EmailSender
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoDataFixture Magento/Sales/_files/invoice.php
|
||||
*/
|
||||
class EmailSenderTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var EmailSender
|
||||
*/
|
||||
private $emailSender;
|
||||
|
||||
/**
|
||||
* @var CollectionFactory
|
||||
*/
|
||||
private $invoiceCollectionFactory;
|
||||
|
||||
/**
|
||||
* @var TransportBuilderMock
|
||||
*/
|
||||
private $transportBuilder;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->emailSender = $this->objectManager->get(EmailSender::class);
|
||||
$this->invoiceCollectionFactory = $this->objectManager->get(CollectionFactory::class);
|
||||
$this->transportBuilder = $this->objectManager->get(TransportBuilderMock::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that order item(s) present in email
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testOrderItemsPresentInEmail()
|
||||
{
|
||||
$order = $this->getOrder('100000001');
|
||||
$invoice = $this->getInvoiceByOrder($order);
|
||||
$this->emailSender->send($order, $invoice);
|
||||
$message = $this->transportBuilder->getSentMessage();
|
||||
$this->assertStringContainsString(
|
||||
'SKU: simple',
|
||||
$message->getBody()->getParts()[0]->getRawContent(),
|
||||
'Expected text wasn\'t found in message.'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get first order invoice
|
||||
*
|
||||
* @param OrderInterface|int $order
|
||||
* @return InvoiceInterface
|
||||
*/
|
||||
protected function getInvoiceByOrder($order): InvoiceInterface
|
||||
{
|
||||
$invoiceCollection = $this->invoiceCollectionFactory->create();
|
||||
|
||||
return $invoiceCollection->setOrderFilter($order)->setPageSize(1)->getFirstItem();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets order entity by increment id.
|
||||
*
|
||||
* @param string $incrementId
|
||||
* @return OrderInterface
|
||||
*/
|
||||
private function getOrder(string $incrementId): OrderInterface
|
||||
{
|
||||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class);
|
||||
$searchCriteria = $searchCriteriaBuilder->addFilter('increment_id', $incrementId)
|
||||
->create();
|
||||
|
||||
/** @var OrderRepositoryInterface $repository */
|
||||
$repository = $this->objectManager->get(OrderRepositoryInterface::class);
|
||||
$items = $repository->getList($searchCriteria)
|
||||
->getItems();
|
||||
|
||||
return array_pop($items);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Sales\Model\Order;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Sales\Model\ResourceModel\Order\Collection as OrderCollection;
|
||||
use Magento\Sales\Api\InvoiceManagementInterface;
|
||||
use Magento\Sales\Api\OrderRepositoryInterface;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
|
||||
/**
|
||||
* Invoice model test.
|
||||
*/
|
||||
class InvoiceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var OrderCollection
|
||||
*/
|
||||
private $collection;
|
||||
|
||||
/**
|
||||
* @var InvoiceManagementInterface
|
||||
*/
|
||||
private $invoiceManagement;
|
||||
|
||||
/**
|
||||
* @var OrderRepositoryInterface
|
||||
*/
|
||||
private $orderRepository;
|
||||
|
||||
/**
|
||||
* @var SearchCriteriaBuilder
|
||||
*/
|
||||
private $searchCriteriaBuilder;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->collection = $this->objectManager->create(OrderCollection::class);
|
||||
$this->invoiceManagement = $this->objectManager->get(InvoiceManagementInterface::class);
|
||||
$this->orderRepository = $this->objectManager->get(OrderRepositoryInterface::class);
|
||||
$this->searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/invoice.php
|
||||
*/
|
||||
public function testOrderTotalItemCount()
|
||||
{
|
||||
$expectedResult = [['total_item_count' => 1]];
|
||||
$actualResult = [];
|
||||
/** @var \Magento\Sales\Model\Order $order */
|
||||
foreach ($this->collection->getItems() as $order) {
|
||||
$actualResult[] = ['total_item_count' => $order->getData('total_item_count')];
|
||||
}
|
||||
$this->assertEquals($expectedResult, $actualResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test order with exactly one configurable.
|
||||
*
|
||||
* @return void
|
||||
* @magentoDataFixture Magento/Sales/_files/order_configurable_product.php
|
||||
*/
|
||||
public function testLastInvoiceWithConfigurable(): void
|
||||
{
|
||||
$searchCriteria = $this->searchCriteriaBuilder->addFilter('increment_id', '100000001')
|
||||
->create();
|
||||
$orders = $this->orderRepository->getList($searchCriteria);
|
||||
$orders = $orders->getItems();
|
||||
$order = array_shift($orders);
|
||||
$invoice = $this->invoiceManagement->prepareInvoice($order);
|
||||
|
||||
self::assertEquals($invoice->isLast(), true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Sales\Model\Order;
|
||||
|
||||
class ItemRepositoryTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/** @var \Magento\Sales\Model\Order */
|
||||
private $order;
|
||||
|
||||
/** @var \Magento\Sales\Api\OrderItemRepositoryInterface */
|
||||
private $orderItemRepository;
|
||||
|
||||
/** @var \Magento\Framework\Api\SearchCriteriaBuilder */
|
||||
private $searchCriteriaBuilder;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$this->order = $objectManager->create(\Magento\Sales\Model\Order::class);
|
||||
$this->orderItemRepository = $objectManager->create(\Magento\Sales\Api\OrderItemRepositoryInterface::class);
|
||||
$this->searchCriteriaBuilder = $objectManager->create(\Magento\Framework\Api\SearchCriteriaBuilder::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/order_configurable_product.php
|
||||
*/
|
||||
public function testAddOrderItemParent()
|
||||
{
|
||||
$this->order->load('100000001', 'increment_id');
|
||||
|
||||
foreach ($this->order->getItems() as $item) {
|
||||
if ($item->getProductType() === \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE) {
|
||||
$orderItem = $this->orderItemRepository->get($item->getItemId());
|
||||
$this->assertInstanceOf(\Magento\Sales\Api\Data\OrderItemInterface::class, $orderItem->getParentItem());
|
||||
}
|
||||
}
|
||||
|
||||
$itemList = $this->orderItemRepository->getList(
|
||||
$this->searchCriteriaBuilder->addFilter('order_id', $this->order->getId())->create()
|
||||
);
|
||||
|
||||
foreach ($itemList->getItems() as $item) {
|
||||
if ($item->getProductType() === \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE) {
|
||||
$this->assertInstanceOf(\Magento\Sales\Api\Data\OrderItemInterface::class, $item->getParentItem());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Sales\Model\Order;
|
||||
|
||||
class ItemTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @param string $options
|
||||
* @param array $expectedData
|
||||
* @dataProvider getProductOptionsDataProvider
|
||||
*/
|
||||
public function testGetProductOptions($options, $expectedData)
|
||||
{
|
||||
$model = \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Sales\Model\Order\Item::class);
|
||||
$model->setData('product_options', $options);
|
||||
$this->assertEquals($expectedData, $model->getProductOptions());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getProductOptionsDataProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'{"option1":1,"option2":2}',
|
||||
["option1" => 1, "option2" => 2]
|
||||
],
|
||||
[
|
||||
["option1" => 1, "option2" => 2],
|
||||
["option1" => 1, "option2" => 2]
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Sales\Model\Order\Payment;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Framework\Api\FilterBuilder;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Framework\Api\SortOrderBuilder;
|
||||
|
||||
/**
|
||||
* Class RepositoryTest
|
||||
* @package Magento\Sales\Model\Order\Payment\
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class RepositoryTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/** @var Repository */
|
||||
protected $repository;
|
||||
|
||||
/** @var SortOrderBuilder */
|
||||
private $sortOrderBuilder;
|
||||
|
||||
/** @var FilterBuilder */
|
||||
private $filterBuilder;
|
||||
|
||||
/** @var SearchCriteriaBuilder */
|
||||
private $searchCriteriaBuilder;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->repository = $objectManager->create(Repository::class);
|
||||
$this->searchCriteriaBuilder = $objectManager->create(
|
||||
\Magento\Framework\Api\SearchCriteriaBuilder::class
|
||||
);
|
||||
$this->filterBuilder = $objectManager->get(
|
||||
\Magento\Framework\Api\FilterBuilder::class
|
||||
);
|
||||
$this->sortOrderBuilder = $objectManager->get(
|
||||
\Magento\Framework\Api\SortOrderBuilder::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/order_payment_list.php
|
||||
*/
|
||||
public function testGetListWithMultipleFiltersAndSorting()
|
||||
{
|
||||
$filter1 = $this->filterBuilder
|
||||
->setField('cc_ss_start_year')
|
||||
->setValue('2014')
|
||||
->create();
|
||||
$filter2 = $this->filterBuilder
|
||||
->setField('cc_exp_month')
|
||||
->setValue('09')
|
||||
->create();
|
||||
$filter3 = $this->filterBuilder
|
||||
->setField('method')
|
||||
->setValue('checkmo')
|
||||
->create();
|
||||
$sortOrder = $this->sortOrderBuilder
|
||||
->setField('cc_exp_month')
|
||||
->setDirection('DESC')
|
||||
->create();
|
||||
|
||||
$this->searchCriteriaBuilder->addFilters([$filter1, $filter2]);
|
||||
$this->searchCriteriaBuilder->addFilters([$filter3]);
|
||||
$this->searchCriteriaBuilder->addSortOrder($sortOrder);
|
||||
$searchCriteria = $this->searchCriteriaBuilder->create();
|
||||
/** @var \Magento\Sales\Api\Data\OrderPaymentSearchResultInterface $result */
|
||||
$result = $this->repository->getList($searchCriteria);
|
||||
$items = $result->getItems();
|
||||
$this->assertCount(2, $items);
|
||||
$this->assertEquals('456', array_shift($items)->getCcLast4());
|
||||
$this->assertEquals('123', array_shift($items)->getCcLast4());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Sales\Model\Order\Payment;
|
||||
|
||||
/**
|
||||
* Tests transaction model:
|
||||
*
|
||||
* @see \Magento\Sales\Model\Order\Payment\Transaction
|
||||
* @magentoDataFixture Magento/Sales/_files/transactions.php
|
||||
*/
|
||||
class TransactionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testLoadByTxnId()
|
||||
{
|
||||
$order = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Order::class);
|
||||
$order->loadByIncrementId('100000001');
|
||||
|
||||
/**
|
||||
* @var $repository \Magento\Sales\Model\Order\Payment\Transaction\Repository
|
||||
*/
|
||||
$repository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Sales\Model\Order\Payment\Transaction\Repository::class
|
||||
);
|
||||
/**
|
||||
* @var $model \Magento\Sales\Model\Order\Payment\Transaction
|
||||
*/
|
||||
$model = $repository->getByTransactionId(
|
||||
'invalid_transaction_id',
|
||||
$order->getPayment()->getId(),
|
||||
$order->getId()
|
||||
);
|
||||
|
||||
$this->assertFalse($model);
|
||||
|
||||
$model = $repository->getByTransactionId('trx1', $order->getPayment()->getId(), $order->getId());
|
||||
$this->assertNotFalse($model->getId());
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Sales\Model\Order\Reorder;
|
||||
|
||||
use Magento\Sales\Api\Data\OrderInterfaceFactory;
|
||||
|
||||
/**
|
||||
* Class UnavailableProductsProviderTest
|
||||
*/
|
||||
class UnavailableProductsProviderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/order_item_with_configurable_for_reorder.php
|
||||
*/
|
||||
public function testGetForOrder()
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Sales\Model\OrderFactory $orderFactory */
|
||||
$orderFactory = $objectManager->get(OrderInterfaceFactory::class);
|
||||
/** @var \Magento\Sales\Model\Order $order */
|
||||
$order = $orderFactory->create()->loadByIncrementId('100001001');
|
||||
$orderItems = $order->getItems();
|
||||
$orderItemSimple = array_pop($orderItems);
|
||||
$orderItemSimple->getSku();
|
||||
/** @var UnavailableProductsProvider $unavailableProductsProvider */
|
||||
$unavailableProductsProvider =
|
||||
$objectManager->create(UnavailableProductsProvider::class);
|
||||
$unavailableProducts = $unavailableProductsProvider->getForOrder($order);
|
||||
$this->assertEquals($orderItemSimple->getSku(), $unavailableProducts[0]);
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Sales\Model\Order\Shipment\Sender;
|
||||
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Provides tests for shipment email sender.
|
||||
*/
|
||||
class EmailSenderTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var EmailSender
|
||||
*/
|
||||
private $emailSender;
|
||||
|
||||
/**
|
||||
* @inheirtDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->emailSender = Bootstrap::getObjectManager()->create(EmailSender::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify shipment will be marked send email on non default store in case default store order email sent is disabled
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/order_fixture_store.php
|
||||
* @magentoConfigFixture sales_email/general/async_sending 1
|
||||
* @magentoConfigFixture default_store sales_email/shipment/enabled 0
|
||||
* @magentoConfigFixture fixturestore_store sales_email/shipment/enabled 1
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testSendShipmentEmailFromNonDefaultStore()
|
||||
{
|
||||
$order = Bootstrap::getObjectManager()->create(Order::class);
|
||||
$order->loadByIncrementId('100000004');
|
||||
$order->setCustomerEmail('customer@example.com');
|
||||
$shipment = Bootstrap::getObjectManager()->create(Order\Shipment::class);
|
||||
$shipment->setOrder($order);
|
||||
$result = $this->emailSender->send($order, $shipment);
|
||||
$this->assertFalse($result);
|
||||
$this->assertTrue($shipment->getSendEmail());
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Sales\Model\Order;
|
||||
|
||||
use Magento\Sales\Api\Data\ShipmentCreationArgumentsExtensionInterfaceFactory;
|
||||
use Magento\Sales\Api\Data\ShipmentCreationArgumentsInterface;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Provide tests for shipment document factory.
|
||||
*/
|
||||
class ShipmentDocumentFactoryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Order
|
||||
*/
|
||||
private $order;
|
||||
|
||||
/**
|
||||
* @var ShipmentDocumentFactory
|
||||
*/
|
||||
private $shipmentDocumentFactory;
|
||||
|
||||
/**
|
||||
* @var ShipmentCreationArgumentsInterface
|
||||
*/
|
||||
private $shipmentCreationArgumentsInterface;
|
||||
|
||||
/**
|
||||
* @var ShipmentCreationArgumentsExtensionInterfaceFactory
|
||||
*/
|
||||
private $shipmentCreationArgumentsExtensionInterfaceFactory;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
$this->order = $objectManager->create(Order::class);
|
||||
$this->shipmentDocumentFactory = $objectManager->create(ShipmentDocumentFactory::class);
|
||||
$this->shipmentCreationArgumentsInterface = $objectManager
|
||||
->create(ShipmentCreationArgumentsInterface::class);
|
||||
$this->shipmentCreationArgumentsExtensionInterfaceFactory = $objectManager
|
||||
->create(ShipmentCreationArgumentsExtensionInterfaceFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create shipment with shipment creation arguments.
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/order.php
|
||||
*/
|
||||
public function testCreate(): void
|
||||
{
|
||||
$order = $this->order->loadByIncrementId('100000001');
|
||||
$argumentsExtensionAttributes = $this->shipmentCreationArgumentsExtensionInterfaceFactory->create([
|
||||
'data' => ['test_attribute_value' => 'test_value']
|
||||
]);
|
||||
$this->shipmentCreationArgumentsInterface->setExtensionAttributes($argumentsExtensionAttributes);
|
||||
$shipment = $this->shipmentDocumentFactory->create(
|
||||
$order,
|
||||
[],
|
||||
[],
|
||||
null,
|
||||
false,
|
||||
[],
|
||||
$this->shipmentCreationArgumentsInterface
|
||||
);
|
||||
$shipmentExtensionAttributes = $shipment->getExtensionAttributes();
|
||||
self::assertEquals('test_value', $shipmentExtensionAttributes->getTestAttributeValue());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Sales\Model\Order;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Payment\Helper\Data;
|
||||
use Magento\Sales\Api\Data\CommentInterface;
|
||||
use Magento\Sales\Api\Data\OrderInterface;
|
||||
use Magento\Sales\Api\Data\ShipmentInterface;
|
||||
use Magento\Sales\Api\Data\ShipmentItemInterface;
|
||||
use Magento\Sales\Api\Data\ShipmentTrackInterface;
|
||||
use Magento\Sales\Api\OrderRepositoryInterface;
|
||||
use Magento\Sales\Api\ShipmentRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Sales/_files/order.php
|
||||
*/
|
||||
class ShipmentTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManager
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var ShipmentRepositoryInterface
|
||||
*/
|
||||
private $shipmentRepository;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->shipmentRepository = $this->objectManager->get(ShipmentRepositoryInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the correctness and stability of set/get packages of shipment
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
public function testPackages()
|
||||
{
|
||||
$order = $this->getOrder('100000001');
|
||||
|
||||
$payment = $order->getPayment();
|
||||
$paymentInfoBlock = $this->objectManager->get(Data::class)
|
||||
->getInfoBlock($payment);
|
||||
$payment->setBlockMock($paymentInfoBlock);
|
||||
|
||||
$items = [];
|
||||
foreach ($order->getItems() as $item) {
|
||||
$items[$item->getId()] = $item->getQtyOrdered();
|
||||
}
|
||||
/** @var \Magento\Sales\Model\Order\Shipment $shipment */
|
||||
$shipment = $this->objectManager->get(ShipmentFactory::class)->create($order, $items);
|
||||
|
||||
$packages = [['1'], ['2']];
|
||||
|
||||
$shipment->setPackages($packages);
|
||||
$saved = $this->shipmentRepository->save($shipment);
|
||||
self::assertEquals($packages, $saved->getPackages());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that getTracksCollection() always return collection instance.
|
||||
*/
|
||||
public function testAddTrack()
|
||||
{
|
||||
$order = $this->getOrder('100000001');
|
||||
|
||||
/** @var ShipmentTrackInterface $track */
|
||||
$track = $this->objectManager->create(ShipmentTrackInterface::class);
|
||||
$track->setNumber('Test Number')
|
||||
->setTitle('Test Title')
|
||||
->setCarrierCode('Test CODE');
|
||||
|
||||
$items = [];
|
||||
foreach ($order->getItems() as $item) {
|
||||
$items[$item->getId()] = $item->getQtyOrdered();
|
||||
}
|
||||
/** @var \Magento\Sales\Model\Order\Shipment $shipment */
|
||||
$shipment = $this->objectManager->get(ShipmentFactory::class)
|
||||
->create($order, $items);
|
||||
$shipment->addTrack($track);
|
||||
$this->shipmentRepository->save($shipment);
|
||||
$saved = $this->shipmentRepository->get((int)$shipment->getEntityId());
|
||||
self::assertNotEmpty($saved->getTracks());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks adding comment to the shipment entity.
|
||||
*/
|
||||
public function testAddComment()
|
||||
{
|
||||
$message1 = 'Test Comment 1';
|
||||
$message2 = 'Test Comment 2';
|
||||
$order = $this->getOrder('100000001');
|
||||
|
||||
/** @var ShipmentInterface $shipment */
|
||||
$shipment = $this->objectManager->create(ShipmentInterface::class);
|
||||
$shipment->setOrder($order)
|
||||
->addItem($this->objectManager->create(ShipmentItemInterface::class))
|
||||
->addComment($message1)
|
||||
->addComment($message2);
|
||||
|
||||
$saved = $this->shipmentRepository->save($shipment);
|
||||
|
||||
$comments = $saved->getComments();
|
||||
$actual = array_map(
|
||||
function (CommentInterface $comment) {
|
||||
return $comment->getComment();
|
||||
},
|
||||
$comments
|
||||
);
|
||||
self::assertCount(2, $actual);
|
||||
self::assertEquals([$message1, $message2], $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets order entity by increment id.
|
||||
*
|
||||
* @param string $incrementId
|
||||
* @return OrderInterface
|
||||
*/
|
||||
private function getOrder(string $incrementId): OrderInterface
|
||||
{
|
||||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class);
|
||||
$searchCriteria = $searchCriteriaBuilder->addFilter('increment_id', $incrementId)
|
||||
->create();
|
||||
|
||||
/** @var OrderRepositoryInterface $repository */
|
||||
$repository = $this->objectManager->get(OrderRepositoryInterface::class);
|
||||
$items = $repository->getList($searchCriteria)
|
||||
->getItems();
|
||||
|
||||
return array_pop($items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that getTracksCollection() returns only order related tracks.
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/two_orders_with_order_items.php
|
||||
*/
|
||||
public function testGetTracksCollection()
|
||||
{
|
||||
$order = $this->getOrder('100000001');
|
||||
$items = [];
|
||||
foreach ($order->getItems() as $item) {
|
||||
$items[$item->getId()] = $item->getQtyOrdered();
|
||||
}
|
||||
/** @var \Magento\Sales\Model\Order\Shipment $shipment */
|
||||
$shipment = $this->objectManager->get(ShipmentFactory::class)
|
||||
->create($order, $items);
|
||||
|
||||
$tracks = $shipment->getTracksCollection();
|
||||
self::assertEmpty($tracks->getItems());
|
||||
|
||||
/** @var ShipmentTrackInterface $track */
|
||||
$track = $this->objectManager->create(ShipmentTrackInterface::class);
|
||||
$track->setNumber('Test Number')
|
||||
->setTitle('Test Title')
|
||||
->setCarrierCode('Test CODE');
|
||||
|
||||
$shipment->addTrack($track);
|
||||
$this->shipmentRepository->save($shipment);
|
||||
$shipmentTracksCollection = $shipment->getTracksCollection();
|
||||
|
||||
$secondOrder = $this->getOrder('100000002');
|
||||
$secondOrderItems = [];
|
||||
foreach ($secondOrder->getItems() as $item) {
|
||||
$secondOrderItems[$item->getId()] = $item->getQtyOrdered();
|
||||
}
|
||||
/** @var \Magento\Sales\Model\Order\Shipment $secondOrderShipment */
|
||||
$secondOrderShipment = $this->objectManager->get(ShipmentFactory::class)
|
||||
->create($secondOrder, $secondOrderItems);
|
||||
|
||||
/** @var ShipmentTrackInterface $secondShipmentTrack */
|
||||
$secondShipmentTrack = $this->objectManager->create(ShipmentTrackInterface::class);
|
||||
$secondShipmentTrack->setNumber('Test Number2')
|
||||
->setTitle('Test Title2')
|
||||
->setCarrierCode('Test CODE2');
|
||||
|
||||
$secondOrderShipment->addTrack($secondShipmentTrack);
|
||||
$this->shipmentRepository->save($secondOrderShipment);
|
||||
$secondShipmentTrackCollection = $secondOrderShipment->getTracksCollection();
|
||||
|
||||
self::assertEquals($shipmentTracksCollection->getColumnValues('id'), [$track->getEntityId()]);
|
||||
self::assertEquals(
|
||||
$secondShipmentTrackCollection->getColumnValues('id'),
|
||||
[$secondShipmentTrack->getEntityId()]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that getTracksCollection() returns only shipment related tracks.
|
||||
*
|
||||
* For the Block and Template responsible for sending email notification, when multiple items order
|
||||
* has multiple shipments and every shipment has a separate tracking, shipment should contain
|
||||
* only tracking info related to given shipment.
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/order_with_two_order_items_with_simple_product.php
|
||||
*/
|
||||
public function testBlock()
|
||||
{
|
||||
$order = $this->getOrder('100000001');
|
||||
|
||||
$shipments = [];
|
||||
foreach ($order->getItems() as $item) {
|
||||
$items[$item->getId()] = $item->getQtyOrdered();
|
||||
/** @var ShipmentTrackInterface $track */
|
||||
$track = $this->objectManager->create(ShipmentTrackInterface::class);
|
||||
$track->setNumber('Test Number')
|
||||
->setTitle('Test Title')
|
||||
->setCarrierCode('Test CODE');
|
||||
/** @var \Magento\Sales\Model\Order\Shipment $shipment */
|
||||
$shipment = $this->objectManager->get(ShipmentFactory::class)
|
||||
->create($order, $items);
|
||||
$shipment->addTrack($track);
|
||||
$this->shipmentRepository->save($shipment);
|
||||
$shipments[] = $shipment;
|
||||
}
|
||||
|
||||
// we extract only the latest shipment
|
||||
$shipment = array_pop($shipments);
|
||||
|
||||
$block = $this->objectManager->create(
|
||||
\Magento\Sales\Block\Order\Email\Shipment\Items::class,
|
||||
[
|
||||
'data' => [
|
||||
'order' => $order,
|
||||
'shipment' => $shipment,
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
$tracks = $block->getShipment()->getTracksCollection()->getItems();
|
||||
$this->assertEquals(1, count($tracks),
|
||||
'There should be only one Tracking item in collection');
|
||||
|
||||
$track = array_pop($tracks);
|
||||
$this->assertEquals($shipment->getId(), $track->getParentId(),
|
||||
'Check that the Tracking belongs to the Shipment');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Sales\Model\Order;
|
||||
|
||||
use Magento\Framework\App\State;
|
||||
use Magento\Sales\Api\Data\OrderInterfaceFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Class ShipmentTest
|
||||
* @package Magento\Sales\Model\Order
|
||||
*/
|
||||
class StatusTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function theCorrectLabelIsUsedDependingOnTheAreaProvider()
|
||||
{
|
||||
return [
|
||||
'backend label' => [
|
||||
'adminhtml',
|
||||
'Example',
|
||||
],
|
||||
'store view label' => [
|
||||
'frontend',
|
||||
'Store view example',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* In the backend the regular label must be showed.
|
||||
*
|
||||
* @param $area
|
||||
* @param $result
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/order_status.php
|
||||
* @dataProvider theCorrectLabelIsUsedDependingOnTheAreaProvider
|
||||
*/
|
||||
public function testTheCorrectLabelIsUsedDependingOnTheArea($area, $result)
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$objectManager->get(State::class)->setAreaCode($area);
|
||||
|
||||
/** @var \Magento\Sales\Model\Order $order */
|
||||
$order = $objectManager->create(\Magento\Sales\Model\Order::class);
|
||||
$order->loadByIncrementId('100000001');
|
||||
|
||||
$this->assertEquals($result, $order->getStatusLabel());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that specified order status frontend label for store should be displayed correctly
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/order_status_with_different_labels.php
|
||||
*/
|
||||
public function testTheCorrectLabelIsUsedDependingOnTheStore()
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$objectManager->get(State::class)->setAreaCode('frontend');
|
||||
$orderFactory = $objectManager->get(OrderInterfaceFactory::class);
|
||||
$order = $orderFactory->create()->loadByIncrementId('100000001');
|
||||
$this->assertEquals('Custom status label', $order->getFrontendStatusLabel());
|
||||
$order->setStoreId(1);
|
||||
$order->save();
|
||||
$this->assertEquals(1, $order->getStoreId());
|
||||
$this->assertEquals('First store label', $order->getFrontendStatusLabel());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Sales\Model;
|
||||
|
||||
/**
|
||||
* Class to verify isIncrementIdUsed method behaviour.
|
||||
*/
|
||||
class OrderIncrementIdCheckerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Sales\Model\OrderIncrementIdChecker
|
||||
*/
|
||||
private $checker;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->checker = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Sales\Model\OrderIncrementIdChecker::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to verify if isIncrementIdUsed method works with numeric increment ids.
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/order.php
|
||||
* @return void
|
||||
*/
|
||||
public function testIsOrderIncrementIdUsedNumericIncrementId(): void
|
||||
{
|
||||
$this->assertTrue($this->checker->isIncrementIdUsed('100000001'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to verify if isIncrementIdUsed method works with alphanumeric increment ids.
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/order_alphanumeric_id.php
|
||||
* @return void
|
||||
*/
|
||||
public function testIsOrderIncrementIdUsedAlphanumericIncrementId(): void
|
||||
{
|
||||
$this->assertTrue($this->checker->isIncrementIdUsed('M00000001'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Sales\Model;
|
||||
|
||||
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
|
||||
use Magento\Checkout\Test\Fixture\PlaceOrder as PlaceOrderFixture;
|
||||
use Magento\Checkout\Test\Fixture\SetBillingAddress as SetBillingAddressFixture;
|
||||
use Magento\Checkout\Test\Fixture\SetDeliveryMethod as SetDeliveryMethodFixture;
|
||||
use Magento\Checkout\Test\Fixture\SetGuestEmail as SetGuestEmailFixture;
|
||||
use Magento\Checkout\Test\Fixture\SetPaymentMethod as SetPaymentMethodFixture;
|
||||
use Magento\Checkout\Test\Fixture\SetShippingAddress as SetShippingAddressFixture;
|
||||
use Magento\Quote\Test\Fixture\AddProductToCart as AddProductToCartFixture;
|
||||
use Magento\Quote\Test\Fixture\GuestCart as GuestCartFixture;
|
||||
use Magento\Sales\Test\Fixture\Creditmemo as CreditmemoFixture;
|
||||
use Magento\Sales\Test\Fixture\Invoice as InvoiceFixture;
|
||||
use Magento\SalesRule\Model\Rule;
|
||||
use Magento\SalesRule\Test\Fixture\Rule as RuleFixture;
|
||||
use Magento\TestFramework\Fixture\Config as Config;
|
||||
use Magento\TestFramework\Fixture\DataFixture;
|
||||
use Magento\TestFramework\Fixture\DataFixtureStorage;
|
||||
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class OrderTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var DataFixtureStorage
|
||||
*/
|
||||
private $fixtures;
|
||||
|
||||
/**
|
||||
* Set up
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->fixtures = Bootstrap::getObjectManager()->get(DataFixtureStorageManager::class)->getStorage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that multiple credit memos can be created for zero total order if not all items are refunded yet
|
||||
*/
|
||||
#[
|
||||
Config('carriers/freeshipping/active', '1', 'store', 'default'),
|
||||
Config('payment/free/active', '1', 'store', 'default'),
|
||||
DataFixture(ProductFixture::class, as: 'product'),
|
||||
DataFixture(GuestCartFixture::class, as: 'cart'),
|
||||
DataFixture(
|
||||
RuleFixture::class,
|
||||
[
|
||||
'simple_action' => Rule::BY_PERCENT_ACTION,
|
||||
'discount_amount' => 100,
|
||||
'apply_to_shipping' => 0,
|
||||
'stop_rules_processing' => 0,
|
||||
'sort_order' => 1,
|
||||
]
|
||||
),
|
||||
DataFixture(
|
||||
AddProductToCartFixture::class,
|
||||
['cart_id' => '$cart.id$', 'product_id' => '$product.id$', 'qty' => 2]
|
||||
),
|
||||
DataFixture(SetBillingAddressFixture::class, ['cart_id' => '$cart.id$']),
|
||||
DataFixture(SetShippingAddressFixture::class, ['cart_id' => '$cart.id$']),
|
||||
DataFixture(SetGuestEmailFixture::class, ['cart_id' => '$cart.id$']),
|
||||
DataFixture(
|
||||
SetDeliveryMethodFixture::class,
|
||||
['cart_id' => '$cart.id$', 'carrier_code' => 'freeshipping', 'method_code' => 'freeshipping']
|
||||
),
|
||||
DataFixture(SetPaymentMethodFixture::class, ['cart_id' => '$cart.id$', 'method' => 'free']),
|
||||
DataFixture(PlaceOrderFixture::class, ['cart_id' => '$cart.id$'], 'order'),
|
||||
DataFixture(InvoiceFixture::class, ['order_id' => '$order.id$'], 'invoice'),
|
||||
DataFixture(
|
||||
CreditmemoFixture::class,
|
||||
['order_id' => '$order.id$', 'items' => [['qty' => 1, 'product_id' => '$product.id$']]],
|
||||
'creditmemo'
|
||||
),
|
||||
]
|
||||
public function testMultipleCreditmemosForZeroTotalOrder()
|
||||
{
|
||||
$order = $this->fixtures->get('order');
|
||||
$this->assertEquals(0, $order->getGrandTotal());
|
||||
$order->unsetData('forced_can_creditmemo');
|
||||
$this->assertTrue(
|
||||
$order->canCreditmemo(),
|
||||
'Should be possible to create second credit memo for zero total order if not all items are refunded yet'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Sales\Model\ResourceModel;
|
||||
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Sales\Model\Grid\LastUpdateTimeCache;
|
||||
use Magento\Sales\Model\ResourceModel\Provider\UpdatedAtListProvider;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Magento\Framework\DB\Adapter\Pdo\Mysql;
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/order_with_invoice_shipment_creditmemo.php
|
||||
*/
|
||||
class GridTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var LastUpdateTimeCache
|
||||
*/
|
||||
private $lastUpdateTimeCache;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->lastUpdateTimeCache = $this->objectManager->get(LastUpdateTimeCache::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider gridDataProvider
|
||||
* @param array $constructorArgs
|
||||
* @param string $orderIdField
|
||||
*/
|
||||
public function testRefreshBySchedule(array $constructorArgs, string $orderIdField)
|
||||
{
|
||||
$constructorArgs['orderIdField'] = $constructorArgs['mainTableName'] . '.' . $orderIdField;
|
||||
$constructorArgs['columns'] = [
|
||||
$orderIdField => $constructorArgs['orderIdField'],
|
||||
'created_at' => $constructorArgs['mainTableName'] . '.created_at',
|
||||
'updated_at' => $constructorArgs['mainTableName'] . '.updated_at',
|
||||
];
|
||||
$constructorArgs['notSyncedDataProvider'] = $this->objectManager->get(UpdatedAtListProvider::class);
|
||||
$grid = $this->objectManager->create(Grid::class, $constructorArgs);
|
||||
|
||||
$order = $this->objectManager->create(\Magento\Sales\Model\Order::class)
|
||||
->loadByIncrementId('100000111');
|
||||
$connection = $grid->getConnection();
|
||||
$select = $connection->select()
|
||||
->from($constructorArgs['mainTableName'], ['created_at', 'updated_at'])
|
||||
->where($orderIdField, $order->getEntityId());
|
||||
$data = $connection->fetchRow($select);
|
||||
$this->assertNotEmpty($data);
|
||||
|
||||
//refresh data without cached updated_at
|
||||
$this->lastUpdateTimeCache->remove($constructorArgs['gridTableName']);
|
||||
$this->assertEmpty($this->lastUpdateTimeCache->get($constructorArgs['gridTableName']));
|
||||
sleep(1);
|
||||
$data['created_at'] = $data['updated_at'] = date('Y-m-d H:i:s');
|
||||
$connection->update(
|
||||
$constructorArgs['mainTableName'],
|
||||
$data,
|
||||
sprintf('%s = %d', $orderIdField, $order->getEntityId())
|
||||
);
|
||||
$grid->refreshBySchedule();
|
||||
|
||||
$select = $connection->select()
|
||||
->from($constructorArgs['gridTableName'], ['created_at', 'updated_at'])
|
||||
->where($orderIdField, $order->getEntityId());
|
||||
$gridData = $connection->fetchRow($select);
|
||||
$this->assertEquals($data, $gridData);
|
||||
|
||||
//refresh data with cached updated_at
|
||||
$this->assertNotEmpty($this->lastUpdateTimeCache->get($constructorArgs['gridTableName']));
|
||||
sleep(1);
|
||||
$data['created_at'] = $data['updated_at'] = date('Y-m-d H:i:s');
|
||||
$connection->update(
|
||||
$constructorArgs['mainTableName'],
|
||||
$data,
|
||||
sprintf('%s = %d', $orderIdField, $order->getEntityId())
|
||||
);
|
||||
$grid->refreshBySchedule();
|
||||
|
||||
$select = $connection->select()
|
||||
->from($constructorArgs['gridTableName'], ['created_at', 'updated_at'])
|
||||
->where($orderIdField, $order->getEntityId());
|
||||
$gridData = $connection->fetchRow($select);
|
||||
$this->assertEquals($data, $gridData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function gridDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'Magento\Sales\Model\ResourceModel\Order\Grid' => [
|
||||
[
|
||||
'mainTableName' => 'sales_order',
|
||||
'gridTableName' => 'sales_order_grid',
|
||||
],
|
||||
'entity_id',
|
||||
],
|
||||
'ShipmentGridAggregator' => [
|
||||
[
|
||||
'mainTableName' => 'sales_shipment',
|
||||
'gridTableName' => 'sales_shipment_grid',
|
||||
],
|
||||
'order_id',
|
||||
],
|
||||
'CreditmemoGridAggregator' => [
|
||||
[
|
||||
'mainTableName' => 'sales_creditmemo',
|
||||
'gridTableName' => 'sales_creditmemo_grid',
|
||||
],
|
||||
'order_id',
|
||||
],
|
||||
'Magento\Sales\Model\ResourceModel\Order\Invoice\Grid' => [
|
||||
[
|
||||
'mainTableName' => 'sales_invoice',
|
||||
'gridTableName' => 'sales_invoice_grid',
|
||||
],
|
||||
'order_id',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider shipmentGridDataProvider
|
||||
* @param array $constructorArgs
|
||||
* @param string $orderIdField
|
||||
* @param string $orderIdIndex
|
||||
*/
|
||||
public function testSalesShipmentGridOrderIdFieldIndex(array $constructorArgs, string $orderIdField, string $orderIdIndex)
|
||||
{
|
||||
$constructorArgs['orderIdField'] = $constructorArgs['mainTableName'] . '.' . $orderIdField;
|
||||
$constructorArgs['columns'] = [
|
||||
$orderIdField => $constructorArgs['orderIdField'],
|
||||
'created_at' => $constructorArgs['mainTableName'] . '.created_at',
|
||||
'updated_at' => $constructorArgs['mainTableName'] . '.updated_at',
|
||||
];
|
||||
$constructorArgs['notSyncedDataProvider'] = $this->objectManager->get(UpdatedAtListProvider::class);
|
||||
$grid = $this->objectManager->create(Grid::class, $constructorArgs);
|
||||
/** @var Mysql $connection */
|
||||
$connection = $grid->getConnection();
|
||||
$order = $this->objectManager->create(\Magento\Sales\Model\Order::class)
|
||||
->loadByIncrementId('100000111');
|
||||
$select = $connection->select()
|
||||
->from($constructorArgs['gridTableName'], ['order_id'])
|
||||
->where("$orderIdField = ?", $order->getEntityId());
|
||||
$gridTableIndexes = $connection->getIndexList($constructorArgs['gridTableName']);
|
||||
$gridFieldData = $connection->fetchRow($select);
|
||||
$testFiledData = ['order_id' => $order->getEntityId()];
|
||||
$this->assertEquals($testFiledData, $gridFieldData);
|
||||
$this->assertArrayHasKey($orderIdIndex, $gridTableIndexes);
|
||||
$this->assertEquals($gridTableIndexes[$orderIdIndex]['fields'][0], $orderIdField);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function shipmentGridDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'Magento\Sales\Model\ResourceModel\Grid' => [
|
||||
[
|
||||
'mainTableName' => 'sales_shipment',
|
||||
'gridTableName' => 'sales_shipment_grid',
|
||||
],
|
||||
'order_id',
|
||||
'SALES_SHIPMENT_GRID_ORDER_ID'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Sales\Model\ResourceModel\Order\Address;
|
||||
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\Sales\Model\Order\Payment;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Sales\Api\Data\OrderAddressInterface as OrderAddress;
|
||||
use Magento\Backend\Model\Locale\Resolver;
|
||||
use Magento\Framework\Locale\ResolverInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test for address collection
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class CollectionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ResolverInterface|MockObject
|
||||
*/
|
||||
private $localeResolverMock;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->localeResolverMock = $this->createMock(ResolverInterface::class);
|
||||
Bootstrap::getObjectManager()->removeSharedInstance(ResolverInterface::class);
|
||||
Bootstrap::getObjectManager()->removeSharedInstance(Resolver::class);
|
||||
Bootstrap::getObjectManager()->addSharedInstance($this->localeResolverMock, ResolverInterface::class);
|
||||
Bootstrap::getObjectManager()->addSharedInstance($this->localeResolverMock, Resolver::class);
|
||||
|
||||
$addressData = [
|
||||
OrderAddress::REGION => 'Alabama',
|
||||
OrderAddress::REGION_ID => '1',
|
||||
OrderAddress::POSTCODE => '11111',
|
||||
OrderAddress::LASTNAME => 'lastname',
|
||||
OrderAddress::FIRSTNAME => 'firstname',
|
||||
OrderAddress::STREET => 'street',
|
||||
OrderAddress::CITY => 'Montgomery',
|
||||
OrderAddress::EMAIL => 'admin@example.com',
|
||||
OrderAddress::TELEPHONE => '11111111',
|
||||
OrderAddress::COUNTRY_ID => 'US'
|
||||
];
|
||||
$billingAddress = Bootstrap::getObjectManager()->create(OrderAddress::class, ['data' => $addressData]);
|
||||
$billingAddress->setAddressType('billing');
|
||||
$shippingAddress = clone $billingAddress;
|
||||
$shippingAddress->setId(null)->setAddressType('shipping');
|
||||
$payment = Bootstrap::getObjectManager()->create(Payment::class);
|
||||
$payment->setMethod('payflowpro')
|
||||
->setCcExpMonth('5')
|
||||
->setCcLast4('0005')
|
||||
->setCcType('AE')
|
||||
->setCcExpYear('2022');
|
||||
$order = Bootstrap::getObjectManager()->create(Order::class);
|
||||
$order->setIncrementId('100000001')
|
||||
->setSubtotal(100)
|
||||
->setBaseSubtotal(100)
|
||||
->setCustomerEmail('admin@example.com')
|
||||
->setCustomerIsGuest(true)
|
||||
->setBillingAddress($billingAddress)
|
||||
->setShippingAddress($shippingAddress)
|
||||
->setStoreId(Bootstrap::getObjectManager()->get(StoreManagerInterface::class)->getStore()->getId())
|
||||
->setPayment($payment);
|
||||
$order->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Directory/_files/region_name_jp.php
|
||||
*/
|
||||
public function testCollectionWithJpLocale(): void
|
||||
{
|
||||
$locale = 'JA_jp';
|
||||
$this->localeResolverMock->method('getLocale')->willReturn($locale);
|
||||
|
||||
$order = Bootstrap::getObjectManager()->create(Order::class)
|
||||
->loadByIncrementId('100000001');
|
||||
|
||||
$collection = $order->getAddressesCollection();
|
||||
foreach ($collection as $address) {
|
||||
$this->assertEquals('アラバマ', $address->getData(OrderAddress::REGION));
|
||||
}
|
||||
}
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Sales\Model\ResourceModel\Order\Customer;
|
||||
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Store\Api\StoreRepositoryInterface;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test for Magento\Customer\Model\ResourceModel\Customer\Collection
|
||||
*/
|
||||
class CollectionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that Customer collection data for Order retain website and store names after fixing performance issue.
|
||||
* @see \Magento\Customer\Model\ResourceModel\Customer\Collection::beforeAddLoadedItem()
|
||||
*
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_for_second_website.php
|
||||
*/
|
||||
public function testCollection(): void
|
||||
{
|
||||
/** @var Collection $customerCollection */
|
||||
$customerCollection = $this->objectManager->create(Collection::class);
|
||||
$customer = $customerCollection->getItems();
|
||||
$customer = array_shift($customer);
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $this->objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$website = $websiteRepository->getById($customer->getWebsiteId());
|
||||
/** @var StoreRepositoryInterface $storeRepository */
|
||||
$storeRepository = $this->objectManager->get(StoreRepositoryInterface::class);
|
||||
$store = $storeRepository->getById($customer->getStoreId());
|
||||
|
||||
$this->assertEquals($website->getName(), $customer->getWebsiteName());
|
||||
$this->assertEquals($store->getName(), $customer->getStoreName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test customer collection with the website and the store name filter.
|
||||
*
|
||||
* @throws LocalizedException
|
||||
* @see \Magento\Customer\Model\ResourceModel\Customer\Collection::addFieldToFilter()
|
||||
*
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_for_second_website.php
|
||||
*/
|
||||
public function testCollectionWithWebsiteStoreFilter(): void
|
||||
{
|
||||
/** @var Collection $customerCollection */
|
||||
$customerCollection = $this->objectManager->create(Collection::class);
|
||||
|
||||
$customer = $customerCollection->getItems();
|
||||
$customer = array_shift($customer);
|
||||
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $this->objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$website = $websiteRepository->getById($customer->getWebsiteId());
|
||||
|
||||
/** @var StoreRepositoryInterface $storeRepository */
|
||||
$storeRepository = $this->objectManager->get(StoreRepositoryInterface::class);
|
||||
$store = $storeRepository->getById($customer->getStoreId());
|
||||
|
||||
$customerCollectionWithStoreWebsiteFilter = $customerCollection
|
||||
->addFieldToFilter('store_name', $store->getName())
|
||||
->addFieldToFilter('website_name', $website->getName());
|
||||
$customerWithStoreWebsiteFilter = $customerCollectionWithStoreWebsiteFilter->getItems();
|
||||
$customerWithStoreWebsiteFilter = array_shift($customerWithStoreWebsiteFilter);
|
||||
|
||||
$this->assertEquals($website->getName(), $customerWithStoreWebsiteFilter->getWebsiteName());
|
||||
$this->assertEquals($store->getName(), $customerWithStoreWebsiteFilter->getStoreName());
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Sales\Model\ResourceModel\Order\Grid;
|
||||
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class CollectionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests collection properties.
|
||||
*
|
||||
* @throws \ReflectionException
|
||||
* @return void
|
||||
*/
|
||||
public function testCollectionCreate(): void
|
||||
{
|
||||
/** @var Collection $gridCollection */
|
||||
$gridCollection = $this->objectManager->get(Collection::class);
|
||||
$tableDescription = $gridCollection->getConnection()
|
||||
->describeTable($gridCollection->getMainTable());
|
||||
|
||||
$mapper = new \ReflectionMethod(
|
||||
Collection::class,
|
||||
'_getMapper'
|
||||
);
|
||||
$mapper->setAccessible(true);
|
||||
$map = $mapper->invoke($gridCollection);
|
||||
|
||||
self::assertIsArray($map);
|
||||
self::assertArrayHasKey('fields', $map);
|
||||
self::assertIsArray($map['fields']);
|
||||
self::assertCount(count($tableDescription), $map['fields']);
|
||||
|
||||
foreach ($map['fields'] as $mappedName) {
|
||||
self::assertStringContainsString('main_table.', $mappedName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that filter condition date is being converted to config timezone before select sql query
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddFieldToFilter(): void
|
||||
{
|
||||
$filterDate = "2021-01-19 00:00:00";
|
||||
/** @var TimezoneInterface $timeZone */
|
||||
$timeZone = $this->objectManager->get(TimezoneInterface::class);
|
||||
/** @var Collection $gridCollection */
|
||||
$gridCollection = $this->objectManager->get(Collection::class);
|
||||
$convertedDate = $timeZone->convertConfigTimeToUtc($filterDate);
|
||||
|
||||
$collection = $gridCollection->addFieldToFilter('created_at', ['qteq' => $filterDate]);
|
||||
$expectedSelect = "SELECT `main_table`.* FROM `sales_order_grid` AS `main_table` " .
|
||||
"WHERE (((`main_table`.`created_at` = '{$convertedDate}')))";
|
||||
|
||||
$this->assertEquals($expectedSelect, $collection->getSelectSql(true));
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Sales\Model\ResourceModel\Order\Payment;
|
||||
|
||||
use Magento\Framework\Encryption\Encryptor;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
class EncryptionUpdateTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
const TEST_CC_NUMBER = '4111111111111111';
|
||||
|
||||
/**
|
||||
* Tests re-encryption of credit card numbers
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/payment_enc_cc.php
|
||||
*/
|
||||
public function testReEncryptCreditCardNumbers()
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var \Magento\Framework\Encryption\EncryptorInterface $encyptor */
|
||||
$encyptor = $objectManager->get(\Magento\Framework\Encryption\EncryptorInterface::class);
|
||||
|
||||
/** @var \Magento\Sales\Model\ResourceModel\Order\Payment\EncryptionUpdate $resource */
|
||||
$resource = $objectManager->create(\Magento\Sales\Model\ResourceModel\Order\Payment\EncryptionUpdate::class);
|
||||
$resource->reEncryptCreditCardNumbers();
|
||||
|
||||
/** @var \Magento\Sales\Model\ResourceModel\Order\Payment\Collection $collection */
|
||||
$collection = $objectManager->create(\Magento\Sales\Model\ResourceModel\Order\Payment\Collection::class);
|
||||
$collection->addFieldToFilter('cc_number_enc', ['notnull' => true]);
|
||||
|
||||
$this->assertGreaterThan(0, $collection->getTotalCount());
|
||||
|
||||
/** @var \Magento\Sales\Model\Order\Payment $payment */
|
||||
foreach ($collection->getItems() as $payment) {
|
||||
$this->assertEquals(
|
||||
static::TEST_CC_NUMBER,
|
||||
$encyptor->decrypt($payment->getCcNumberEnc())
|
||||
);
|
||||
|
||||
$this->assertStringStartsWith('0:' . Encryptor::CIPHER_LATEST . ':', $payment->getCcNumberEnc());
|
||||
}
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Sales\Model\ResourceModel\Order;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Class StatusTest
|
||||
*/
|
||||
class StatusTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Sales\Model\ResourceModel\Order\Status
|
||||
*/
|
||||
protected $resourceModel;
|
||||
|
||||
/**
|
||||
* Test setUp
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->resourceModel = Bootstrap::getObjectManager()
|
||||
->create(
|
||||
\Magento\Sales\Model\ResourceModel\Order\Status::class,
|
||||
[
|
||||
'data' => ['status' => 'fake_status']
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/assign_status_to_state.php
|
||||
*/
|
||||
public function testUnassignState()
|
||||
{
|
||||
$this->resourceModel->unassignState('fake_status_do_not_use_it', 'fake_state_do_not_use_it');
|
||||
$this->assertTrue(true);
|
||||
$this->assertFalse((bool)
|
||||
$this->resourceModel->getConnection()->fetchOne($this->resourceModel->getConnection()->select()
|
||||
->from($this->resourceModel->getTable('sales_order_status_state'), [new \Zend_Db_Expr(1)])
|
||||
->where('status = ?', 'fake_status_do_not_use_it')
|
||||
->where('state = ?', 'fake_state_do_not_use_it')));
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
+122
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Sales\Model\ResourceModel\Report\Bestsellers;
|
||||
|
||||
class CollectionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Sales\Model\ResourceModel\Report\Bestsellers\Collection
|
||||
*/
|
||||
private $_collection;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Sales\Model\ResourceModel\Report\Bestsellers\Collection::class
|
||||
);
|
||||
$this->_collection->setPeriod('day')->setDateRange(null, null)->addStoreFilter([1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/order.php
|
||||
* @magentoDataFixture Magento/Sales/_files/report_bestsellers.php
|
||||
*/
|
||||
public function testGetItems()
|
||||
{
|
||||
$expectedResult = [1 => 2];
|
||||
$actualResult = [];
|
||||
/** @var \Magento\Reports\Model\Item $reportItem */
|
||||
foreach ($this->_collection->getItems() as $reportItem) {
|
||||
$actualResult[$reportItem->getData('product_id')] = $reportItem->getData('qty_ordered');
|
||||
}
|
||||
$this->assertEquals($expectedResult, $actualResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider tableForPeriodDataProvider
|
||||
*
|
||||
* @param $period
|
||||
* @param $expectedTable
|
||||
* @param $dateFrom
|
||||
* @param $dateTo
|
||||
*/
|
||||
public function testTableSelection($period, $expectedTable, $dateFrom, $dateTo)
|
||||
{
|
||||
$dbTableName = $this->_collection->getTable($expectedTable);
|
||||
$this->_collection->setPeriod($period);
|
||||
$this->_collection->setDateRange($dateFrom, $dateTo);
|
||||
$this->_collection->load();
|
||||
$from = $this->_collection->getSelect()->getPart('from');
|
||||
|
||||
$this->assertArrayHasKey($dbTableName, $from);
|
||||
|
||||
$this->assertArrayHasKey('tableName', $from[$dbTableName]);
|
||||
$actualTable = $from[$dbTableName]['tableName'];
|
||||
|
||||
$this->assertEquals($dbTableName, $actualTable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testTableSelection
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function tableForPeriodDataProvider()
|
||||
{
|
||||
$dateNow = date('Y-m-d', time());
|
||||
$dateYearAgo = date('Y-m-d', strtotime($dateNow . ' -1 year'));
|
||||
return [
|
||||
[
|
||||
'period' => 'year',
|
||||
'table' => 'sales_bestsellers_aggregated_yearly',
|
||||
'date_from' => null,
|
||||
'date_to' => null,
|
||||
],
|
||||
[
|
||||
'period' => 'month',
|
||||
'table' => 'sales_bestsellers_aggregated_monthly',
|
||||
'date_from' => null,
|
||||
'date_to' => null
|
||||
],
|
||||
[
|
||||
'period' => 'day',
|
||||
'table' => 'sales_bestsellers_aggregated_daily',
|
||||
'date_from' => null,
|
||||
'date_to' => null
|
||||
],
|
||||
[
|
||||
'period' => 'undefinedPeriod',
|
||||
'table' => 'sales_bestsellers_aggregated_daily',
|
||||
'date_from' => null,
|
||||
'date_to' => null
|
||||
],
|
||||
[
|
||||
'period' => null,
|
||||
'table' => 'sales_bestsellers_aggregated_daily',
|
||||
'date_from' => $dateYearAgo,
|
||||
'date_to' => $dateNow
|
||||
],
|
||||
[
|
||||
'period' => null,
|
||||
'table' => 'sales_bestsellers_aggregated_daily',
|
||||
'date_from' => $dateNow,
|
||||
'date_to' => $dateNow
|
||||
],
|
||||
[
|
||||
'period' => null,
|
||||
'table' => 'sales_bestsellers_aggregated_daily',
|
||||
'date_from' => $dateYearAgo,
|
||||
'date_to' => $dateYearAgo
|
||||
],
|
||||
[
|
||||
'period' => null,
|
||||
'table' => 'sales_bestsellers_aggregated_yearly',
|
||||
'date_from' => null,
|
||||
'date_to' => null
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Sales\Model\ResourceModel\Report\Invoiced\Collection;
|
||||
|
||||
/**
|
||||
* Integration tests for invoices reports collection which is used to obtain invoice reports by invoice date.
|
||||
*/
|
||||
class InvoicedTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Sales\Model\ResourceModel\Report\Invoiced\Collection\Invoiced
|
||||
*/
|
||||
private $collection;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$this->collection = $this->objectManager->create(
|
||||
\Magento\Sales\Model\ResourceModel\Report\Invoiced\Collection\Invoiced::class
|
||||
);
|
||||
$this->collection->setPeriod('day')
|
||||
->setDateRange(null, null)
|
||||
->addStoreFilter([1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/invoice.php
|
||||
* @magentoDataFixture Magento/Sales/_files/order_from_past.php
|
||||
* @magentoDataFixture Magento/Sales/_files/report_invoiced.php
|
||||
* @return void
|
||||
*/
|
||||
public function testGetItems()
|
||||
{
|
||||
|
||||
/** @var \Magento\Sales\Model\Order $order */
|
||||
$order = $this->objectManager->create(\Magento\Sales\Model\Order::class);
|
||||
$order->loadByIncrementId('100000001');
|
||||
$invoiceCreatedAt = $order->getInvoiceCollection()
|
||||
->getFirstItem()
|
||||
->getCreatedAt();
|
||||
/** @var \Magento\Framework\Stdlib\DateTime\DateTime $dateTime */
|
||||
$dateTime = $this->objectManager->create(\Magento\Framework\Stdlib\DateTime\DateTimeFactory::class)
|
||||
->create();
|
||||
/** @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone */
|
||||
$timezone = $this->objectManager->create(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class);
|
||||
$invoiceCreatedAt = $timezone->formatDateTime(
|
||||
$invoiceCreatedAt,
|
||||
\IntlDateFormatter::SHORT,
|
||||
\IntlDateFormatter::NONE,
|
||||
null,
|
||||
null,
|
||||
'yyyy-MM-dd'
|
||||
);
|
||||
$invoiceCreatedAtDate = $dateTime->date('Y-m-d', $invoiceCreatedAt);
|
||||
|
||||
$expectedResult = [
|
||||
[
|
||||
'orders_count' => 1,
|
||||
'orders_invoiced' => 1,
|
||||
'period' => $invoiceCreatedAtDate
|
||||
],
|
||||
];
|
||||
$actualResult = [];
|
||||
/** @var \Magento\Reports\Model\Item $reportItem */
|
||||
foreach ($this->collection->getItems() as $reportItem) {
|
||||
$actualResult[] = [
|
||||
'orders_count' => $reportItem->getData('orders_count'),
|
||||
'orders_invoiced' => $reportItem->getData('orders_invoiced'),
|
||||
'period' => $reportItem->getData('period')
|
||||
];
|
||||
}
|
||||
$this->assertEquals($expectedResult, $actualResult);
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Sales\Model\ResourceModel\Report\Invoiced\Collection;
|
||||
|
||||
/**
|
||||
* Integration tests for invoices reports collection which is used to obtain invoice reports by order date.
|
||||
*/
|
||||
class OrderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Sales\Model\ResourceModel\Report\Invoiced\Collection\Order
|
||||
*/
|
||||
private $collection;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->collection = $this->objectManager->create(
|
||||
\Magento\Sales\Model\ResourceModel\Report\Invoiced\Collection\Order::class
|
||||
);
|
||||
$this->collection->setPeriod('day')
|
||||
->setDateRange(null, null)
|
||||
->addStoreFilter([1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/invoice.php
|
||||
* @magentoDataFixture Magento/Sales/_files/order_from_past.php
|
||||
* @magentoDataFixture Magento/Sales/_files/report_invoiced.php
|
||||
* @return void
|
||||
*/
|
||||
public function testGetItems()
|
||||
{
|
||||
/** @var \Magento\Sales\Model\Order $order */
|
||||
$order = $this->objectManager
|
||||
->create(\Magento\Sales\Model\Order::class);
|
||||
$order->loadByIncrementId('100000001');
|
||||
/** @var \Magento\Framework\Stdlib\DateTime\DateTime $dateTime */
|
||||
$dateTime = $this->objectManager->create(\Magento\Framework\Stdlib\DateTime\DateTimeFactory::class)
|
||||
->create();
|
||||
/** @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone */
|
||||
$timezone = $this->objectManager->create(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class);
|
||||
$orderCreatedAt = $timezone->formatDateTime(
|
||||
$order->getCreatedAt(),
|
||||
\IntlDateFormatter::SHORT,
|
||||
\IntlDateFormatter::NONE,
|
||||
null,
|
||||
null,
|
||||
'yyyy-MM-dd'
|
||||
);
|
||||
$invoiceCreatedAtDate = $dateTime->date('Y-m-d', $orderCreatedAt);
|
||||
|
||||
$expectedResult = [
|
||||
[
|
||||
'orders_count' => 1,
|
||||
'orders_invoiced' => 1,
|
||||
'period' => $invoiceCreatedAtDate
|
||||
],
|
||||
];
|
||||
$actualResult = [];
|
||||
/** @var \Magento\Reports\Model\Item $reportItem */
|
||||
foreach ($this->collection->getItems() as $reportItem) {
|
||||
$actualResult[] = [
|
||||
'orders_count' => $reportItem->getData('orders_count'),
|
||||
'orders_invoiced' => $reportItem->getData('orders_invoiced'),
|
||||
'period' => $reportItem->getData('period')
|
||||
];
|
||||
}
|
||||
$this->assertEquals($expectedResult, $actualResult);
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Sales\Model\ResourceModel\Report\Refunded\Collection;
|
||||
|
||||
/**
|
||||
* Integration tests for refunds reports collection which is used to obtain refund reports by order date.
|
||||
*/
|
||||
class OrderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Sales\Model\ResourceModel\Report\Refunded\Collection\Order
|
||||
*/
|
||||
private $collection;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->collection = $this->objectManager->create(
|
||||
\Magento\Sales\Model\ResourceModel\Report\Refunded\Collection\Order::class
|
||||
);
|
||||
$this->collection->setPeriod('day')
|
||||
->setDateRange(null, null)
|
||||
->addStoreFilter([1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/order_info.php
|
||||
* @magentoDataFixture Magento/Sales/_files/order_from_past.php
|
||||
* @magentoDataFixture Magento/Sales/_files/report_refunded.php
|
||||
* @return void
|
||||
*/
|
||||
public function testGetItems()
|
||||
{
|
||||
/** @var \Magento\Sales\Model\Order $order */
|
||||
$order = $this->objectManager->create(\Magento\Sales\Model\Order::class);
|
||||
$order->loadByIncrementId('100000001');
|
||||
/** @var \Magento\Framework\Stdlib\DateTime\DateTime $dateTime */
|
||||
$dateTime = $this->objectManager->create(\Magento\Framework\Stdlib\DateTime\DateTimeFactory::class)
|
||||
->create();
|
||||
/** @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone */
|
||||
$timezone = $this->objectManager->create(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class);
|
||||
$orderCreatedAt = $timezone->formatDateTime(
|
||||
$order->getCreatedAt(),
|
||||
\IntlDateFormatter::SHORT,
|
||||
\IntlDateFormatter::NONE,
|
||||
null,
|
||||
null,
|
||||
'yyyy-MM-dd'
|
||||
);
|
||||
$creditmemoCreatedAtDate = $dateTime->date('Y-m-d', $orderCreatedAt);
|
||||
|
||||
$expectedResult = [
|
||||
[
|
||||
'orders_count' => 1,
|
||||
'refunded' => 50,
|
||||
'online_refunded' => 50,
|
||||
'offline_refunded' => 0,
|
||||
'period' => $creditmemoCreatedAtDate
|
||||
],
|
||||
];
|
||||
$actualResult = [];
|
||||
/** @var \Magento\Reports\Model\Item $reportItem */
|
||||
foreach ($this->collection->getItems() as $reportItem) {
|
||||
$actualResult[] = array_intersect_key($reportItem->getData(), $expectedResult[0]);
|
||||
}
|
||||
$this->assertEquals($expectedResult, $actualResult);
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Sales\Model\ResourceModel\Report\Refunded\Collection;
|
||||
|
||||
/**
|
||||
* Integration tests for refunds reports collection which is used to obtain refund reports by refund date.
|
||||
*/
|
||||
class RefundedTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Sales\Model\ResourceModel\Report\Refunded\Collection\Refunded
|
||||
*/
|
||||
private $collection;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->collection = $this->objectManager->create(
|
||||
\Magento\Sales\Model\ResourceModel\Report\Refunded\Collection\Refunded::class
|
||||
);
|
||||
$this->collection->setPeriod('day')
|
||||
->setDateRange(null, null)
|
||||
->addStoreFilter([1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/order_info.php
|
||||
* @magentoDataFixture Magento/Sales/_files/order_from_past.php
|
||||
* @magentoDataFixture Magento/Sales/_files/report_refunded.php
|
||||
* @return void
|
||||
*/
|
||||
public function testGetItems()
|
||||
{
|
||||
/** @var \Magento\Sales\Model\Order $order */
|
||||
$order = $this->objectManager->create(\Magento\Sales\Model\Order::class);
|
||||
$order->loadByIncrementId('100000001');
|
||||
$creditmemoCreatedAt = $order->getCreditmemosCollection()->getFirstItem()->getCreatedAt();
|
||||
/** @var \Magento\Framework\Stdlib\DateTime\DateTime $dateTime */
|
||||
$dateTime = $this->objectManager->create(\Magento\Framework\Stdlib\DateTime\DateTimeFactory::class)
|
||||
->create();
|
||||
/** @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone */
|
||||
$timezone = $this->objectManager->create(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class);
|
||||
$creditmemoCreatedAt = $timezone->formatDateTime(
|
||||
$creditmemoCreatedAt,
|
||||
\IntlDateFormatter::SHORT,
|
||||
\IntlDateFormatter::NONE,
|
||||
null,
|
||||
null,
|
||||
'yyyy-MM-dd'
|
||||
);
|
||||
$creditmemoCreatedAtDate = $dateTime->date('Y-m-d', $creditmemoCreatedAt);
|
||||
|
||||
$expectedResult = [
|
||||
[
|
||||
'orders_count' => 1,
|
||||
'refunded' => 50,
|
||||
'online_refunded' => 50,
|
||||
'offline_refunded' => 0,
|
||||
'period' => $creditmemoCreatedAtDate
|
||||
],
|
||||
];
|
||||
$actualResult = [];
|
||||
/** @var \Magento\Reports\Model\Item $reportItem */
|
||||
foreach ($this->collection->getItems() as $reportItem) {
|
||||
$actualResult[] = array_intersect_key($reportItem->getData(), $expectedResult[0]);
|
||||
}
|
||||
$this->assertEquals($expectedResult, $actualResult);
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Sales\Model\ResourceModel\Report\Shipping\Collection;
|
||||
|
||||
/**
|
||||
* Integration tests for shipments reports collection which is used to obtain shipment reports by order date.
|
||||
*/
|
||||
class OrderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Sales\Model\ResourceModel\Report\Shipping\Collection\Order
|
||||
*/
|
||||
private $collection;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->collection = $this->objectManager->create(
|
||||
\Magento\Sales\Model\ResourceModel\Report\Shipping\Collection\Order::class
|
||||
);
|
||||
$this->collection->setPeriod('day')
|
||||
->setDateRange(null, null)
|
||||
->addStoreFilter([1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/order_shipping.php
|
||||
* @magentoDataFixture Magento/Sales/_files/order_from_past.php
|
||||
* @magentoDataFixture Magento/Sales/_files/report_shipping.php
|
||||
* @return void
|
||||
*/
|
||||
public function testGetItems()
|
||||
{
|
||||
/** @var \Magento\Sales\Model\Order $order */
|
||||
$order = $this->objectManager->create(\Magento\Sales\Model\Order::class);
|
||||
$order->loadByIncrementId('100000001');
|
||||
/** @var \Magento\Framework\Stdlib\DateTime\DateTime $dateTime */
|
||||
$dateTime = $this->objectManager->create(\Magento\Framework\Stdlib\DateTime\DateTimeFactory::class)
|
||||
->create();
|
||||
/** @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone */
|
||||
$timezone = $this->objectManager->create(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class);
|
||||
$orderCreatedAt = $timezone->formatDateTime(
|
||||
$order->getCreatedAt(),
|
||||
\IntlDateFormatter::SHORT,
|
||||
\IntlDateFormatter::NONE,
|
||||
null,
|
||||
null,
|
||||
'yyyy-MM-dd'
|
||||
);
|
||||
$shipmentCreatedAtDate = $dateTime->date('Y-m-d', $orderCreatedAt);
|
||||
|
||||
$expectedResult = [
|
||||
[
|
||||
'orders_count' => 1,
|
||||
'total_shipping' => 36,
|
||||
'total_shipping_actual' => 34,
|
||||
'period' => $shipmentCreatedAtDate
|
||||
],
|
||||
];
|
||||
$actualResult = [];
|
||||
/** @var \Magento\Reports\Model\Item $reportItem */
|
||||
foreach ($this->collection->getItems() as $reportItem) {
|
||||
$actualResult[] = array_intersect_key($reportItem->getData(), $expectedResult[0]);
|
||||
}
|
||||
$this->assertEquals($expectedResult, $actualResult);
|
||||
}
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Sales\Model\ResourceModel\Report\Shipping\Collection;
|
||||
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\Stdlib\DateTime\DateTime;
|
||||
use Magento\Framework\Stdlib\DateTime\DateTimeFactory;
|
||||
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
|
||||
use Magento\Reports\Model\Item;
|
||||
use Magento\Sales\Model\ResourceModel\Order\Shipment\Grid\Collection as ShipmentGridCollection;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Integration tests for shipments reports collection which is used to obtain shipment reports by shipment date.
|
||||
*/
|
||||
class ShipmentTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Shipment
|
||||
*/
|
||||
private $collection;
|
||||
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->collection = $this->objectManager->create(
|
||||
Shipment::class
|
||||
);
|
||||
$this->collection->setPeriod('day')
|
||||
->setDateRange(null, null)
|
||||
->addStoreFilter([1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/order_shipping.php
|
||||
* @magentoDataFixture Magento/Sales/_files/order_from_past.php
|
||||
* @magentoDataFixture Magento/Sales/_files/report_shipping.php
|
||||
* @return void
|
||||
*/
|
||||
public function testGetItems()
|
||||
{
|
||||
/** @var \Magento\Sales\Model\Order $order */
|
||||
$order = $this->objectManager->create(\Magento\Sales\Model\Order::class);
|
||||
$order->loadByIncrementId('100000001');
|
||||
$shipmentCreatedAt = $order->getShipmentsCollection()->getFirstItem()->getCreatedAt();
|
||||
/** @var DateTime $dateTime */
|
||||
$dateTime = $this->objectManager->create(DateTimeFactory::class)
|
||||
->create();
|
||||
/** @var TimezoneInterface $timezone */
|
||||
$timezone = $this->objectManager->create(TimezoneInterface::class);
|
||||
$shipmentCreatedAt = $timezone->formatDateTime(
|
||||
$shipmentCreatedAt,
|
||||
\IntlDateFormatter::SHORT,
|
||||
\IntlDateFormatter::NONE,
|
||||
null,
|
||||
null,
|
||||
'yyyy-MM-dd'
|
||||
);
|
||||
$shipmentCreatedAtDate = $dateTime->date('Y-m-d', $shipmentCreatedAt);
|
||||
|
||||
$expectedResult = [
|
||||
[
|
||||
'orders_count' => 1,
|
||||
'total_shipping' => 36,
|
||||
'total_shipping_actual' => 34,
|
||||
'period' => $shipmentCreatedAtDate
|
||||
],
|
||||
];
|
||||
$actualResult = [];
|
||||
/** @var Item $reportItem */
|
||||
foreach ($this->collection->getItems() as $reportItem) {
|
||||
$actualResult[] = array_intersect_key($reportItem->getData(), $expectedResult[0]);
|
||||
}
|
||||
$this->assertEquals($expectedResult, $actualResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that order_created_at field does not change after sales_shipment_grid row update
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/order_shipping.php
|
||||
* @return void
|
||||
*/
|
||||
public function testOrderShipmentGridOrderCreatedAt(): void
|
||||
{
|
||||
$incrementId = '100000001';
|
||||
/** @var \Magento\Sales\Model\Order $order */
|
||||
$order = $this->objectManager->create(\Magento\Sales\Model\Order::class);
|
||||
$order->loadByIncrementId($incrementId);
|
||||
/** @var ShipmentGridCollection $grid */
|
||||
$grid = $this->objectManager->get(ShipmentGridCollection::class);
|
||||
$grid->getSelect()
|
||||
->where('order_increment_id', $incrementId);
|
||||
$itemId = $grid->getFirstItem()
|
||||
->getEntityId();
|
||||
$connection = $grid->getResource()
|
||||
->getConnection();
|
||||
$tableName = $grid->getMainTable();
|
||||
$connection->update(
|
||||
$tableName,
|
||||
['customer_name' => 'Test'],
|
||||
$connection->quoteInto('entity_id = ?', $itemId)
|
||||
);
|
||||
$updatedRow = $connection->select()
|
||||
->where('entity_id = ?', $itemId)
|
||||
->from($tableName, ['order_created_at']);
|
||||
$orderCreatedAt = $connection->fetchOne($updatedRow);
|
||||
|
||||
$this->assertEquals($order->getCreatedAt(), $orderCreatedAt);
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Sales\Model\ResourceModel\Sale;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
class CollectionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/order_with_customer.php
|
||||
*/
|
||||
public function testSetCustomerFilter()
|
||||
{
|
||||
$collectionModel = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Sales\Model\ResourceModel\Sale\Collection::class
|
||||
);
|
||||
$this->assertEquals(1, $collectionModel->setCustomerIdFilter(1)->count());
|
||||
$collectionModel = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Sales\Model\ResourceModel\Sale\Collection::class
|
||||
);
|
||||
$this->assertEquals(0, $collectionModel->setCustomerIdFilter(2)->count());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Sales\Model\Service;
|
||||
|
||||
use Magento\Sales\Api\Data\OrderInterface;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Tests \Magento\Sales\Model\Service\InvoiceService
|
||||
*/
|
||||
class InvoiceServiceTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var InvoiceService
|
||||
*/
|
||||
private $invoiceService;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->invoiceService = Bootstrap::getObjectManager()->create(InvoiceService::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $invoiceQty
|
||||
* @magentoDataFixture Magento/Sales/_files/order_configurable_product.php
|
||||
* @return void
|
||||
* @dataProvider prepareInvoiceConfigurableProductDataProvider
|
||||
*/
|
||||
public function testPrepareInvoiceConfigurableProduct(int $invoiceQty): void
|
||||
{
|
||||
/** @var OrderInterface $order */
|
||||
$order = Bootstrap::getObjectManager()->create(Order::class)->load('100000001', 'increment_id');
|
||||
$orderItems = $order->getItems();
|
||||
foreach ($orderItems as $orderItem) {
|
||||
if ($orderItem->getParentItemId()) {
|
||||
$parentItemId = $orderItem->getParentItemId();
|
||||
}
|
||||
}
|
||||
$invoice = $this->invoiceService->prepareInvoice($order, [$parentItemId => $invoiceQty]);
|
||||
$invoiceItems = $invoice->getItems();
|
||||
foreach ($invoiceItems as $invoiceItem) {
|
||||
$this->assertEquals($invoiceQty, $invoiceItem->getQty());
|
||||
}
|
||||
}
|
||||
|
||||
public function prepareInvoiceConfigurableProductDataProvider()
|
||||
{
|
||||
return [
|
||||
'full invoice' => [2],
|
||||
'partial invoice' => [1]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $invoiceQty
|
||||
* @magentoDataFixture Magento/Sales/_files/order.php
|
||||
* @return void
|
||||
* @dataProvider prepareInvoiceSimpleProductDataProvider
|
||||
*/
|
||||
public function testPrepareInvoiceSimpleProduct(int $invoiceQty): void
|
||||
{
|
||||
/** @var OrderInterface $order */
|
||||
$order = Bootstrap::getObjectManager()->create(Order::class)->load('100000001', 'increment_id');
|
||||
$orderItems = $order->getItems();
|
||||
$invoiceQtys = [];
|
||||
foreach ($orderItems as $orderItem) {
|
||||
$invoiceQtys[$orderItem->getItemId()] = $invoiceQty;
|
||||
}
|
||||
$invoice = $this->invoiceService->prepareInvoice($order, $invoiceQtys);
|
||||
$invoiceItems = $invoice->getItems();
|
||||
foreach ($invoiceItems as $invoiceItem) {
|
||||
$this->assertEquals($invoiceQty, $invoiceItem->getQty());
|
||||
}
|
||||
}
|
||||
|
||||
public function prepareInvoiceSimpleProductDataProvider()
|
||||
{
|
||||
return [
|
||||
'full invoice' => [2],
|
||||
'partial invoice' => [1]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if ordered and invoiced qty of bundle product does match.
|
||||
*
|
||||
* @param array $qtyToInvoice
|
||||
* @param array $qtyInvoiced
|
||||
* @param string $errorMsg
|
||||
* @return void
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
* @magentoDataFixture Magento/Sales/_files/order_with_bundle.php
|
||||
* @dataProvider bundleProductQtyOrderedDataProvider
|
||||
*/
|
||||
public function testPrepareInvoiceBundleProduct(
|
||||
array $qtyToInvoice,
|
||||
array $qtyInvoiced,
|
||||
string $errorMsg
|
||||
): void {
|
||||
/** @var Order $order */
|
||||
$order = Bootstrap::getObjectManager()->create(Order::class)
|
||||
->load('100000001', 'increment_id');
|
||||
|
||||
$predefinedQtyToInvoice = $this->getPredefinedQtyToInvoice($order, $qtyToInvoice);
|
||||
$invoice = $this->invoiceService->prepareInvoice($order, $predefinedQtyToInvoice);
|
||||
|
||||
foreach ($invoice->getItems() as $invoiceItem) {
|
||||
if (isset($qtyInvoiced[$invoiceItem->getSku()])) {
|
||||
$this->assertEquals(
|
||||
$qtyInvoiced[$invoiceItem->getSku()],
|
||||
$invoiceItem->getQty(),
|
||||
sprintf($errorMsg, $invoiceItem->getSku())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for invoice creation with and w/o predefined qty to invoice.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function bundleProductQtyOrderedDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'Create invoice w/o predefined qty' => [
|
||||
'Qty to invoice' => [],
|
||||
'Qty ordered' => [
|
||||
'bundle_1' => 2,
|
||||
'bundle_simple_1' => 10,
|
||||
],
|
||||
'Error msg' => 'Invoiced qty for product %s does not match.',
|
||||
],
|
||||
'Create invoice with predefined qty' => [
|
||||
'Qty to invoice' => [
|
||||
'bundle_1' => 2,
|
||||
'bundle_simple_1' => 10,
|
||||
],
|
||||
'Qty ordered' => [
|
||||
'bundle_1' => 2,
|
||||
'bundle_simple_1' => 10,
|
||||
],
|
||||
'Error msg' => 'Invoiced qty for product %s does not match.',
|
||||
],
|
||||
'Create invoice with partial predefined qty for bundle' => [
|
||||
'Qty to invoice' => [
|
||||
'bundle_1' => 1,
|
||||
],
|
||||
'Qty ordered' => [
|
||||
'bundle_1' => 1,
|
||||
'bundle_simple_1' => 5,
|
||||
],
|
||||
'Error msg' => 'Invoiced qty for product %s does not match.',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Associate product qty to invoice to order item id.
|
||||
*
|
||||
* @param Order $order
|
||||
* @param array $qtyToInvoice
|
||||
* @return array
|
||||
*/
|
||||
private function getPredefinedQtyToInvoice(Order $order, array $qtyToInvoice): array
|
||||
{
|
||||
$predefinedQtyToInvoice = [];
|
||||
|
||||
foreach ($order->getAllItems() as $orderItem) {
|
||||
if (array_key_exists($orderItem->getSku(), $qtyToInvoice)) {
|
||||
$predefinedQtyToInvoice[$orderItem->getId()] = $qtyToInvoice[$orderItem->getSku()];
|
||||
}
|
||||
}
|
||||
|
||||
return $predefinedQtyToInvoice;
|
||||
}
|
||||
}
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Sales\Model\Service;
|
||||
|
||||
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Sales\Api\PaymentFailuresInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
/**
|
||||
* Tests \Magento\Sales\Api\PaymentFailuresInterface.
|
||||
*/
|
||||
class PaymentFailuresServiceTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var PaymentFailuresInterface
|
||||
*/
|
||||
private $paymentFailures;
|
||||
|
||||
/**
|
||||
* @var Quote
|
||||
*/
|
||||
private $quote;
|
||||
|
||||
/**
|
||||
* @var CartRepositoryInterface|MockObject
|
||||
*/
|
||||
private $cartRepositoryMock;
|
||||
|
||||
/**
|
||||
* @var TimezoneInterface|MockObject
|
||||
*/
|
||||
private $localeDateMock;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->quote = Bootstrap::getObjectManager()->create(Quote::class);
|
||||
$this->cartRepositoryMock = $this->getMockBuilder(CartRepositoryInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['get'])
|
||||
->getMockForAbstractClass();
|
||||
$this->localeDateMock = $this->getMockBuilder(TimezoneInterface::class)
|
||||
->setMethods(['formatDateTime'])
|
||||
->getMockForAbstractClass();
|
||||
|
||||
$this->paymentFailures = Bootstrap::getObjectManager()->create(
|
||||
PaymentFailuresInterface::class,
|
||||
[
|
||||
'cartRepository' => $this->cartRepositoryMock,
|
||||
'localeDate' => $this->localeDateMock,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/quote_with_two_products_and_customer.php
|
||||
* @magentoConfigFixture cataloginventory/options/enable_inventory_check 1
|
||||
* @magentoConfigFixture current_store payment/payflowpro/title Some Title Of The Method
|
||||
* @magentoConfigFixture current_store carriers/freeshipping/title Some Shipping Method
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @return void
|
||||
*/
|
||||
public function testHandlerWithCustomer(): void
|
||||
{
|
||||
$errorMessage = __('Transaction declined.');
|
||||
$checkoutType = 'custom_checkout';
|
||||
|
||||
$this->quote->load('test01', 'reserved_order_id');
|
||||
$this->cartRepositoryMock->method('get')
|
||||
->with($this->quote->getId())
|
||||
->willReturn($this->quote);
|
||||
|
||||
$dateAndTime = 'Nov 22, 2019, 1:00:00 AM';
|
||||
$this->localeDateMock->expects($this->atLeastOnce())->method('formatDateTime')->willReturn($dateAndTime);
|
||||
$this->paymentFailures->handle((int)$this->quote->getId(), $errorMessage->render());
|
||||
|
||||
$paymentReflection = new \ReflectionClass($this->paymentFailures);
|
||||
$templateVarsMethod = $paymentReflection->getMethod('getTemplateVars');
|
||||
$templateVarsMethod->setAccessible(true);
|
||||
|
||||
$templateVars = $templateVarsMethod->invoke($this->paymentFailures, $this->quote, $errorMessage, $checkoutType);
|
||||
$expectedVars = [
|
||||
'reason' => $errorMessage->render(),
|
||||
'checkoutType' => $checkoutType,
|
||||
'dateAndTime' => $dateAndTime,
|
||||
'customer' => 'John Smith',
|
||||
'customerEmail' => 'aaa@aaa.com',
|
||||
'paymentMethod' => 'Some Title Of The Method',
|
||||
'shippingMethod' => 'Some Shipping Method',
|
||||
'items' => 'Simple Product x 2 USD 10<br />Custom Design Simple Product x 1 USD 10',
|
||||
'total' => 'USD 30.0000',
|
||||
'billingAddress' => $this->quote->getBillingAddress(),
|
||||
'shippingAddress' => $this->quote->getShippingAddress(),
|
||||
'billingAddressHtml' => $this->quote->getBillingAddress()->format('html'),
|
||||
'shippingAddressHtml' => $this->quote->getShippingAddress()->format('html'),
|
||||
];
|
||||
|
||||
$this->assertEquals($expectedVars, $templateVars);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/quote_with_two_products_and_customer.php
|
||||
* @magentoConfigFixture cataloginventory/options/enable_inventory_check 0
|
||||
* @magentoConfigFixture current_store payment/payflowpro/title Some Title Of The Method
|
||||
* @magentoConfigFixture current_store carriers/freeshipping/title Some Shipping Method
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @return void
|
||||
*/
|
||||
public function testHandlerWithCustomerWithInventoryCheckDisabled(): void
|
||||
{
|
||||
$errorMessage = __('Transaction declined.');
|
||||
$checkoutType = 'custom_checkout';
|
||||
|
||||
$this->quote->load('test01', 'reserved_order_id');
|
||||
$this->cartRepositoryMock->method('get')
|
||||
->with($this->quote->getId())
|
||||
->willReturn($this->quote);
|
||||
|
||||
$dateAndTime = 'Nov 22, 2019, 1:00:00 AM';
|
||||
$this->localeDateMock->expects($this->atLeastOnce())->method('formatDateTime')->willReturn($dateAndTime);
|
||||
$this->paymentFailures->handle((int)$this->quote->getId(), $errorMessage->render());
|
||||
|
||||
$paymentReflection = new \ReflectionClass($this->paymentFailures);
|
||||
$templateVarsMethod = $paymentReflection->getMethod('getTemplateVars');
|
||||
$templateVarsMethod->setAccessible(true);
|
||||
|
||||
$templateVars = $templateVarsMethod->invoke($this->paymentFailures, $this->quote, $errorMessage, $checkoutType);
|
||||
$expectedVars = [
|
||||
'reason' => $errorMessage->render(),
|
||||
'checkoutType' => $checkoutType,
|
||||
'dateAndTime' => $dateAndTime,
|
||||
'customer' => 'John Smith',
|
||||
'customerEmail' => 'aaa@aaa.com',
|
||||
'paymentMethod' => 'Some Title Of The Method',
|
||||
'shippingMethod' => 'Some Shipping Method',
|
||||
'items' => 'Simple Product x 2.0000 USD 10<br />Custom Design Simple Product x 1.0000 USD 10',
|
||||
'total' => 'USD 30.0000',
|
||||
'billingAddress' => $this->quote->getBillingAddress(),
|
||||
'shippingAddress' => $this->quote->getShippingAddress(),
|
||||
'billingAddressHtml' => $this->quote->getBillingAddress()->format('html'),
|
||||
'shippingAddressHtml' => $this->quote->getShippingAddress()->format('html'),
|
||||
];
|
||||
|
||||
$this->assertEquals($expectedVars, $templateVars);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user