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,110 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Sales\Controller\Guest;
use Magento\Customer\Model\Session;
use Magento\Framework\Data\Form\FormKey;
use Magento\Framework\Message\MessageInterface;
use Magento\TestFramework\Request;
use Magento\TestFramework\TestCase\AbstractController;
/**
* @magentoAppIsolation enabled
*/
class FormTest extends AbstractController
{
/**
* Test view order as guest with correct data
*
* @magentoDataFixture Magento/Sales/_files/order.php
*/
public function testViewOrderAsGuest()
{
$this->prepareRequestData();
$this->dispatch('sales/guest/view/');
$content = $this->getResponse()->getBody();
$this->assertStringContainsString('Order # 100000001', $content);
}
/**
* View order as logged in customer
*
* @magentoDataFixture Magento/Sales/_files/order.php
* @magentoDataFixture Magento/Customer/_files/customer.php
*/
public function testViewOrderAsLoggedIn()
{
$this->login(1);
$this->getRequest()->setMethod(Request::METHOD_POST);
$this->dispatch('sales/guest/view/');
$this->assertRedirect($this->stringContains('sales/order/history/'));
}
/**
* Test attempting to open the Returns form as logged in customer
*
* @magentoDataFixture Magento/Sales/_files/order.php
* @magentoDataFixture Magento/Customer/_files/customer.php
*/
public function testAttemptToOpenTheFormAsLoggedIn()
{
$this->login(1);
$this->dispatch('sales/guest/form/');
$this->assertRedirect($this->stringContains('sales/order/history'));
}
/**
* Test Return Order for guest with incorrect data
*/
public function testViewOrderAsGuestWithIncorrectData()
{
$this->prepareRequestData(true);
$this->dispatch('sales/guest/view/');
$this->assertSessionMessages(
$this->equalTo(['You entered incorrect data. Please try again.']),
MessageInterface::TYPE_ERROR
);
}
/**
* Login the user
*
* @param string $customerId Customer to mark as logged in for the session
* @return void
*/
protected function login($customerId)
{
/** @var Session $session */
$session = $this->_objectManager->get(Session::class);
$session->loginById($customerId);
}
/**
* @param bool $invalidData
* @return void
*/
private function prepareRequestData($invalidData = false)
{
$orderId = 100000001;
$email = $invalidData ? 'wrong@example.com' : 'customer@example.com';
/** @var FormKey $formKey */
$formKey = $this->_objectManager->get(FormKey::class);
$post = [
'oar_order_id' => $orderId,
'oar_billing_lastname' => 'lastname',
'oar_type' => 'email',
'oar_email' => $email,
'oar_zip' => '',
'form_key' => $formKey->getFormKey(),
];
$this->getRequest()->setMethod(Request::METHOD_POST);
$this->getRequest()->setPostValue($post);
}
}
@@ -0,0 +1,139 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Sales\Controller\Guest;
use Magento\Checkout\Model\Session as CheckoutSession;
use Magento\Customer\Model\Session;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Message\MessageInterface;
use Magento\Framework\Stdlib\CookieManagerInterface;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Sales\Api\Data\OrderInterfaceFactory;
use Magento\Sales\Helper\Guest;
use Magento\TestFramework\Request;
use Magento\TestFramework\TestCase\AbstractController;
/**
* Test for guest reorder controller.
*
* @see \Magento\Sales\Controller\Guest\Reorder
* @magentoAppArea frontend
* @magentoDbIsolation enabled
*/
class ReorderTest extends AbstractController
{
/** @var CheckoutSession */
private $checkoutSession;
/** @var OrderInterfaceFactory */
private $orderFactory;
/** @var CookieManagerInterface */
private $cookieManager;
/** @var Session */
private $customerSession;
/** @var CartRepositoryInterface */
private $quoteRepository;
/**
* @inheritdoc
*/
protected function setUp(): void
{
parent::setUp();
$this->checkoutSession = $this->_objectManager->get(CheckoutSession::class);
$this->orderFactory = $this->_objectManager->get(OrderInterfaceFactory::class);
$this->cookieManager = $this->_objectManager->get(CookieManagerInterface::class);
$this->customerSession = $this->_objectManager->get(Session::class);
$this->quoteRepository = $this->_objectManager->get(CartRepositoryInterface::class);
}
/**
* @inheritdoc
*/
protected function tearDown(): void
{
$createdQuoteId = $this->checkoutSession->getQuoteId();
if ($createdQuoteId !== null) {
try {
$this->quoteRepository->delete($this->quoteRepository->get($createdQuoteId));
} catch (NoSuchEntityException $e) {
//already deleted
}
}
$this->customerSession->setCustomerId(null);
parent::tearDown();
}
/**
* @magentoDbIsolation disabled
*
* @magentoDataFixture Magento/Sales/_files/order_by_guest_with_simple_product.php
*
* @return void
*/
public function testReorderSimpleProduct(): void
{
$orderIncrementId = 'test_order_1';
$order = $this->orderFactory->create()->loadByIncrementId($orderIncrementId);
$cookieValue = base64_encode($order->getProtectCode() . ':' . $orderIncrementId);
$this->cookieManager->setPublicCookie(Guest::COOKIE_NAME, $cookieValue);
$this->dispatchReorderRequest();
$this->assertRedirect($this->stringContains('checkout/cart'));
$quoteId = $this->checkoutSession->getQuoteId();
$this->assertNotNull($quoteId);
$quoteItemsCollection = $this->quoteRepository->get((int)$quoteId)->getItemsCollection();
$this->assertCount(1, $quoteItemsCollection);
$this->assertEquals(
$order->getItemsCollection()->getFirstItem()->getSku(),
$quoteItemsCollection->getFirstItem()->getSku()
);
}
/**
* @return void
*/
public function testReorderWithoutParamsAndCookie(): void
{
$this->dispatchReorderRequest();
$this->assertRedirect($this->stringContains('sales/guest/form'));
$this->assertSessionMessages(
$this->containsEqual((string)__('You entered incorrect data. Please try again.')),
MessageInterface::TYPE_ERROR
);
}
/**
* @magentoDataFixture Magento/Customer/_files/customer.php
*
* @return void
*/
public function testReorderGuestOrderByCustomer(): void
{
$this->customerSession->setCustomerId(1);
$this->dispatchReorderRequest();
$this->assertRedirect($this->stringContains('sales/order/history'));
}
/**
* Dispatch reorder request.
*
* @return void
*/
private function dispatchReorderRequest(): void
{
$this->getRequest()->setMethod(Request::METHOD_POST);
$this->dispatch('sales/guest/reorder/');
}
}
@@ -0,0 +1,77 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Sales\Controller\Guest;
use Magento\Framework\Stdlib\CookieManagerInterface;
use Magento\Sales\Api\Data\OrderInterfaceFactory;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Helper\Guest;
use Magento\TestFramework\Request;
use Magento\TestFramework\TestCase\AbstractController;
/**
* Test for orders and returns controller.
*
* @see \Magento\Sales\Controller\Guest\View
*/
class ViewTest extends AbstractController
{
/** @var CookieManagerInterface */
private $cookieManager;
/** @var OrderInterfaceFactory */
private $orderFactory;
/** @var OrderRepositoryInterface */
private $orderRepository;
/**
* @inheritdoc
*/
protected function setUp(): void
{
parent::setUp();
$this->cookieManager = $this->_objectManager->get(CookieManagerInterface::class);
$this->orderFactory = $this->_objectManager->get(OrderInterfaceFactory::class);
$this->orderRepository = $this->_objectManager->get(OrderRepositoryInterface::class);
}
/**
* Check that controller applied GET requests.
*
* @return void
*/
public function testExecuteWithGetRequest(): void
{
$this->getRequest()->setMethod(Request::METHOD_GET);
$this->dispatch('sales/guest/view/');
$this->assertRedirect($this->stringContains('sales/guest/form'));
}
/**
* @magentoDataFixture Magento/Sales/_files/order.php
*
* @return void
*/
public function testExecuteWithWrongCookie(): void
{
$order = $this->orderFactory->create()->loadByIncrementId('100000001');
$order->setProtectCode('0e6640');
$this->orderRepository->save($order);
$cookieValue = base64_encode('0' . ':' . $order->getIncrementId());
$this->cookieManager->setPublicCookie(Guest::COOKIE_NAME, $cookieValue);
$this->getRequest()->setMethod(Request::METHOD_GET);
$this->dispatch('sales/guest/view/');
$this->assertRedirect($this->stringContains('sales/guest/form/'));
$this->assertSessionMessages(
$this->containsEqual((string)__('You entered incorrect data. Please try again.'))
);
}
}