ltsecurityinc安防产品在线商城代码
This commit is contained in:
+57
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Review\Model\ResourceModel\Rating;
|
||||
|
||||
class CollectionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Review\Model\ResourceModel\Rating\Collection
|
||||
*/
|
||||
protected $collection;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Review\Model\ResourceModel\Rating\Collection::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Review/_files/customer_review_with_rating.php
|
||||
*/
|
||||
public function testAddEntitySummaryToItem()
|
||||
{
|
||||
$ratingData = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Framework\Registry::class)
|
||||
->registry('rating_data');
|
||||
|
||||
$result = $this->collection->addEntitySummaryToItem($ratingData->getEntityId(), $ratingData->getStoreId());
|
||||
$this->assertEquals($this->collection, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testAddEntitySummaryToItemEmpty()
|
||||
{
|
||||
foreach ($this->collection->getItems() as $item) {
|
||||
$item->delete();
|
||||
}
|
||||
$this->collection->clear();
|
||||
$result = $this->collection->addEntitySummaryToItem(1, 1);
|
||||
$this->assertEquals($this->collection, $result);
|
||||
}
|
||||
|
||||
public function testAddStoreData()
|
||||
{
|
||||
$this->collection->addStoreData();
|
||||
}
|
||||
|
||||
public function testSetStoreFilter()
|
||||
{
|
||||
$this->collection->setStoreFilter(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Review\Model\ResourceModel;
|
||||
|
||||
/**
|
||||
* Class RatingTest
|
||||
*/
|
||||
class RatingTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$storeId = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Store\Model\StoreManagerInterface::class)
|
||||
->getStore()->getId();
|
||||
|
||||
$rating = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Review\Model\Rating::class
|
||||
);
|
||||
$rating->setData([
|
||||
'rating_code' => 'Test Rating',
|
||||
'position' => 0,
|
||||
'is_active' => true,
|
||||
'entity_id' => 1
|
||||
]);
|
||||
$rating->setRatingCodes([$storeId => 'Test Rating']);
|
||||
$rating->setStores([$storeId]);
|
||||
$rating->save();
|
||||
$this->id = $rating->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testRatingLoad()
|
||||
{
|
||||
$rating = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Review\Model\Rating::class
|
||||
);
|
||||
$rating->load($this->id);
|
||||
$this->assertEquals('Test Rating', $rating->getRatingCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testRatingEdit()
|
||||
{
|
||||
$rating = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Review\Model\Rating::class
|
||||
);
|
||||
$rating->load($this->id);
|
||||
$this->assertEquals('Test Rating', $rating->getRatingCode());
|
||||
$storeId = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Store\Model\StoreManagerInterface::class)
|
||||
->getStore()->getId();
|
||||
$rating->setRatingCode('Test Rating Edited');
|
||||
$rating->setRatingCodes([$storeId => 'Test Rating Edited']);
|
||||
$rating->save();
|
||||
|
||||
$this->assertEquals('Test Rating Edited', $rating->getRatingCode());
|
||||
$this->assertEquals([$storeId => 'Test Rating Edited'], $rating->getRatingCodes());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testRatingSaveWithError()
|
||||
{
|
||||
$this->expectException('Exception');
|
||||
$this->expectExceptionMessage('Rolled back transaction has not been completed correctly');
|
||||
$rating = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Review\Model\Rating::class
|
||||
);
|
||||
$rating->load($this->id);
|
||||
$rating->setRatingCodes([222 => 'Test Rating Edited']);
|
||||
$rating->save();
|
||||
}
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Review\Model\ResourceModel\Review\Product;
|
||||
|
||||
/**
|
||||
* Tests some functionality of the Product Review collection
|
||||
*/
|
||||
class CollectionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @param string $status
|
||||
* @param int $expectedCount
|
||||
* @param string $sortAttribute
|
||||
* @param string $dir
|
||||
* @param callable $assertion
|
||||
* @dataProvider sortOrderAssertionsDataProvider
|
||||
* @magentoDataFixture Magento/Review/_files/different_reviews.php
|
||||
*/
|
||||
public function testGetResultingIds(
|
||||
?int $status,
|
||||
int $expectedCount,
|
||||
string $sortAttribute,
|
||||
string $dir,
|
||||
callable $assertion
|
||||
) {
|
||||
/**
|
||||
* @var $collection \Magento\Review\Model\ResourceModel\Review\Product\Collection
|
||||
*/
|
||||
$collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Review\Model\ResourceModel\Review\Product\Collection::class
|
||||
);
|
||||
if ($status) {
|
||||
$collection->addStatusFilter($status);
|
||||
}
|
||||
$collection->setOrder($sortAttribute, $dir);
|
||||
$actual = $collection->getResultingIds();
|
||||
$this->assertCount($expectedCount, $actual);
|
||||
$assertion($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function sortOrderAssertionsDataProvider() :array
|
||||
{
|
||||
return [
|
||||
[
|
||||
\Magento\Review\Model\Review::STATUS_APPROVED,
|
||||
2,
|
||||
'rt.review_id',
|
||||
'DESC',
|
||||
function (array $actual) :void {
|
||||
$this->assertLessThan($actual[0], $actual[1]);
|
||||
}
|
||||
],
|
||||
[
|
||||
\Magento\Review\Model\Review::STATUS_APPROVED,
|
||||
2,
|
||||
'rt.review_id',
|
||||
'ASC',
|
||||
function (array $actual) :void {
|
||||
$this->assertLessThan($actual[1], $actual[0]);
|
||||
}
|
||||
],
|
||||
[
|
||||
\Magento\Review\Model\Review::STATUS_APPROVED,
|
||||
2,
|
||||
'rt.created_at',
|
||||
'ASC',
|
||||
function (array $actual) :void {
|
||||
$this->assertLessThan($actual[1], $actual[0]);
|
||||
}
|
||||
],
|
||||
[
|
||||
null,
|
||||
3,
|
||||
'rt.review_id',
|
||||
'ASC',
|
||||
function (array $actual) :void {
|
||||
$this->assertLessThan($actual[1], $actual[0]);
|
||||
}
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Review\Model\ResourceModel\Review;
|
||||
|
||||
use Magento\Framework\App\ResourceConnection;
|
||||
|
||||
/**
|
||||
* Class ReviewTest
|
||||
*/
|
||||
class ReviewTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
/**
|
||||
* @var \Magento\Review\Model\ResourceModel\Review
|
||||
*/
|
||||
protected $reviewResource;
|
||||
|
||||
/**
|
||||
* @var \Magento\Review\Model\ResourceModel\Review\Collection
|
||||
*/
|
||||
protected $reviewCollection;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\App\ResourceConnection
|
||||
*/
|
||||
protected $resource;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\DB\Adapter\AdapterInterface
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->resource = $this->objectManager->get(\Magento\Framework\App\ResourceConnection::class);
|
||||
$this->connection = $this->resource->getConnection();
|
||||
$this->reviewCollection = $this->objectManager->create(
|
||||
\Magento\Review\Model\ResourceModel\Review\Collection::class
|
||||
);
|
||||
$this->reviewResource = $this->objectManager->create(\Magento\Review\Model\ResourceModel\Review::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Review/_files/customer_review_with_rating.php
|
||||
*/
|
||||
public function testAggregate()
|
||||
{
|
||||
$rating = $this->reviewCollection->getFirstItem();
|
||||
$this->reviewResource->aggregate($rating);
|
||||
|
||||
$select = $this->connection->select()->from($this->resource->getTableName('review_entity_summary'));
|
||||
$result = $this->connection->fetchRow($select);
|
||||
|
||||
$this->assertEquals(1, $result['reviews_count']);
|
||||
$this->assertEquals(40, $result['rating_summary']);
|
||||
}
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Review\Model\ResourceModel\Review\Summary;
|
||||
|
||||
use Magento\Framework\Data\Collection\Db\FetchStrategy\Query;
|
||||
use Magento\Framework\Data\Collection\EntityFactory;
|
||||
use Magento\Framework\DB\Adapter\AdapterInterface;
|
||||
use Magento\Framework\DB\Adapter\Pdo\Mysql;
|
||||
use Magento\Framework\DB\Select;
|
||||
use Magento\Framework\DB\Select\SelectRenderer;
|
||||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
|
||||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
|
||||
use Magento\Review\Model\ResourceModel\Review\Summary\Collection;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Tests some functionality of the Review Summary collection
|
||||
*/
|
||||
class CollectionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var Collection
|
||||
*/
|
||||
protected Collection $collection;
|
||||
|
||||
/**
|
||||
* @var Query
|
||||
*/
|
||||
protected Query $fetchStrategyMock;
|
||||
|
||||
/**
|
||||
* @var EntityFactory
|
||||
*/
|
||||
protected EntityFactory $entityFactoryMock;
|
||||
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
protected LoggerInterface $loggerMock;
|
||||
|
||||
/**
|
||||
* @var AbstractDb
|
||||
*/
|
||||
protected AbstractDb $resourceMock;
|
||||
|
||||
/**
|
||||
* @var AdapterInterface
|
||||
*/
|
||||
protected AdapterInterface $connectionMock;
|
||||
|
||||
/**
|
||||
* @var Select
|
||||
*/
|
||||
protected Select $selectMock;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->fetchStrategyMock = $this->createPartialMock(
|
||||
Query::class,
|
||||
['fetchAll']
|
||||
);
|
||||
$this->entityFactoryMock = $this->createPartialMock(
|
||||
EntityFactory::class,
|
||||
['create']
|
||||
);
|
||||
$this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
|
||||
$this->resourceMock = $this->getMockBuilder(AbstractDb::class)
|
||||
->setMethods(['getConnection', 'getMainTable', 'getTable'])
|
||||
->disableOriginalConstructor()
|
||||
->getMockForAbstractClass();
|
||||
$this->connectionMock = $this->createPartialMock(
|
||||
Mysql::class,
|
||||
['select', 'query']
|
||||
);
|
||||
$selectRenderer = $this->getMockBuilder(SelectRenderer::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->selectMock = $this->getMockBuilder(Select::class)
|
||||
->setMethods(['where'])
|
||||
->setConstructorArgs(['adapter' => $this->connectionMock, 'selectRenderer' => $selectRenderer])
|
||||
->getMock();
|
||||
$this->connectionMock->expects($this->once())
|
||||
->method('select')
|
||||
->willReturn($this->selectMock);
|
||||
$this->resourceMock->expects($this->once())
|
||||
->method('getConnection')
|
||||
->willReturn($this->connectionMock);
|
||||
$this->resourceMock->expects($this->once())
|
||||
->method('getMainTable')
|
||||
->willReturn('main_table_name');
|
||||
|
||||
$this->resourceMock->expects($this->once())
|
||||
->method('getTable')
|
||||
->willReturnArgument(0);
|
||||
$objectManager = new ObjectManager($this);
|
||||
$this->collection = $objectManager->getObject(
|
||||
Collection::class,
|
||||
[
|
||||
'entityFactory' => $this->entityFactoryMock,
|
||||
'logger' => $this->loggerMock,
|
||||
'fetchStrategy' => $this->fetchStrategyMock,
|
||||
'resource' => $this->resourceMock
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|int $storeId
|
||||
* @param string $expectedQuery
|
||||
* @dataProvider storeIdDataProvider
|
||||
*/
|
||||
public function testAddStoreFilter(array|int $storeId, string $expectedQuery)
|
||||
{
|
||||
$this->selectMock->expects($this->once())->method('where')->with($expectedQuery, $storeId);
|
||||
$this->collection->addStoreFilter($storeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function storeIdDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[1, 'store_id = ?'],
|
||||
[[1,2], 'store_id IN (?)']
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user