init
This commit is contained in:
+69
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Reports\Model\ResourceModel\Product\Lowstock;
|
||||
|
||||
/**
|
||||
* Test for \Magento\Reports\Model\ResourceModel\Product\Lowstock\Collection
|
||||
*/
|
||||
class CollectionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \Magento\Reports\Model\ResourceModel\Product\Lowstock\Collection
|
||||
*/
|
||||
private $collection;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Reports\Model\ResourceModel\Product\Lowstock\Collection
|
||||
*/
|
||||
$this->collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Reports\Model\ResourceModel\Product\Lowstock\Collection::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that filterByProductType method throws LocalizedException if not String or Array is passed to it
|
||||
*
|
||||
*/
|
||||
public function testFilterByProductTypeException()
|
||||
{
|
||||
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
|
||||
|
||||
$this->collection->filterByProductType(100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that String argument passed to filterByProductType method is correctly passed to attribute adder
|
||||
*
|
||||
*/
|
||||
public function testFilterByProductTypeString()
|
||||
{
|
||||
$this->collection->filterByProductType('simple');
|
||||
$whereParts = $this->collection->getSelect()->getPart(\Magento\Framework\DB\Select::WHERE);
|
||||
$this->assertStringContainsString('simple', $whereParts[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that Array argument passed to filterByProductType method is correctly passed to attribute adder
|
||||
*
|
||||
*/
|
||||
public function testFilterByProductTypeArray()
|
||||
{
|
||||
$this->collection->filterByProductType(['simple', 'configurable']);
|
||||
$whereParts = $this->collection->getSelect()->getPart(\Magento\Framework\DB\Select::WHERE);
|
||||
|
||||
$this->assertThat(
|
||||
$whereParts[0],
|
||||
$this->logicalAnd(
|
||||
$this->stringContains('simple'),
|
||||
$this->stringContains('configurable')
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+215
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Reports\Model\ResourceModel\Report\Product\Viewed;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class CollectionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Reports\Model\ResourceModel\Report\Product\Viewed\Collection
|
||||
*/
|
||||
private $_collection;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Reports\Model\ResourceModel\Report\Product\Viewed\Collection::class
|
||||
);
|
||||
$this->_collection->setPeriod('day')
|
||||
->setDateRange(null, null)
|
||||
->addStoreFilter([1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Reports/_files/viewed_products.php
|
||||
* @magentoConfigFixture default/reports/options/enabled 1
|
||||
*/
|
||||
public function testGetItems()
|
||||
{
|
||||
$actualResult = [];
|
||||
/** @var \Magento\Reports\Model\Item $reportItem */
|
||||
foreach ($this->_collection->getItems() as $reportItem) {
|
||||
$actualResult[$reportItem->getData('product_id')] = $reportItem->getData('views_num');
|
||||
}
|
||||
$this->assertNotEmpty($actualResult);
|
||||
$this->assertCount(3, $actualResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider tableForPeriodDataProvider
|
||||
*
|
||||
* @param $period
|
||||
* @param $expectedTable
|
||||
* @param $dateFrom
|
||||
* @param $dateTo
|
||||
* @param $isTotal
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
public function testTableSelection($period, $expectedTable, $dateFrom, $dateTo, $isTotal = false)
|
||||
{
|
||||
$dbTableName = $this->_collection->getTable($expectedTable);
|
||||
$this->_collection->setPeriod($period);
|
||||
if ($isTotal != false) {
|
||||
$this->_collection->setAggregatedColumns(['id']);
|
||||
$this->_collection->isTotals(true);
|
||||
}
|
||||
$this->_collection->setDateRange($dateFrom, $dateTo);
|
||||
$this->_collection->load();
|
||||
$from = $this->_collection->getSelect()->getPart('from');
|
||||
|
||||
if ($isTotal != false) {
|
||||
$this->assertArrayHasKey('t', $from);
|
||||
$this->assertArrayHasKey('tableName', $from['t']);
|
||||
} elseif (!empty($from) && is_array($from)) {
|
||||
$this->assertArrayHasKey($dbTableName, $from);
|
||||
$actualTable = $from[$dbTableName]['tableName'];
|
||||
$this->assertEquals($dbTableName, $actualTable);
|
||||
$this->assertArrayHasKey('tableName', $from[$dbTableName]);
|
||||
} else {
|
||||
$union = $this->_collection->getSelect()->getPart('union');
|
||||
$count = count($union);
|
||||
if ($period !== null && $dateFrom !== null && $dateTo !== null && $period != 'month') {
|
||||
if ($period == 'year') {
|
||||
if ($dbTableName == "report_viewed_product_aggregated_daily") {
|
||||
$this->assertEquals(2, $count);
|
||||
}
|
||||
if ($dbTableName == "report_viewed_product_aggregated_yearly") {
|
||||
$this->assertEquals(3, $count);
|
||||
}
|
||||
} else {
|
||||
$this->assertEquals(3, $count);
|
||||
}
|
||||
} else {
|
||||
$this->assertEquals(2, $count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testTableSelection
|
||||
*
|
||||
* @return array
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function tableForPeriodDataProvider()
|
||||
{
|
||||
$dateFrom = '2019-10-15';
|
||||
$dateYearBefore = date('Y-m-d', strtotime($dateFrom . ' -1 year'));
|
||||
return [
|
||||
[
|
||||
'period' => 'year',
|
||||
'table' => 'report_viewed_product_aggregated_yearly',
|
||||
'date_from' => null,
|
||||
'date_to' => null,
|
||||
'is_total' => true,
|
||||
],
|
||||
[
|
||||
'period' => 'year',
|
||||
'table' => 'report_viewed_product_aggregated_yearly',
|
||||
'date_from' => $dateYearBefore,
|
||||
'date_to' => $dateFrom,
|
||||
],
|
||||
[
|
||||
'period' => 'year',
|
||||
'table' => 'report_viewed_product_aggregated_yearly',
|
||||
'date_from' => $dateYearBefore,
|
||||
'date_to' => null,
|
||||
],
|
||||
[
|
||||
'period' => 'month',
|
||||
'table' => 'report_viewed_product_aggregated_monthly',
|
||||
'date_from' => null,
|
||||
'date_to' => $dateFrom,
|
||||
],
|
||||
[
|
||||
'period' => 'year',
|
||||
'table' => 'report_viewed_product_aggregated_yearly',
|
||||
'date_from' => $dateYearBefore,
|
||||
'date_to' => null,
|
||||
],
|
||||
[
|
||||
'period' => 'year',
|
||||
'table' => 'report_viewed_product_aggregated_yearly',
|
||||
'date_from' => null,
|
||||
'date_to' => $dateFrom,
|
||||
],
|
||||
[
|
||||
'period' => 'month',
|
||||
'table' => 'report_viewed_product_aggregated_monthly',
|
||||
'date_from' => null,
|
||||
'date_to' => null,
|
||||
],
|
||||
[
|
||||
'period' => 'month',
|
||||
'table' => 'report_viewed_product_aggregated_monthly',
|
||||
'date_from' => $dateYearBefore,
|
||||
'date_to' => $dateYearBefore,
|
||||
],
|
||||
[
|
||||
'period' => 'month',
|
||||
'table' => 'report_viewed_product_aggregated_monthly',
|
||||
'date_from' => null,
|
||||
'date_to' => $dateYearBefore,
|
||||
],
|
||||
[
|
||||
'period' => 'month',
|
||||
'table' => 'report_viewed_product_aggregated_monthly',
|
||||
'date_from' => $dateYearBefore,
|
||||
'date_to' => null,
|
||||
],
|
||||
[
|
||||
'period' => 'day',
|
||||
'table' => 'report_viewed_product_aggregated_daily',
|
||||
'date_from' => null,
|
||||
'date_to' => null,
|
||||
],
|
||||
[
|
||||
'period' => 'undefinedPeriod',
|
||||
'table' => 'report_viewed_product_aggregated_daily',
|
||||
'date_from' => null,
|
||||
'date_to' => null,
|
||||
],
|
||||
[
|
||||
'period' => null,
|
||||
'table' => 'report_viewed_product_aggregated_daily',
|
||||
'date_from' => $dateYearBefore,
|
||||
'date_to' => $dateFrom,
|
||||
],
|
||||
[
|
||||
'period' => null,
|
||||
'table' => 'report_viewed_product_aggregated_daily',
|
||||
'date_from' => $dateFrom,
|
||||
'date_to' => $dateFrom,
|
||||
],
|
||||
[
|
||||
'period' => 'day',
|
||||
'table' => 'report_viewed_product_aggregated_daily',
|
||||
'date_from' => $dateYearBefore,
|
||||
'date_to' => $dateYearBefore,
|
||||
],
|
||||
[
|
||||
'period' => 'year',
|
||||
'table' => 'report_viewed_product_aggregated_daily',
|
||||
'date_from' => $dateYearBefore,
|
||||
'date_to' => $dateYearBefore,
|
||||
],
|
||||
[
|
||||
'period' => 'year',
|
||||
'table' => 'report_viewed_product_aggregated_daily',
|
||||
'date_from' => null,
|
||||
'date_to' => $dateYearBefore,
|
||||
],
|
||||
[
|
||||
'period' => null,
|
||||
'table' => 'report_viewed_product_aggregated_yearly',
|
||||
'date_from' => null,
|
||||
'date_to' => null,
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Reports\Model\ResourceModel\Report\Sold;
|
||||
|
||||
/**
|
||||
* Class CollectionTest
|
||||
*/
|
||||
class CollectionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Reports\Model\ResourceModel\Product\Sold\Collection
|
||||
*/
|
||||
private $collection;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Reports\Model\ResourceModel\Product\Sold\Collection
|
||||
*/
|
||||
$this->collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Reports\Model\ResourceModel\Product\Sold\Collection::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/order_item_with_configurable_for_reorder.php
|
||||
*/
|
||||
public function testFilterByProductTypeException()
|
||||
{
|
||||
$items = $this->collection->addOrderedQty()->getItems();
|
||||
$this->assertCount(1, $items);
|
||||
$orderItem = array_shift($items);
|
||||
$this->assertEquals('1.0000', $orderItem['ordered_qty']);
|
||||
$this->assertEquals('Configurable Product', $orderItem['order_items_name']);
|
||||
//verify if order_item_sku exists in return data
|
||||
$this->assertEquals('simple_20', $orderItem['order_items_sku']);
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Reports\Model\ResourceModel\Review\Customer;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class CollectionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Reports\Model\ResourceModel\Review\Customer\Collection
|
||||
*/
|
||||
private $collection;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Reports\Model\ResourceModel\Review\Customer\Collection::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This tests covers issue described in:
|
||||
* https://github.com/magento/magento2/issues/10301
|
||||
*
|
||||
* @magentoDataFixture Magento/Review/_files/customer_review.php
|
||||
*/
|
||||
public function testSelectCountSql()
|
||||
{
|
||||
$this->collection->addFieldToFilter('customer_name', ['like' => '%John%'])->getItems();
|
||||
$this->assertEquals(1, $this->collection->getSize());
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Reports\Model\ResourceModel\Review\Product;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class CollectionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Reports\Model\ResourceModel\Review\Product\Collection
|
||||
*/
|
||||
private $_collection;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Reports\Model\ResourceModel\Review\Product\Collection::class
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetSelect()
|
||||
{
|
||||
$select = (string)$this->_collection->getSelect();
|
||||
$search = '/SUM\(table_rating.percent\)\/COUNT\(table_rating.rating_id\) AS `avg_rating`'
|
||||
. '[\s\S]+SUM\(table_rating.percent_approved\)\/COUNT\(table_rating.rating_id\) AS `avg_rating_approved`'
|
||||
. '[\s\S]+LEFT JOIN `.*rating_option_vote_aggregated` AS `table_rating`/';
|
||||
|
||||
$this->assertMatchesRegularExpression($search, $select);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user