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,79 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Wishlist\Block\Account;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\View\Result\Page;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
/**
* Checks My Wish List link displaying in account dashboard
*
* @magentoAppArea frontend
* @magentoDbIsolation enabled
* @magentoAppIsolation 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->create(Page::class);
}
/**
* @return void
*/
public function testNewsletterLink(): void
{
$this->preparePage();
$block = $this->page->getLayout()->getBlock('customer-account-navigation-wish-list-link');
$this->assertNotFalse($block);
$html = $block->toHtml();
$this->assertStringContainsString('wishlist/', $html);
$this->assertEquals('My Wish List', strip_tags($html));
}
/**
* @magentoConfigFixture current_store wishlist/general/active 0
*
* @return void
*/
public function testNewsletterLinkDisabled(): void
{
$this->preparePage();
$block = $this->page->getLayout()->getBlock('customer-account-navigation-wish-list-link');
$this->assertFalse($block);
}
/**
* Prepare page before render
*
* @return void
*/
private function preparePage(): void
{
$this->page->addHandle([
'default',
'customer_account',
]);
$this->page->getLayout()->generateXml();
}
}
@@ -0,0 +1,69 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Wishlist\Block\Catalog\Product\ProductList\Item\AddTo;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\View\LayoutInterface;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
/**
* Checks add to wishlist button on category page.
*
* @magentoAppArea frontend
* @magentoDbIsolation enabled
* @magentoAppIsolation disabled
*/
class WishlistTest extends TestCase
{
/** @var ObjectManagerInterface */
private $objectManager;
/** @var Wishlist */
private $block;
/** @var ProductRepositoryInterface */
private $productRepository;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
$this->productRepository->cleanCache();
$this->block = $this->objectManager->get(LayoutInterface::class)
->createBlock(Wishlist::class)->setTemplate('Magento_Wishlist::catalog/product/list/addto/wishlist.phtml');
}
/**
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
*
* @return void
*/
public function testAddToWishListVisible(): void
{
$product = $this->productRepository->get('simple2');
$html = $this->block->setProduct($product)->toHtml();
$this->assertEquals('Add to Wish List', trim(strip_tags($html)));
}
/**
* @magentoConfigFixture current_store wishlist/general/active 0
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
*
* @return void
*/
public function testAddToWishListNotVisible(): void
{
$product = $this->productRepository->get('simple2');
$this->assertEmpty($this->block->setProduct($product)->toHtml());
}
}
@@ -0,0 +1,108 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Wishlist\Block\Catalog\Product\View\AddTo;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\Registry;
use Magento\Framework\View\LayoutInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Helper\Xpath;
use PHPUnit\Framework\TestCase;
/**
* Checks add to wishlist button on product page.
*
* @magentoAppArea frontend
* @magentoDbIsolation enabled
* @magentoAppIsolation disabled
*/
class WishlistTest extends TestCase
{
private const ADD_TO_WISHLIST_XPATH = "//a[@data-action='add-to-wishlist']"
. "/span[contains(text(), 'Add to Wish List')]";
/** @var ObjectManagerInterface */
private $objectManager;
/** @var Registry */
private $registry;
/** @var Wishlist */
private $block;
/** @var ProductRepositoryInterface */
private $productRepository;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->registry = $this->objectManager->get(Registry::class);
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
$this->productRepository->cleanCache();
$this->block = $this->objectManager->get(LayoutInterface::class)
->createBlock(Wishlist::class)->setTemplate('Magento_Wishlist::catalog/product/view/addto/wishlist.phtml');
}
/**
* @inheritdoc
*/
protected function tearDown(): void
{
$this->registry->unregister('product');
parent::tearDown();
}
/**
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
*
* @return void
*/
public function testAddToWishListVisible(): void
{
$product = $this->productRepository->get('simple2');
$this->registerProduct($product);
$this->assertEquals(
1,
Xpath::getElementsCountForXpath(self::ADD_TO_WISHLIST_XPATH, $this->block->toHtml())
);
}
/**
* @magentoConfigFixture current_store wishlist/general/active 0
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
*
* @return void
*/
public function testAddToWishListNotVisible(): void
{
$product = $this->productRepository->get('simple2');
$this->registerProduct($product);
$this->assertEquals(
0,
Xpath::getElementsCountForXpath(self::ADD_TO_WISHLIST_XPATH, $this->block->toHtml())
);
}
/**
* Register the product.
*
* @param ProductInterface $product
* @return void
*/
private function registerProduct(ProductInterface $product): void
{
$this->registry->unregister('product');
$this->registry->register('product', $product);
}
}
@@ -0,0 +1,61 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Wishlist\Block\Customer;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\View\LayoutInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Helper\Xpath;
use PHPUnit\Framework\TestCase;
/**
* Class test share wish list block.
*
* @magentoDbIsolation enabled
* @magentoAppArea frontend
*/
class SharingTest extends TestCase
{
/** @var ObjectManagerInterface */
private $objectManager;
/** @var Sharing */
private $block;
/**
* @inheritdoc
*/
protected function setUp(): void
{
parent::setUp();
$this->objectManager = Bootstrap::getObjectManager();
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(Sharing::class);
}
/**
* @return void
*/
public function testDisplayWishListSharingForm(): void
{
$elementsXpath = [
'Emails input' => "//form[contains(@class, 'share')]//textarea[@name='emails' and @id='email_address']",
'Message input' => "//form[contains(@class, 'share')]//textarea[@name='message' and @id='message']",
'Share button' => "//form[contains(@class, 'share')]//button[contains(@class, 'submit')]"
. "/span[contains(text(), 'Share Wish List')]",
];
$blockHtml = $this->block->setTemplate('Magento_Wishlist::sharing.phtml')->toHtml();
foreach ($elementsXpath as $element => $xpath) {
$this->assertEquals(
1,
Xpath::getElementsCountForXpath($xpath, $blockHtml),
sprintf("%s was not found.", $element)
);
}
}
}
@@ -0,0 +1,94 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Wishlist\Block\Customer;
use Magento\Framework\App\ProductMetadata;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\View\Result\Page;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Helper\Xpath;
use PHPUnit\Framework\TestCase;
/**
* Class test sidebar wish list block.
*
* @magentoAppArea frontend
* @magentoDbIsolation enabled
* @magentoAppIsolation enabled
*/
class SidebarTest extends TestCase
{
private const BLOCK_NAME = 'wishlist_sidebar';
/** @var ObjectManagerInterface */
private $objectManager;
/** @var Page */
private $page;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$productMetadataInterface = $this->objectManager->get(ProductMetadataInterface::class);
if ($productMetadataInterface->getEdition() !== ProductMetadata::EDITION_NAME) {
$this->markTestSkipped('Skipped, because this logic is rewritten on EE.');
}
$this->page = $this->objectManager->create(Page::class);
}
/**
* @magentoConfigFixture current_store wishlist/general/show_in_sidebar 1
*
* @return void
*/
public function testSidebarWishListVisible(): void
{
$this->preparePageLayout();
$block = $this->page->getLayout()->getBlock(self::BLOCK_NAME);
$this->assertNotFalse($block);
$this->assertEquals(
1,
Xpath::getElementsCountForXpath(
"//div[contains(@class, 'block-wishlist')]//strong[contains(text(), 'My Wish List')]",
$block->toHtml()
)
);
}
/**
* @magentoConfigFixture current_store wishlist/general/show_in_sidebar 0
*
* @return void
*/
public function testSidebarWishListNotVisible(): void
{
$this->preparePageLayout();
$this->assertFalse(
$this->page->getLayout()->getBlock(self::BLOCK_NAME),
'Sidebar wish list should not be visible.'
);
}
/**
* Prepare category page.
*
* @return void
*/
private function preparePageLayout(): void
{
$this->page->addHandle([
'default',
'catalog_category_view',
]);
$this->page->getLayout()->generateXml();
}
}
@@ -0,0 +1,132 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Wishlist\Block\Customer\Wishlist\Item;
use Magento\Customer\Model\Session;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\View\Element\Text;
use Magento\Framework\View\LayoutInterface;
use Magento\Framework\View\Result\PageFactory;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Helper\Xpath;
use Magento\TestFramework\Wishlist\Model\GetWishlistByCustomerId;
use Magento\Wishlist\Block\Customer\Wishlist\Items;
use PHPUnit\Framework\TestCase;
/**
* Test wish list item column.
*
* @magentoDbIsolation disabled
* @magentoAppArea frontend
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ColumnTest extends TestCase
{
/** @var ObjectManagerInterface */
private $objectManager;
/** @var Session */
private $customerSession;
/** @var LayoutInterface */
private $layout;
/** @var Column */
private $block;
/** @var GetWishlistByCustomerId */
private $getWishlistItemsByCustomerId;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->customerSession = $this->objectManager->get(Session::class);
$this->layout = $this->objectManager->get(LayoutInterface::class);
$this->block = $this->layout->addBlock(Column::class, 'test');
$this->layout->addBlock(Text::class, 'child', 'test');
$this->getWishlistItemsByCustomerId = $this->objectManager->get(GetWishlistByCustomerId::class);
}
/**
* @inheritdoc
*/
protected function tearDown(): void
{
$this->customerSession->setCustomerId(null);
parent::tearDown();
}
/**
* @magentoAppIsolation enabled
*
* @return void
*/
public function testToHtml(): void
{
$item = new \StdClass();
$this->block->setItem($item);
$this->block->toHtml();
$this->assertSame($item, $this->layout->getBlock('child')->getItem());
}
/**
* @return void
*/
public function testGetJs(): void
{
$expected = uniqid();
$this->layout->getBlock('child')->setJs($expected);
$this->assertEquals($expected, $this->block->getJs());
}
/**
* @magentoDataFixture Magento/Wishlist/_files/wishlist.php
*
* @return void
*/
public function testWishListItemButtons(): void
{
$buttons = [
"Add to Cart button" => "//button[contains(@class, 'tocart')]/span[contains(text(), 'Add to Cart')]",
"Edit button" => "//a[contains(@class, 'edit')]/span[contains(text(), 'Edit')]",
"Remove item button" => "//a[contains(@class, 'delete')]/span[contains(text(), 'Remove item')]",
];
$item = $this->getWishlistItemsByCustomerId->getItemBySku(1, 'simple');
$this->assertNotNull($item);
$block = $this->getWishListItemsBlock()->getChildBlock('customer.wishlist.item.inner');
$blockHtml = $block->setItem($item)->toHtml();
foreach ($buttons as $buttonName => $xpath) {
$this->assertEquals(
1,
Xpath::getElementsCountForXpath($xpath, $blockHtml),
sprintf("%s wasn't found.", $buttonName)
);
}
}
/**
* Get wish list items block.
*
* @return Items
*/
private function getWishListItemsBlock(): Items
{
$page = $this->objectManager->create(PageFactory::class)->create();
$page->addHandle([
'default',
'wishlist_index_index',
]);
$page->getLayout()->generateXml();
return $page->getLayout()->getBlock('customer.wishlist.items');
}
}
@@ -0,0 +1,29 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Test class for \Magento\Wishlist\Block\Customer\Wishlist\Item\Options.
*/
namespace Magento\Wishlist\Block\Customer\Wishlist\Item;
class OptionsTest extends \PHPUnit\Framework\TestCase
{
public function testGetTemplate()
{
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
)->createBlock(
\Magento\Wishlist\Block\Customer\Wishlist\Item\Options::class
);
$this->assertEmpty($block->getTemplate());
$product = new \Magento\Framework\DataObject(['type_id' => 'test']);
$item = new \Magento\Framework\DataObject(['product' => $product]);
$block->setItem($item);
$this->assertNotEmpty($block->getTemplate());
$block->setTemplate('template');
$this->assertEquals('template', $block->getTemplate());
}
}
@@ -0,0 +1,31 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Wishlist\Block\Customer\Wishlist;
class ItemsTest extends \PHPUnit\Framework\TestCase
{
public function testGetColumns()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$layout = $objectManager->get(
\Magento\Framework\View\LayoutInterface::class
);
$block = $layout->addBlock(\Magento\Wishlist\Block\Customer\Wishlist\Items::class, 'test');
$child = $this->getMockBuilder(\Magento\Wishlist\Block\Customer\Wishlist\Item\Column::class)
->setMethods(['isEnabled'])
->disableOriginalConstructor()
->getMock();
$child->expects($this->any())->method('isEnabled')->willReturn(true);
$layout->addBlock($child, 'child', 'test');
$expected = $child->getType();
$columns = $block->getColumns();
$this->assertNotEmpty($columns);
foreach ($columns as $column) {
$this->assertSame($expected, $column->getType());
}
}
}
@@ -0,0 +1,129 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Wishlist\Block\Customer;
use Magento\Customer\Model\Session;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\View\Result\Page;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Helper\Xpath;
use PHPUnit\Framework\TestCase;
/**
* Class test block wish list on customer account page.
*
* @magentoAppArea frontend
* @magentoDbIsolation disabled
* @magentoAppIsolation disabled
*/
class WishlistTest extends TestCase
{
private const ITEMS_COUNT_XPATH = "//div[contains(@class, 'pager')]//span[contains(@class, 'toolbar-number')"
. " and contains(text(), '%s Item')]";
/** @var ObjectManagerInterface */
private $objectManager;
/** @var Page */
private $page;
/** @var Session */
private $customerSession;
/**
* @inheritdoc
*/
protected function setUp(): void
{
parent::setUp();
$this->objectManager = Bootstrap::getObjectManager();
$this->page = $this->objectManager->create(Page::class);
$this->customerSession = $this->objectManager->get(Session::class);
}
/**
* @inheritdoc
*/
protected function tearDown(): void
{
$this->customerSession->setCustomerId(null);
parent::tearDown();
}
/**
* @magentoConfigFixture current_store wishlist/wishlist_link/use_qty 0
* @magentoDataFixture Magento/Wishlist/_files/wishlist_with_product_qty_three.php
*
* @return void
*/
public function testDisplayNumberOfItemsInWishList(): void
{
$this->customerSession->setCustomerId(1);
$pagerBlockHtml = $this->getWishListBlock()->getChildBlock('wishlist_item_pager')->toHtml();
$this->assertEquals(
1,
Xpath::getElementsCountForXpath(sprintf(self::ITEMS_COUNT_XPATH, 1), $pagerBlockHtml),
"Element items count wasn't found."
);
}
/**
* @magentoConfigFixture current_store wishlist/wishlist_link/use_qty 1
* @magentoDataFixture Magento/Wishlist/_files/wishlist_with_product_qty_three.php
*
* @return void
*/
public function testDisplayItemQuantitiesInWishList(): void
{
$this->markTestSkipped('Test is blocked by issue MC-31595');
$this->customerSession->setCustomerId(1);
$pagerBlockHtml = $this->getWishListBlock()->getChildBlock('wishlist_item_pager')->toHtml();
$this->assertEquals(
1,
Xpath::getElementsCountForXpath(sprintf(self::ITEMS_COUNT_XPATH, 3), $pagerBlockHtml),
"Element items count wasn't found."
);
}
/**
* @magentoDataFixture Magento/Wishlist/_files/wishlist.php
*
* @return void
*/
public function testDisplayActionButtonsInWishList(): void
{
$buttonsXpath = [
"//button[contains(@class, 'update') and @type='submit']/span[contains(text(), 'Update Wish List')]",
"//button[contains(@class, 'share') and @type='submit']/span[contains(text(), 'Share Wish List')]",
"//button[contains(@class, 'tocart') and @type='button']/span[contains(text(), 'Add All to Cart')]",
];
$this->customerSession->setCustomerId(1);
$blockHtml = $this->getWishListBlock()->toHtml();
foreach ($buttonsXpath as $xpath) {
$this->assertEquals(1, Xpath::getElementsCountForXpath($xpath, $blockHtml));
}
}
/**
* Get wish list block.
*
* @return Wishlist
*/
private function getWishListBlock(): Wishlist
{
$this->page->addHandle([
'default',
'wishlist_index_index',
]);
$this->page->getLayout()->generateXml();
return $this->page->getLayout()->getBlock('customer.wishlist');
}
}
@@ -0,0 +1,56 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Wishlist\Block;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\View\LayoutInterface;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
/**
* Class test link my wish list in customer menu.
*
* @magentoAppArea frontend
* @magentoDbIsolation enabled
* @magentoAppIsolation disabled
*/
class LinkTest extends TestCase
{
/** @var ObjectManagerInterface */
private $objectManager;
/** @var Link */
private $block;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(Link::class);
}
/**
* @return void
*/
public function testWishListLinkVisible(): void
{
$this->assertStringContainsString('My Wish List', strip_tags($this->block->toHtml()));
}
/**
* @magentoConfigFixture current_store wishlist/general/active 0
*
* @return void
*/
public function testWishListLinkNotVisible(): void
{
$this->assertEmpty($this->block->toHtml());
}
}
@@ -0,0 +1,55 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Wishlist\Block\Share;
class WishlistTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\TestFramework\ObjectManager
*/
protected $_objectManager;
/**
* @var \Magento\Wishlist\Block\Share\Wishlist
*/
protected $_block;
/**
* @var \Magento\Customer\Model\Session
*/
protected $_customerSession;
protected function setUp(): void
{
$this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->_customerSession = $this->_objectManager->get(\Magento\Customer\Model\Session::class);
$this->_block = $this->_objectManager->create(\Magento\Wishlist\Block\Share\Wishlist::class);
}
/**
* @magentoDataFixture Magento/Customer/_files/customer.php
* @magentoDataFixture Magento/Wishlist/_files/wishlist.php
*/
public function testGetWishlistCustomer()
{
$this->_customerSession->loginById(1);
$expectedCustomer = $this->_customerSession->getCustomerDataObject();
$actualCustomer = $this->_block->getWishlistCustomer();
$this->assertInstanceOf(\Magento\Customer\Api\Data\CustomerInterface::class, $actualCustomer);
$this->assertEquals((int)$expectedCustomer->getId(), (int)$actualCustomer->getId());
$this->assertEquals((int)$expectedCustomer->getWebsiteId(), (int)$actualCustomer->getWebsiteId());
$this->assertEquals((int)$expectedCustomer->getStoreId(), (int)$actualCustomer->getStoreId());
$this->assertEquals((int)$expectedCustomer->getGroupId(), (int)$actualCustomer->getGroupId());
$this->assertEquals($expectedCustomer->getCustomAttributes(), $actualCustomer->getCustomAttributes());
$this->assertEquals($expectedCustomer->getFirstname(), $actualCustomer->getFirstname());
$this->assertEquals($expectedCustomer->getLastname(), $actualCustomer->getLastname());
$this->assertEquals($expectedCustomer->getEmail(), $actualCustomer->getEmail());
$this->assertEquals($expectedCustomer->getEmail(), $actualCustomer->getEmail());
$this->assertEquals((int)$expectedCustomer->getDefaultBilling(), (int)$actualCustomer->getDefaultBilling());
$this->assertEquals((int)$expectedCustomer->getDefaultShipping(), (int)$actualCustomer->getDefaultShipping());
}
}