Skip to content

Commit

Permalink
update the report integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
diosmosis committed Sep 23, 2024
1 parent 131991a commit fa6f5b8
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 7 deletions.
2 changes: 1 addition & 1 deletion plugins/Goals/Columns/Metrics/RevenuePerVisit.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class RevenuePerVisit extends ProcessedMetric
*/
private $allIdGoals;

public function __construct(?array $allIdGoals)
public function __construct(?array $allIdGoals = null)
{
$this->allIdGoals = $allIdGoals;
}
Expand Down
92 changes: 86 additions & 6 deletions tests/PHPUnit/Integration/ReportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@
namespace Piwik\Tests\Integration;

use Piwik\API\Proxy;
use Piwik\Columns\Dimension;
use Piwik\Container\StaticContainer;
use Piwik\DataTable\Row;
use Piwik\Plugin\Metric;
use Piwik\Plugin\ProcessedMetric;
use Piwik\Plugin\Report;
use Piwik\Plugins\DevicesDetection\Columns\BrowserName;
use Piwik\Plugins\ExampleReport\Reports\GetExampleReport;
use Piwik\Plugins\Actions\Columns\ExitPageUrl;
use Piwik\Piwik;
use Piwik\Metrics;
use Piwik\Plugins\ExampleTracker\Columns\ExampleDimension;
use Piwik\Plugins\Goals\Columns\Metrics\RevenuePerVisit;
use Piwik\Plugins\Referrers\Columns\Keyword;
use Piwik\Plugin\ReportsProvider;
use Piwik\Report\ReportWidgetFactory;
Expand All @@ -31,6 +37,7 @@ protected function init()
{
parent::init();

$this->dimension = new BrowserName();
$this->name = 'My Custom Report Name';
$this->order = 20;
$this->module = 'TestPlugin';
Expand All @@ -40,6 +47,48 @@ protected function init()
}
}

class AdvancedProcessedMetric extends ProcessedMetric
{
public function getName()
{
return 'advancedmetric';
}

public function getTranslatedName()
{
return 'MyPlugin_AdvancedMetric';
}

public function compute(Row $row)
{
// unimplemented (not required for test)
}

public function getDependentMetrics()
{
return [];
}

public function getExtraMetricSemanticTypes(): array
{
return [
'intermediate_value' => Dimension::TYPE_NUMBER,
];
}

public function getExtraMetricAggregationTypes(): array
{
return [
'intermediate_value' => Metric::AGGREGATION_TYPE_SUM,
];
}

public function getSemanticType(): ?string
{
return Dimension::TYPE_PERCENT;
}
}

class GetAdvancedReport extends GetBasicReport
{
protected function init()
Expand All @@ -51,7 +100,12 @@ protected function init()
$this->documentation = Piwik::translate('ExampleReportDocumentation');
$this->dimension = new ExitPageUrl();
$this->metrics = array('nb_actions', 'nb_visits');
$this->processedMetrics = array('conversion_rate', 'bounce_rate');
$this->processedMetrics = [
'conversion_rate',
'bounce_rate',
new RevenuePerVisit(),
new AdvancedProcessedMetric(),
];
$this->parameters = array('idGoal' => 1);
$this->isSubtableReport = true;
$this->actionToLoadSubTables = 'GetBasicReport';
Expand Down Expand Up @@ -108,7 +162,6 @@ public function setUp(): void
parent::setUp();

Fixture::createWebsite('2014-01-01 00:00:00');
$this->unloadAllPlugins();
$_GET['idSite'] = 1;

$this->exampleReport = new GetExampleReport();
Expand Down Expand Up @@ -199,7 +252,9 @@ public function testGetProcessedMetricsShouldFindTranslationsForMetricsAndReturn
{
$expected = array(
'conversion_rate' => 'General_ColumnConversionRate',
'bounce_rate' => 'General_ColumnBounceRate'
'bounce_rate' => 'General_ColumnBounceRate',
'revenue_per_visit' => 'General_ColumnValuePerVisit',
'advancedmetric' => 'MyPlugin_AdvancedMetric',
);
$this->assertEquals($expected, $this->advancedReport->getProcessedMetrics());
}
Expand Down Expand Up @@ -274,7 +329,15 @@ public function testConfigureReportMetadataShouldBuiltStructureAndIncludeOnlyFie
'bounce_rate' => 'percent',
'conversion_rate' => 'percent',
],
)
'processedMetricFormulas' => [],
'temporaryMetricAggregationTypes' => [],
'temporaryMetricSemanticTypes' => [],
'metricAggregationTypes' => [
'nb_visits' => 'sum',
'nb_actions' => 'sum',
],
'dimension' => 'DevicesDetection_ColumnBrowser',
),
), $reports);
}

Expand Down Expand Up @@ -307,18 +370,35 @@ public function testConfigureReportMetadataShouldBuiltStructureAllFieldsSet()
'processedMetrics' => array(
'conversion_rate' => 'General_ColumnConversionRate',
'bounce_rate' => 'General_ColumnBounceRate',
'revenue_per_visit' => 'General_ColumnValuePerVisit',
'advancedmetric' => 'MyPlugin_AdvancedMetric',
),
'actionToLoadSubTables' => 'GetBasicReport',
'constantRowsCount' => true,
'order' => '20',
'order' => 20,
'subcategory' => 'Actions_SubmenuPageTitles',
'metricTypes' => [
'nb_actions' => 'number',
'nb_visits' => 'number',
'conversion_rate' => 'percent',
'bounce_rate' => 'percent',
'revenue_per_visit' => 'money',
'advancedmetric' => 'percent',
],
)
'processedMetricFormulas' => [
'revenue_per_visit' => '$revenue / ($nb_visits != 0 ? $nb_visits : $nb_conversions)',
],
'temporaryMetricAggregationTypes' => [
'intermediate_value' => 'sum',
],
'temporaryMetricSemanticTypes' => [
'intermediate_value' => 'number',
],
'metricAggregationTypes' => [
'nb_visits' => 'sum',
'nb_actions' => 'sum',
],
),
), $reports);
}

Expand Down

0 comments on commit fa6f5b8

Please sign in to comment.