ltsecurityinc安防产品在线商城代码
This commit is contained in:
+112
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\MediaContentCatalog\Model\ResourceModel;
|
||||
|
||||
use Magento\Framework\Exception\InvalidArgumentException;
|
||||
use Magento\MediaContentApi\Api\GetAssetIdsByContentFieldInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test for GetAssetIdsByContentFieldTest
|
||||
*/
|
||||
class GetAssetIdsByContentFieldTest extends TestCase
|
||||
{
|
||||
private const STORE_FIELD = 'store_id';
|
||||
private const STATUS_FIELD = 'content_status';
|
||||
private const STATUS_ENABLED = '1';
|
||||
private const STATUS_DISABLED = '0';
|
||||
private const FIXTURE_ASSET_ID = 2020;
|
||||
private const DEFAULT_STORE_ID = '1';
|
||||
|
||||
/**
|
||||
* @var GetAssetIdsByContentFieldInterface
|
||||
*/
|
||||
private $getAssetIdsByContentField;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->getAssetIdsByContentField = $objectManager->get(GetAssetIdsByContentFieldInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getting asset id by category fields
|
||||
*
|
||||
* @dataProvider dataProvider
|
||||
* @magentoConfigFixture system/media_gallery/enabled 1
|
||||
* @magentoDataFixture Magento/MediaGallery/_files/media_asset.php
|
||||
* @magentoDataFixture Magento/MediaContentCatalog/_files/category_with_asset.php
|
||||
*
|
||||
* @param string $field
|
||||
* @param string $value
|
||||
* @param array $expectedAssetIds
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function testCategoryFields(string $field, string $value, array $expectedAssetIds): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expectedAssetIds,
|
||||
$this->getAssetIdsByContentField->execute($field, $value)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getting asset id by product fields
|
||||
*
|
||||
* @dataProvider dataProvider
|
||||
* @magentoConfigFixture system/media_gallery/enabled 1
|
||||
* @magentoDataFixture Magento/MediaGallery/_files/media_asset.php
|
||||
* @magentoDataFixture Magento/MediaContentCatalog/_files/product_with_asset.php
|
||||
* @param string $field
|
||||
* @param string $value
|
||||
* @param array $expectedAssetIds
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function testProductFields(string $field, string $value, array $expectedAssetIds): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expectedAssetIds,
|
||||
$this->getAssetIdsByContentField->execute($field, $value)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getting asset when media gallery disabled
|
||||
*
|
||||
* @magentoConfigFixture system/media_gallery/enabled 0
|
||||
* @magentoDataFixture Magento/MediaGallery/_files/media_asset.php
|
||||
* @magentoDataFixture Magento/MediaContentCatalog/_files/product_with_asset.php
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function testProductFieldsWithDisabledMediaGallery(): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
[],
|
||||
$this->getAssetIdsByContentField->execute(self::STATUS_FIELD, self::STATUS_ENABLED)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for tests
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function dataProvider(): array
|
||||
{
|
||||
return [
|
||||
[self::STATUS_FIELD, self::STATUS_ENABLED, [self::FIXTURE_ASSET_ID]],
|
||||
[self::STATUS_FIELD, self::STATUS_DISABLED, []],
|
||||
[self::STORE_FIELD, self::DEFAULT_STORE_ID, [self::FIXTURE_ASSET_ID]],
|
||||
];
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\MediaContentCatalog\Model\ResourceModel;
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\MediaContentApi\Model\GetEntityContentsInterface;
|
||||
use Magento\MediaContentApi\Api\Data\ContentIdentityInterfaceFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test for GetEntityContentsInterface
|
||||
*/
|
||||
class GetEntityContentTest extends TestCase
|
||||
{
|
||||
private const CONTENT_TYPE = 'catalog_product';
|
||||
private const TYPE = 'entityType';
|
||||
private const ENTITY_ID = 'entityId';
|
||||
private const FIELD = 'field';
|
||||
|
||||
/**
|
||||
* @var GetEntityContentsInterface
|
||||
*/
|
||||
private $getContent;
|
||||
|
||||
/**
|
||||
* @var ContentIdentityInterfaceFactory
|
||||
*/
|
||||
private $contentIdentityFactory;
|
||||
|
||||
/**
|
||||
* @var ProductRepositoryInterface
|
||||
*/
|
||||
private $productRepository;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->getContent = $objectManager->get(GetEntityContentsInterface::class);
|
||||
$this->contentIdentityFactory = $objectManager->get(ContentIdentityInterfaceFactory::class);
|
||||
$this->productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for get content from product in different store views
|
||||
*
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
|
||||
*/
|
||||
public function testProduct(): void
|
||||
{
|
||||
$product = $this->productRepository->get('simple');
|
||||
$contentIdentity = $this->contentIdentityFactory->create(
|
||||
[
|
||||
self::TYPE => self::CONTENT_TYPE,
|
||||
self::FIELD => 'description',
|
||||
self::ENTITY_ID => (string) $product->getEntityId(),
|
||||
]
|
||||
);
|
||||
$this->assertEquals(
|
||||
['Description with <b>html tag</b>'],
|
||||
$this->getContent->execute($contentIdentity)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for get content from product in different store views
|
||||
*
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_multiwebsite_different_description.php
|
||||
*/
|
||||
public function testProductTwoWebsites(): void
|
||||
{
|
||||
$product = $this->productRepository->get('simple-on-two-websites-different-description');
|
||||
$contentIdentity = $this->contentIdentityFactory->create(
|
||||
[
|
||||
self::TYPE => self::CONTENT_TYPE,
|
||||
self::FIELD => 'description',
|
||||
self::ENTITY_ID => (string) $product->getEntityId(),
|
||||
]
|
||||
);
|
||||
$this->assertEquals(
|
||||
[
|
||||
'<p>Product base description</p>',
|
||||
'<p>Product second description</p>'
|
||||
],
|
||||
$this->getContent->execute($contentIdentity)
|
||||
);
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Catalog\Model\Category;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/** @var Category $category */
|
||||
$category = Bootstrap::getObjectManager()->create(Category::class);
|
||||
$category->isObjectNew(true);
|
||||
$category->setId(
|
||||
28767
|
||||
)->setCreatedAt(
|
||||
'2014-06-23 09:50:07'
|
||||
)->setName(
|
||||
'Category 1'
|
||||
)->setDescription(
|
||||
'content {{media url="testDirectory/path.jpg"}} content'
|
||||
)->setParentId(
|
||||
2
|
||||
)->setPath(
|
||||
'1/2/333'
|
||||
)->setLevel(
|
||||
2
|
||||
)->setAvailableSortBy(
|
||||
['position', 'name']
|
||||
)->setDefaultSortBy(
|
||||
'name'
|
||||
)->setIsActive(
|
||||
true
|
||||
)->setPosition(
|
||||
1
|
||||
)->save();
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/** @var \Magento\Framework\Registry $registry */
|
||||
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
/** @var $category \Magento\Catalog\Model\Category */
|
||||
$category = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Category::class);
|
||||
$category->load(28767);
|
||||
if ($category->getId()) {
|
||||
$category->delete();
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
|
||||
/** @var ObjectManager $objectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var $product Product */
|
||||
$product = $objectManager->create(Product::class);
|
||||
$product->isObjectNew(true);
|
||||
$product->setTypeId(Type::TYPE_SIMPLE)
|
||||
->setId(1567)
|
||||
->setAttributeSetId(4)
|
||||
->setName('Simple Product')
|
||||
->setSku('simple_with_asset')
|
||||
->setPrice(10)
|
||||
->setWeight(1)
|
||||
->setShortDescription('content {{media url="testDirectory/path.jpg"}} content')
|
||||
->setTaxClassId(0)
|
||||
->setDescription('content {{media url="testDirectory/path.jpg"}} content')
|
||||
->setMetaTitle('meta title')
|
||||
->setMetaKeyword('meta keyword')
|
||||
->setMetaDescription('meta description')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(
|
||||
[
|
||||
'use_config_manage_stock' => 1,
|
||||
'qty' => 100,
|
||||
'is_qty_decimal' => 0,
|
||||
'is_in_stock' => 1,
|
||||
]
|
||||
);
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
$productRepository->save($product);
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
|
||||
\Magento\TestFramework\Helper\Bootstrap::getInstance()->getInstance()->reinitialize();
|
||||
|
||||
/** @var \Magento\Framework\Registry $registry */
|
||||
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
try {
|
||||
$product = $productRepository->get('simple_with_asset', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
}
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
Reference in New Issue
Block a user