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,67 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Downloadable\Block\Account;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\View\Result\Page;
use Magento\Framework\View\Result\PageFactory;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
/**
* Checks My Downloadable Product link displaying in account dashboard
*
* @magentoAppArea frontend
* @magentoDbIsolation enabled
*/
class LinkTest extends TestCase
{
/** @var ObjectManagerInterface */
private $objectManager;
/** @var Page */
private $page;
/**
* @inheritdoc
*/
protected function setUp(): void
{
parent::setUp();
$this->objectManager = Bootstrap::getObjectManager();
$this->page = $this->objectManager->get(PageFactory::class)->create();
}
/**
* @return void
*/
public function testMyDownloadableProductLink(): void
{
$this->preparePage();
$block = $this->page->getLayout()->getBlock('customer-account-navigation-downloadable-products-link');
$this->assertNotFalse($block);
$html = $block->toHtml();
$this->assertStringContainsString('downloadable/customer/products', $html);
$this->assertEquals('My Downloadable Products', strip_tags($html));
}
/**
* Prepare page before render
*
* @return void
*/
private function preparePage(): void
{
$this->page->addHandle([
'default',
'customer_account',
]);
$this->page->getLayout()->generateXml();
}
}
@@ -0,0 +1,123 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Downloadable\Block\Adminhtml\Catalog\Product\Edit\Tab\Downloadable;
/**
* Class LinksTest
*
* @package Magento\Downloadable\Block\Adminhtml\Catalog\Product\Edit\Tab\Downloadable
* @deprecated
* @see \Magento\Downloadable\Ui\DataProvider\Product\Form\Modifier\Links
*/
class LinksTest extends \PHPUnit\Framework\TestCase
{
/**
* @magentoAppArea adminhtml
*/
public function testGetUploadButtonsHtml()
{
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
)->createBlock(
\Magento\Downloadable\Block\Adminhtml\Catalog\Product\Edit\Tab\Downloadable\Links::class
);
self::performUploadButtonTest($block);
}
/**
* Reuse code for testing getUploadButtonHtml()
*
* @param \Magento\Framework\View\Element\AbstractBlock $block
*/
public static function performUploadButtonTest(\Magento\Framework\View\Element\AbstractBlock $block)
{
/** @var $layout \Magento\Framework\View\LayoutInterface */
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Framework\View\Layout::class
);
$layout->addBlock($block, 'links');
$expected = uniqid();
$text = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
)->createBlock(
\Magento\Framework\View\Element\Text::class,
'',
['data' => ['text' => $expected]]
);
$block->unsetChild('upload_button');
$layout->addBlock($text, 'upload_button', 'links');
self::assertEquals($expected, $block->getUploadButtonHtml());
}
/**
* @magentoAppArea adminhtml
* @magentoAppIsolation enabled
*/
public function testGetLinkData()
{
/** @var $objectManager \Magento\TestFramework\ObjectManager */
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$objectManager->get(
\Magento\Framework\Registry::class
)->register(
'product',
new \Magento\Framework\DataObject(['type_id' => 'simple'])
);
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
)->createBlock(
\Magento\Downloadable\Block\Adminhtml\Catalog\Product\Edit\Tab\Downloadable\Links::class
);
$this->assertEmpty($block->getLinkData());
}
/**
* Get Links Title for simple/virtual/downloadable product
*
* @magentoConfigFixture current_store catalog/downloadable/links_title Links Title Test
* @magentoAppIsolation enabled
* @dataProvider productLinksTitleDataProvider
*
* @magentoAppArea adminhtml
* @param string $productType
* @param string $linksTitle
* @param string $expectedResult
*/
public function testGetLinksTitle($productType, $linksTitle, $expectedResult)
{
/** @var $objectManager \Magento\TestFramework\ObjectManager */
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$objectManager->get(
\Magento\Framework\Registry::class
)->register(
'product',
new \Magento\Framework\DataObject(['type_id' => $productType, 'id' => '1', 'links_title' => $linksTitle])
);
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
)->createBlock(
\Magento\Downloadable\Block\Adminhtml\Catalog\Product\Edit\Tab\Downloadable\Links::class
);
$this->assertEquals($expectedResult, $block->getLinksTitle());
}
/**
* Data Provider with product types
*
* @return array
*/
public function productLinksTitleDataProvider()
{
return [
['simple', null, 'Links Title Test'],
['simple', 'Links Title', 'Links Title Test'],
['virtual', null, 'Links Title Test'],
['virtual', 'Links Title', 'Links Title Test'],
['downloadable', null, null],
['downloadable', 'Links Title', 'Links Title']
];
}
}
@@ -0,0 +1,101 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Downloadable\Block\Adminhtml\Catalog\Product\Edit\Tab\Downloadable;
/**
* Class SamplesTest
*
* @package Magento\Downloadable\Block\Adminhtml\Catalog\Product\Edit\Tab\Downloadable
* @deprecated
* @see \Magento\Downloadable\Ui\DataProvider\Product\Form\Modifier\Samples
*/
class SamplesTest extends \PHPUnit\Framework\TestCase
{
public function testGetUploadButtonsHtml()
{
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
)->createBlock(
\Magento\Downloadable\Block\Adminhtml\Catalog\Product\Edit\Tab\Downloadable\Samples::class
);
\Magento\Downloadable\Block\Adminhtml\Catalog\Product\Edit\Tab\Downloadable\LinksTest::performUploadButtonTest(
$block
);
}
/**
* @magentoAppIsolation enabled
*/
public function testGetSampleData()
{
/** @var $objectManager \Magento\TestFramework\ObjectManager */
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$objectManager->get(
\Magento\Framework\Registry::class
)->register(
'current_product',
new \Magento\Framework\DataObject(['type_id' => 'simple'])
);
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
)->createBlock(
\Magento\Downloadable\Block\Adminhtml\Catalog\Product\Edit\Tab\Downloadable\Samples::class
);
$this->assertEmpty($block->getSampleData());
}
/**
* Get Samples Title for simple/virtual/downloadable product
*
* @magentoConfigFixture current_store catalog/downloadable/samples_title Samples Title Test
* @magentoAppIsolation enabled
* @dataProvider productSamplesTitleDataProvider
*
* @param string $productType
* @param string $samplesTitle
* @param string $expectedResult
*/
public function testGetSamplesTitle($productType, $samplesTitle, $expectedResult)
{
/** @var $objectManager \Magento\TestFramework\ObjectManager */
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$objectManager->get(
\Magento\Framework\Registry::class
)->register(
'current_product',
new \Magento\Framework\DataObject(
[
'type_id' => $productType,
'id' => '1',
'samples_title' => $samplesTitle,
]
)
);
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
)->createBlock(
\Magento\Downloadable\Block\Adminhtml\Catalog\Product\Edit\Tab\Downloadable\Samples::class
);
$this->assertEquals($expectedResult, $block->getSamplesTitle());
}
/**
* Data Provider with product types
*
* @return array
*/
public function productSamplesTitleDataProvider()
{
return [
['simple', null, 'Samples Title Test'],
['simple', 'Samples Title', 'Samples Title Test'],
['virtual', null, 'Samples Title Test'],
['virtual', 'Samples Title', 'Samples Title Test'],
['downloadable', null, null],
['downloadable', 'Samples Title', 'Samples Title']
];
}
}
@@ -0,0 +1,184 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Downloadable\Block\Customer\Products;
use Magento\Customer\Model\Session;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\View\LayoutInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\InvoiceOrderInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Api\RefundOrderInterface;
use Magento\Sales\Model\OrderFactory;
use Magento\Sales\Model\OrderRepository;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Helper\Xpath;
use PHPUnit\Framework\TestCase;
/**
* Class to check My Downloadable products tab content
*
* @see ListProducts
* @magentoAppArea frontend
* @magentoAppIsolation enabled
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ListProductsTest extends TestCase
{
/** @var string */
private $downloadLinkXpath = "//a[contains(@href, 'downloadable/download/link') and contains(text(), '%s')]";
/** @var string */
private $statusXpath = "//table[@id='my-downloadable-products-table']"
. "//td[@data-th='Status' and contains(text(), '%s')]";
/** @var ObjectManagerInterface */
private $objectManager;
/** @var LayoutInterface */
private $layout;
/** @var Session */
private $customerSession;
/** @var OrderRepositoryInterface */
private $orderRepository;
/** @var InvoiceOrderInterface */
private $invoiceOrder;
/**
* @inheritdoc
*/
protected function setUp(): void
{
parent::setUp();
$this->objectManager = Bootstrap::getObjectManager();
$this->layout = $this->objectManager->get(LayoutInterface::class);
$this->customerSession = $this->objectManager->get(Session::class);
$this->orderRepository = $this->objectManager->get(OrderRepositoryInterface::class);
$this->invoiceOrder = $this->objectManager->get(InvoiceOrderInterface::class);
}
/**
* @inheritdoc
*/
protected function tearDown(): void
{
$this->customerSession->logout();
parent::tearDown();
}
/**
* @return void
*/
public function testNoItems(): void
{
$html = $this->createBlock()->toHtml();
$this->assertStringContainsString(
(string)__('You have not purchased any downloadable products yet.'),
strip_tags($html)
);
}
/**
* @magentoDataFixture Magento/Downloadable/_files/order_with_customer_and_downloadable_product.php
*
* @return void
*/
public function testPendingOrder(): void
{
$this->customerSession->loginById(1);
$this->assertEquals(
0,
Xpath::getElementsCountForXpath(
sprintf($this->downloadLinkXpath, 'Downloadable Product Link'),
$this->createBlock()->toHtml()
),
'The download link displayed'
);
}
/**
* @magentoDataFixture Magento/Downloadable/_files/order_with_customer_and_downloadable_product.php
*
* @return void
*/
public function testCompleteOrder(): void
{
$order = $this->getOrder('100000001');
$this->invoiceOrder->execute($order->getId());
$this->customerSession->loginById(1);
$html = $this->createBlock()->toHtml();
$this->assertEquals(
1,
Xpath::getElementsCountForXpath(sprintf($this->downloadLinkXpath, 'Downloadable Product Link'), $html),
'The download link is not found'
);
$this->assertEquals(
1,
Xpath::getElementsCountForXpath(sprintf($this->statusXpath, (string)__('Available')), $html),
'Wrong status displayed'
);
}
/**
* @magentoDataFixture Magento/Downloadable/_files/order_with_customer_and_downloadable_product.php
*
* @return void
*/
public function testClosedOrder(): void
{
$order = $this->getOrder('100000001');
$this->invoiceOrder->execute($order->getId());
$this->objectManager->removeSharedInstance(OrderRepository::class);
$refundOrder = $this->objectManager->create(RefundOrderInterface::class);
$refundOrder->execute($order->getId());
$this->customerSession->loginById(1);
$html = $this->createBlock()->toHtml();
$this->assertEquals(
0,
Xpath::getElementsCountForXpath(sprintf($this->downloadLinkXpath, 'Downloadable Product Link'), $html),
'The download link is displayed for closed order'
);
$this->assertEquals(
1,
Xpath::getElementsCountForXpath(sprintf($this->statusXpath, (string)__('Expired')), $html),
'Wrong status displayed'
);
}
/**
* Load order by increment id
*
* @param $orderIncrementId
* @return OrderInterface
*/
private function getOrder($orderIncrementId): OrderInterface
{
$order = $this->objectManager->get(OrderFactory::class)->create();
return $order->loadByIncrementId($orderIncrementId);
}
/**
* Create ProductsList block
*
* @return ListProducts
*/
private function createBlock(): ListProducts
{
$block = $this->objectManager->create(ListProducts::class);
$block->setTemplate('Magento_Downloadable::customer/products/list.phtml');
$this->layout->addBlock($block, 'downloadable_customer_products_list');
return $block;
}
}
@@ -0,0 +1,83 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Downloadable\Block\Sales\Order\Email\Items\Order;
use Magento\Checkout\Model\Session as CheckoutSession;
use Magento\Framework\ObjectManagerInterface;
use Magento\Quote\Api\GuestCartManagementInterface;
use Magento\Quote\Model\Quote;
use Magento\Quote\Model\QuoteIdMask;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Mail\Template\TransportBuilderMock;
use PHPUnit\Framework\TestCase;
use Magento\Quote\Model\QuoteIdMaskFactory;
/**
* Test order confirmation email for downloadable product.
*
* @magentoDbIsolation enabled
* @magentoAppArea frontend
*/
class DownloadableTest extends TestCase
{
/**
* @var ObjectManagerInterface
*/
private $objectManager;
/**
* @var TransportBuilderMock
*/
private $transportBuilder;
/**
* @var QuoteIdMaskFactory
*/
private $quoteIdMaskFactory;
/**
* @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);
}
/**
* @magentoDataFixture Magento/Downloadable/_files/quote_with_configurable_downloadable_product.php
* @return void
*/
public function testShouldSendDownloadableLinksInTheEmail(): void
{
/** @var Quote $quote */
$quote = $this->objectManager->create(Quote::class);
$quote->load('reserved_order_configurable_downloadable', '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);
$cartManagement->placeOrder($cartId);
$message = $this->transportBuilder->getSentMessage();
$rawMessage = $message->getBody()->getParts()[0]->getRawContent();
$this->assertStringContainsString('Configurable Downloadable Product', $rawMessage);
$this->assertStringContainsString('SKU: downloadable-product', $rawMessage);
$this->assertStringContainsString('Downloadable Product Link', $rawMessage);
$this->assertStringContainsString('/downloadable/download/link/id/', $rawMessage);
}
}