Skip to content

Commit

Permalink
Fix warning Trying to add two strings in DataTable\Row::sumRowArray (#…
Browse files Browse the repository at this point in the history
…21420)

* Fix warning Trying to add two strings in DataTable\Row::sumRowArray

* Update expected test file

---------

Co-authored-by: Marc Neudert <[email protected]>
  • Loading branch information
tsteur and mneudert authored Oct 19, 2023
1 parent a89e26d commit 2ce56ce
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugins/CoreHome/Columns/Metrics/EvolutionMetric.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function compute(Row $row)
$ratio = self::getRatio($this->currentData, $this->pastData, $row);
$period = $this->pastData->getMetadata(DataTableFactory::TABLE_METADATA_PERIOD_INDEX);
$row->setMetadata('ratio', $ratio);
$row->setMetadata('currencySymbol', $row['label'] !== DataTable::ID_SUMMARY_ROW ? Site::getCurrencySymbolFor($row['label']) : API::getInstance()->getDefaultCurrency());
$row->setMetadata('currencySymbol', $row['label'] !== DataTable::ID_SUMMARY_ROW && $row['label'] !== DataTable::LABEL_TOTALS_ROW ? Site::getCurrencySymbolFor($row['label']) : API::getInstance()->getDefaultCurrency());
$row->setMetadata('previous_'.$columnName, $pastValue);
$row->setMetadata('periodName', $period->getLabel());
$row->setMetadata('previousRange', $period->getLocalizedShortString());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

namespace Piwik\Plugins\CoreHome\tests\Integration\Columns\Metrics;

use Piwik\DataTable;
use Piwik\DataTable\Row;
use Piwik\Date;
use Piwik\Plugins\CoreHome\Columns\Metrics\EvolutionMetric;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;

/**
* @group CoreHome
* @group EvolutionMetricTest
* @group Plugins
* @group Columns
*/
class EvolutionMetricTest extends IntegrationTestCase
{

public function setUp(): void
{
parent::setUp();
Fixture::createWebsite('2022-01-01 00:00:00');
}

public function test_shouldNotBreakIfSummaryRowGiven()
{
$this->assertNoFailureOnComputeForLabel(DataTable::ID_SUMMARY_ROW);
}

public function test_shouldNotBreakIfTotalsRowGiven()
{
$this->assertNoFailureOnComputeForLabel(DataTable::LABEL_TOTALS_ROW);
}

private function assertNoFailureOnComputeForLabel($label): void
{
$pastData = new DataTable();
$cPeriod = new \Piwik\Period\Week(Date::factory('2021-10-10'));
$pastData->setMetadata('period', $cPeriod);

$evolution = new EvolutionMetric('nb_visits', $pastData);

$row = new Row([Row::COLUMNS => ['nb_visits' => 5, 'label' => $label]]);
$evolution->compute($row);

$currency = $row->getMetadata('currencySymbol');
$this->assertNotEmpty($currency);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -342,5 +342,16 @@
</result>
</reportMetadata>
<reportTotal>
<nb_visits>9</nb_visits>
<nb_actions>31</nb_actions>
<nb_pageviews>31</nb_pageviews>
<revenue>35</revenue>
<_metadata>
<ts_archived>today-date-removed-in-tests</ts_archived>
</_metadata>
<visits_evolution_trend>7</visits_evolution_trend>
<actions_evolution_trend>7</actions_evolution_trend>
<pageviews_evolution_trend>7</pageviews_evolution_trend>
<revenue_evolution_trend>6</revenue_evolution_trend>
</reportTotal>
</result>

0 comments on commit 2ce56ce

Please sign in to comment.