File size: 4,334 Bytes
bf8c0ce | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | <?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Tests\Integration\CoreHome;
use Piwik\DataTable\Map;
use Piwik\Plugins\CoreHome\DataTableRowAction\RowEvolution;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
use Piwik\View;
/**
* @group CoreHome
* @group RowEvolution
*/
class RowEvolutionTest extends IntegrationTestCase
{
public function setUp(): void
{
parent::setUp();
Fixture::createWebsite('2014-01-01 00:00:00');
$_GET['idSite'] = 1;
$_GET['date'] = '2014-01-01';
$_GET['period'] = 'day';
}
public function tearDown(): void
{
unset($_GET['idSite'], $_GET['date'], $_GET['period']);
parent::tearDown();
}
public function testGetRowEvolutionGraphKeepsGraphLabelResetSeparateFromExportLabel(): void
{
$rowEvolution = (new \ReflectionClass(RowEvolution::class))->newInstanceWithoutConstructor();
$this->setProperty($rowEvolution, 'apiMethod', 'Referrers.getWebsites');
$this->setProperty($rowEvolution, 'label', '@referrer.com');
$this->setProperty($rowEvolution, 'graphType', 'graphEvolution');
$this->setProperty($rowEvolution, 'dataTable', new Map());
$this->setProperty($rowEvolution, 'availableMetrics', []);
$view = $rowEvolution->getRowEvolutionGraph();
$this->assertSame('', $view->requestConfig->request_parameters_to_modify['label']);
$this->assertSame('@referrer.com', $view->config->export_parameters_to_modify['label']);
$this->assertFalse($view->config->show_flatten_table_export);
}
/**
* A plugin whose report configureView adds an identifier to
* request_parameters_to_modify (as plugin-CustomReports does with
* idCustomReport) must still see that identifier reach the export URL
* even when RowEvolution has populated export_parameters_to_modify['label'].
* The _dataTableActions.twig template must merge the two maps, not pick one.
*/
public function testDataTableActionsTemplateMergesRequestAndExportParameters(): void
{
$view = new View('@CoreHome/_dataTableActions');
$view->properties = [
// Simulates a plugin's configureView contribution.
'request_parameters_to_modify' => ['idDummyReport' => 42, 'label' => ''],
// Simulates RowEvolution::getRowEvolutionGraph overriding the label for exports.
'export_parameters_to_modify' => ['label' => '@rowLabel'],
'show_footer' => true,
'show_footer_icons' => true,
'title' => '',
'apiMethodToRequestDataTable' => 'Referrers.getWebsites',
'max_export_filter_limit' => 100,
'show_export' => true,
'show_export_as_image_icon' => false,
'hide_annotations_view' => true,
'show_search' => false,
'report_id' => 'test',
'show_flatten_table' => false,
'report_supports_flatten' => false,
'show_flatten_table_export' => false,
'show_periods' => false,
'translations' => [],
];
$view->footerIcons = [];
$view->clientSideParameters = ['viewDataTable' => 'table'];
$view->hasMultipleDimensions = false;
$view->isDataTableEmpty = false;
$view->isComparing = false;
$html = $view->render();
$this->assertSame(1, preg_match('/request-params="([^"]*)"/', $html, $matches));
$requestParams = json_decode(htmlspecialchars_decode($matches[1]), true);
$this->assertIsArray($requestParams);
$this->assertSame(42, $requestParams['idDummyReport']);
$this->assertSame('@rowLabel', $requestParams['label']);
}
private function setProperty(object $instance, string $propertyName, $value): void
{
$property = new \ReflectionProperty($instance, $propertyName);
$property->setAccessible(true);
$property->setValue($instance, $value);
}
}
|