Skip to content

Commit 40ebd2d

Browse files
committed
MC-37074: Create automated test for "Dynamic charts on Magento dashboard
1 parent aa272e6 commit 40ebd2d

File tree

1 file changed

+66
-0
lines changed
  • dev/tests/integration/testsuite/Magento/Backend/Block/Dashboard/Chart

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Backend\Block\Dashboard\Chart;
9+
10+
use Magento\Backend\ViewModel\ChartsPeriod;
11+
use Magento\Framework\ObjectManagerInterface;
12+
use Magento\Framework\View\Element\Template;
13+
use Magento\Framework\View\LayoutInterface;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use Magento\TestFramework\Helper\Xpath;
16+
use PHPUnit\Framework\TestCase;
17+
18+
/**
19+
* Checks chart periods on Magento dashboard
20+
*
21+
* @magentoAppArea adminhtml
22+
*/
23+
class PeriodTest extends TestCase
24+
{
25+
/** @var ObjectManagerInterface */
26+
private $objectManager;
27+
28+
/** @var Template */
29+
private $block;
30+
31+
/** @var LayoutInterface */
32+
private $layout;
33+
34+
/**
35+
* @inheritdoc
36+
*/
37+
public function setUp(): void
38+
{
39+
parent::setUp();
40+
41+
$this->objectManager = Bootstrap::getObjectManager();
42+
$this->layout = $this->objectManager->get(LayoutInterface::class);
43+
$this->block = $this->layout->createBlock(Template::class);
44+
$this->block->setTemplate("Magento_Backend::dashboard/chart/period.phtml");
45+
$this->block->setData('view_model', $this->objectManager->get(ChartsPeriod::class));
46+
}
47+
48+
/**
49+
* @return void
50+
*/
51+
public function testChartPeriodOptions(): void
52+
{
53+
$html = $this->block->toHtml();
54+
$dropDownList = [
55+
__('Last 24 Hours'),
56+
__('Last 7 Days'),
57+
__('Current Month'),
58+
__('YTD'),
59+
__('2YTD')
60+
];
61+
foreach ($dropDownList as $item) {
62+
$xPath = "//select[@id='dashboard_chart_period']/option[normalize-space(text())='{$item}']";
63+
$this->assertEquals(1, Xpath::getElementsCountForXpath($xPath, $html));
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)