ltsecurityinc安防产品在线商城代码

This commit is contained in:
2026-09-14 17:47:10 +08:00
parent 57d8444c15
commit 6a3c9c5bd8
14539 changed files with 1775310 additions and 0 deletions
@@ -0,0 +1,150 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Multishipping\Controller\Checkout;
use Magento\Customer\Api\AccountManagementInterface;
use Magento\Customer\Model\Session as CustomerSession;
use Magento\Framework\App\Request\Http as HttpRequest;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Message\MessageInterface;
use Magento\Quote\Api\Data\CartInterface;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Quote\Api\CartRepositoryInterface as QuoteRepository;
use Magento\TestFramework\TestCase\AbstractController;
use Psr\Log\LoggerInterface;
/**
* Test class for @see \Magento\Multishipping\Controller\Checkout\AddressesPost.
*
* @magentoAppArea frontend
*/
class AddressesPostTest extends AbstractController
{
/**
* @var QuoteRepository
*/
private $quoteRepository;
/**
* @inheritdoc
*/
protected function setUp(): void
{
parent::setUp();
$this->quoteRepository = $this->_objectManager->get(QuoteRepository::class);
}
/**
* @magentoDataFixture Magento/Checkout/_files/quote_with_address.php
*/
public function testExecute()
{
$quote = $this->getQuote('test_order_1');
$this->setMultiShippingToQuote($quote);
$quoteItems = $quote->getItems();
$quoteItemId = array_shift($quoteItems)->getItemId();
$this->loginCustomer();
$qty = 3;
$productPrice = 10;
$request = [
'ship' => [
1 => [
$quoteItemId => [
'qty' => $qty,
'address' => 1,
],
],
]
];
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
$this->getRequest()->setPostValue($request);
$this->dispatch('multishipping/checkout/addressesPost');
$freshQuote = $this->getQuote('test_order_1');
$this->assertEquals($qty, $freshQuote->getItemsQty());
$this->assertEquals($productPrice * $qty, $freshQuote->getGrandTotal());
}
/**
* @magentoDataFixture Magento/Checkout/_files/quote_with_address.php
*/
public function testExecuteFail()
{
$msg = 'Verify the shipping address information and continue.';
$quote = $this->getQuote('test_order_1');
$this->setMultiShippingToQuote($quote);
$quoteItems = $quote->getItems();
$quoteItemId = array_shift($quoteItems)->getItemId();
$this->loginCustomer();
$request = [
'ship' => [
1 => [
$quoteItemId => [
'qty' => 1,
'address' => $quoteItemId,
],
],
],
];
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
$this->getRequest()->setPostValue($request);
$this->dispatch('multishipping/checkout/addressesPost');
$this->assertSessionMessages($this->equalTo([$msg]), MessageInterface::TYPE_ERROR);
}
/**
* @param CartInterface $quote
* @return void
*/
private function setMultiShippingToQuote(CartInterface $quote): void
{
$quote->setIsMultiShipping(1);
$this->quoteRepository->save($quote);
}
/**
* Authenticates customer and creates customer session.
*
* @return void
*/
private function loginCustomer(): void
{
$logger = $this->createMock(LoggerInterface::class);
/** @var AccountManagementInterface $service */
$service = $this->_objectManager->create(AccountManagementInterface::class);
try {
$customer = $service->authenticate('customer@example.com', 'password');
} catch (LocalizedException $e) {
$this->fail($e->getMessage());
}
/** @var CustomerSession $customerSession */
$customerSession = $this->_objectManager->get(CustomerSession::class, [$logger]);
$customerSession->setCustomerDataAsLoggedIn($customer);
}
/**
* Gets quote by reserved order id.
*
* @param string $reservedOrderId
* @return CartInterface
*/
private function getQuote(string $reservedOrderId): CartInterface
{
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
$searchCriteriaBuilder = $this->_objectManager->create(SearchCriteriaBuilder::class);
$searchCriteria = $searchCriteriaBuilder->addFilter('reserved_order_id', $reservedOrderId)->create();
/** @var QuoteRepository $quoteRepository */
$quoteRepository = $this->_objectManager->get(QuoteRepository::class);
$items = $quoteRepository->getList($searchCriteria)->getItems();
return array_pop($items);
}
}
@@ -0,0 +1,176 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Multishipping\Controller\Checkout;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Checkout\Model\Session;
use Magento\Customer\Api\AccountManagementInterface;
use Magento\Customer\Model\Session as CustomerSession;
use Magento\Framework\Exception\LocalizedException;
use Magento\Quote\Model\Quote;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Quote\Api\CartRepositoryInterface as QuoteRepository;
use Magento\Framework\Serialize\Serializer\Json;
/**
* Test class for \Magento\Multishipping\Controller\Checkout
*
* @magentoAppArea frontend
* @magentoDataFixture Magento/Sales/_files/quote.php
* @magentoDataFixture Magento/Customer/_files/customer.php
*/
class CheckItemsTest extends \Magento\TestFramework\TestCase\AbstractController
{
/**
* @var Quote
*/
private $quote;
/**
* @var Session
*/
private $checkoutSession;
/**
* @var ProductRepositoryInterface
*/
private $productRepository;
/**
* @var Json
*/
private $json;
/**
* @inheritdoc
*/
protected function setUp(): void
{
parent::setUp();
$this->checkoutSession = $this->_objectManager->get(Session::class);
$this->productRepository = $this->_objectManager->get(ProductRepositoryInterface::class);
$this->json = $this->_objectManager->get(Json::class);
$this->quote = $this->getQuote('test01');
$this->checkoutSession->setQuoteId($this->quote->getId());
$this->checkoutSession->setCartWasUpdated(false);
}
/**
* Validator of quote items.
*
* @param array $requestQuantity
* @param array $expectedResponse
*
* @magentoConfigFixture current_store multishipping/options/checkout_multiple 1
* @magentoConfigFixture current_store multishipping/options/checkout_multiple_maximum_qty 200
* @dataProvider requestDataProvider
*/
public function testExecute($requestQuantity, $expectedResponse)
{
$this->loginCustomer();
try {
/** @var $product Product */
$product = $this->productRepository->get('simple');
} catch (\Exception $e) {
$this->fail('No such product entity');
}
$quoteItem = $this->quote->getItemByProduct($product);
$this->assertNotFalse($quoteItem, 'Cannot get quote item for simple product');
$request = [];
if (!empty($requestQuantity) && is_array($requestQuantity)) {
$request= [
'ship' => [
[$quoteItem->getId() => $requestQuantity],
]
];
}
$this->getRequest()->setPostValue($request);
$this->dispatch('multishipping/checkout/checkItems');
$response = $this->getResponse()->getBody();
$this->assertEquals($expectedResponse, $this->json->unserialize($response));
}
/**
* Authenticates customer and creates customer session.
*/
private function loginCustomer()
{
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
/** @var AccountManagementInterface $service */
$service = $this->_objectManager->create(AccountManagementInterface::class);
try {
$customer = $service->authenticate('customer@example.com', 'password');
} catch (LocalizedException $e) {
$this->fail($e->getMessage());
}
/** @var CustomerSession $customerSession */
$customerSession = $this->_objectManager->create(CustomerSession::class, [$logger]);
$customerSession->setCustomerDataAsLoggedIn($customer);
}
/**
* Gets quote by reserved order id.
*
* @param string $reservedOrderId
* @return Quote
*/
private function getQuote($reservedOrderId)
{
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
$searchCriteriaBuilder = $this->_objectManager->create(SearchCriteriaBuilder::class);
$searchCriteria = $searchCriteriaBuilder->addFilter('reserved_order_id', $reservedOrderId)
->create();
/** @var QuoteRepository $quoteRepository */
$quoteRepository = $this->_objectManager->get(QuoteRepository::class);
$items = $quoteRepository->getList($searchCriteria)
->getItems();
return array_pop($items);
}
/**
* Variations of request data.
* @returns array
*/
public function requestDataProvider(): array
{
return [
[
'request' => [],
'response' => [
'success' => false,
'error_message' => 'We are unable to process your request. Please, try again later.'
]
],
[
'request' => ['qty' => 2],
'response' => [
'success' => true,
]
],
[
'request' => ['qty' => 101],
'response' => [
'success' => false,
'error_message' => 'The requested qty is not available']
],
[
'request' => ['qty' => 230],
'response' => [
'success' => false,
'error_message' => 'Maximum qty allowed for Shipping to multiple addresses is 200']
],
];
}
}
@@ -0,0 +1,76 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Multishipping\Controller;
use Magento\Multishipping\Model\Checkout\Type\Multishipping\State;
/**
* Test class for \Magento\Multishipping\Controller\Checkout
*
* @magentoAppArea frontend
* @magentoDataFixture Magento/Sales/_files/quote.php
* @magentoDataFixture Magento/Customer/_files/customer.php
*/
class CheckoutTest extends \Magento\TestFramework\TestCase\AbstractController
{
/**
* @var \Magento\Quote\Model\Quote
*/
protected $quote;
/**
* @var \Magento\Checkout\Model\Session
*/
protected $checkoutSession;
/**
* @inheritdoc
*/
protected function setUp(): void
{
parent::setUp();
$this->quote = $this->_objectManager->create(\Magento\Quote\Model\Quote::class);
$this->checkoutSession = $this->_objectManager->get(\Magento\Checkout\Model\Session::class);
$this->quote->load('test01', 'reserved_order_id');
$this->checkoutSession->setQuoteId($this->quote->getId());
$this->checkoutSession->setCartWasUpdated(false);
}
/**
* Covers \Magento\Multishipping\Block\Checkout\Payment\Info and \Magento\Multishipping\Block\Checkout\Overview
*
* @magentoConfigFixture current_store multishipping/options/checkout_multiple 1
*/
public function testOverviewAction()
{
/** @var \Magento\Framework\Data\Form\FormKey $formKey */
$formKey = $this->_objectManager->get(\Magento\Framework\Data\Form\FormKey::class);
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
/** @var \Magento\Customer\Api\AccountManagementInterface $service */
$service = $this->_objectManager->create(\Magento\Customer\Api\AccountManagementInterface::class);
$customer = $service->authenticate('customer@example.com', 'password');
/** @var \Magento\Customer\Model\Session $customerSession */
$customerSession = $this->_objectManager->create(\Magento\Customer\Model\Session::class, [$logger]);
$customerSession->setCustomerDataAsLoggedIn($customer);
$this->checkoutSession->setCheckoutState(State::STEP_BILLING);
$this->getRequest()->setPostValue('payment', ['method' => 'checkmo']);
$this->dispatch('multishipping/checkout/overview');
$html = $this->getResponse()->getBody();
$this->assertStringContainsString('<div class="box box-billing-method">', $html);
$this->assertStringContainsString('<div class="box box-shipping-method">', $html);
$this->assertStringContainsString(
'<dt class="title">' . $this->quote->getPayment()->getMethodInstance()->getTitle() . '</dt>',
$html
);
$this->assertStringContainsString('<span class="price">$10.00</span>', $html);
$this->assertStringContainsString(
'<input name="form_key" type="hidden" value="' . $formKey->getFormKey(),
$html
);
}
}