File size: 1,945 Bytes
8fba801 | 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 | <?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\Plugins\Ecommerce\tests\Unit\Columns;
use Piwik\Plugins\Ecommerce\Columns\BaseConversion;
use Piwik\Tests\Framework\TestCase\UnitTestCase;
use Piwik\Tracker\GoalManager;
/**
* @group Ecommerce
*/
class BaseConversionTest extends UnitTestCase
{
private function makeConversion()
{
return new class extends BaseConversion {
public function exposeRoundRevenueIfNeeded($revenue)
{
return $this->roundRevenueIfNeeded($revenue);
}
};
}
/**
* @dataProvider getInRangeRevenueData
*/
public function testRoundRevenueIfNeededKeepsValuesWithinCap($revenue, $expected)
{
$this->assertEquals($expected, $this->makeConversion()->exposeRoundRevenueIfNeeded($revenue));
}
public function getInRangeRevenueData()
{
return [
'decimal is rounded' => [25.559, 25.56],
'integer kept' => [40, 40],
'negative kept' => [-50, -50],
'exactly at the cap' => [GoalManager::MAX_ALLOWED_REVENUE, GoalManager::MAX_ALLOWED_REVENUE],
];
}
/**
* @dataProvider getOutOfRangeRevenueData
*/
public function testRoundRevenueIfNeededRejectsValuesAboveCap($revenue)
{
$this->assertFalse($this->makeConversion()->exposeRoundRevenueIfNeeded($revenue));
}
public function getOutOfRangeRevenueData()
{
return [
'false is unchanged' => [false],
'just above the cap' => [GoalManager::MAX_ALLOWED_REVENUE + 1],
'negative above the cap' => [-GoalManager::MAX_ALLOWED_REVENUE - 1],
'overflow value' => ['1e308'],
'negative overflow value' => ['-1e308'],
];
}
}
|