init
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Backend\Block\Dashboard\Chart;
|
||||
|
||||
use Magento\Backend\ViewModel\ChartsPeriod;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\View\Element\Template;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Helper\Xpath;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Checks chart periods on Magento dashboard
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class PeriodTest extends TestCase
|
||||
{
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var Template */
|
||||
private $block;
|
||||
|
||||
/** @var LayoutInterface */
|
||||
private $layout;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->layout = $this->objectManager->get(LayoutInterface::class);
|
||||
$this->block = $this->layout->createBlock(Template::class);
|
||||
$this->block->setTemplate("Magento_Backend::dashboard/chart/period.phtml");
|
||||
$this->block->setData('view_model', $this->objectManager->get(ChartsPeriod::class));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testChartPeriodOptions(): void
|
||||
{
|
||||
$html = $this->block->toHtml();
|
||||
$dropDownList = [
|
||||
__('Today'),
|
||||
__('Last 24 Hours'),
|
||||
__('Last 7 Days'),
|
||||
__('Current Month'),
|
||||
__('YTD'),
|
||||
__('2YTD')
|
||||
];
|
||||
foreach ($dropDownList as $item) {
|
||||
$xPath = "//select[@id='dashboard_chart_period']/option[normalize-space(text())='{$item}']";
|
||||
$this->assertEquals(1, Xpath::getElementsCountForXpath($xPath, $html));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Backend\Block\Dashboard\Orders;
|
||||
|
||||
use Magento\Backend\Block\Template\Context;
|
||||
|
||||
class GridTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var Grid
|
||||
*/
|
||||
private $block;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$block = $this->createMock(\Magento\Backend\Block\Dashboard\Orders\Grid::class);
|
||||
$layout = $this->createMock(\Magento\Framework\View\LayoutInterface::class);
|
||||
$layout->expects($this->atLeastOnce())->method('getChildName')->willReturn('test');
|
||||
$layout->expects($this->atLeastOnce())->method('getBlock')->willReturn($block);
|
||||
$context = $objectManager->create(Context::class, ['layout' => $layout]);
|
||||
|
||||
$this->block = $objectManager->create(Grid::class, ['context' => $context]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/order.php
|
||||
*/
|
||||
public function testGetPreparedCollection()
|
||||
{
|
||||
$collection = $this->block->getPreparedCollection();
|
||||
foreach ($collection->getItems() as $item) {
|
||||
if ($item->getIncrementId() == '100000001') {
|
||||
$this->assertEquals('firstname lastname', $item->getCustomer());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Backend\Block\Dashboard\Tab\Products;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap as BootstrapHelper;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\Backend\Block\Dashboard\Tab\Products\Viewed as ViewedProductsTabBlock;
|
||||
use Magento\Catalog\Model\ProductRepository;
|
||||
use Magento\Framework\Event\ManagerInterface as EventManager;
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class ViewedTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var LayoutInterface
|
||||
*/
|
||||
private $layout;
|
||||
|
||||
/**
|
||||
* @var ProductRepository
|
||||
*/
|
||||
private $productRepository;
|
||||
|
||||
/**
|
||||
* @var EventManager
|
||||
*/
|
||||
private $eventManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = BootstrapHelper::getObjectManager();
|
||||
$this->layout = $this->objectManager->get(LayoutInterface::class);
|
||||
$this->productRepository = $this->objectManager->get(ProductRepository::class);
|
||||
$this->eventManager = $this->objectManager->get(EventManager::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoConfigFixture default/reports/options/enabled 1
|
||||
*/
|
||||
public function testGetPreparedCollectionProductPrice()
|
||||
{
|
||||
/** @var ViewedProductsTabBlock $viewedProductsTabBlock */
|
||||
$viewedProductsTabBlock = $this->layout->createBlock(ViewedProductsTabBlock::class);
|
||||
$product = $this->productRepository->getById(1);
|
||||
$this->eventManager->dispatch('catalog_controller_product_view', ['product' => $product]);
|
||||
|
||||
$collection = $viewedProductsTabBlock->getPreparedCollection();
|
||||
|
||||
$this->assertEquals(
|
||||
10,
|
||||
$collection->getFirstItem()->getDataByKey('price')
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user