File size: 4,671 Bytes
968114b | 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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | <?php
/**
* Matomo - 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\AnonymousPiwikUsageMeasurement\tests\Integration\Tracker;
use Piwik\Plugins\AnonymousPiwikUsageMeasurement\Tracker\Profiles;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
/**
* @group AnonymousPiwikUsageMeasurement
* @group Profiles
* @group ProfilesTest
* @group Plugins
*/
class ProfilesTest extends IntegrationTestCase
{
/**
* @var Profiles
*/
private $profiles;
public function setUp(): void
{
parent::setUp();
$this->profiles = new Profiles();
}
public function test_popAll_ShouldReturnNoProfiles_WhenNothingPushed()
{
$this->assertSame(array(), $this->profiles->popAll());
}
public function test_pushEvent_ShouldAddProfileToListOfExistingProfiles()
{
$this->pushProfile('2014-01-01 00:01:02');
$this->assertEquals(array(array(
'creation_date' => '2014-01-01 00:01:02',
'category' => 'Category',
'name' => 'myName',
'action' => 'myAction',
'count' => '1',
'wall_time' => '35',
)), $this->profiles->popAll());
}
public function test_pushEvent_ShouldAggregateValue_WhenPushingSameEventMultipleTimes()
{
$this->pushProfile('2014-01-01 00:01:02');
$this->pushProfile('2014-01-01 00:01:03');
$this->pushProfile('2014-01-01 00:01:04');
$this->assertEquals(array(array(
'creation_date' => '2014-01-01 00:01:02',
'category' => 'Category',
'name' => 'myName',
'action' => 'myAction',
'count' => '3',
'wall_time' => '105',
)), $this->profiles->popAll());
}
public function test_pushEvent_ShouldPushAndReturnDifferentProfiles()
{
$this->pushProfile('2014-01-01 00:01:02');
$this->pushProfile('2014-01-01 00:01:03', 'OtherCategory');
$this->pushProfile('2014-01-01 00:01:04', 'Category', 'otherName');
$this->pushProfile('2014-01-01 00:01:05', 'Category', 'myName', 'otherAction');
$this->pushProfile('2014-01-01 00:01:06', 'Category', 'myName', 'lastAction', 10, 202);
$this->pushProfile('2014-01-01 00:01:07', 'Category', 'myName', 'lastAction', 1, $wallTime = 71);
$this->pushProfile('2014-01-01 00:01:08');
$expected = array(
array(
'creation_date' => '2014-01-01 00:01:06',
'category' => 'Category',
'name' => 'myName',
'action' => 'lastAction',
'count' => '11',
'wall_time' => '273',
),
array(
'creation_date' => '2014-01-01 00:01:02',
'category' => 'Category',
'name' => 'myName',
'action' => 'myAction',
'count' => '2', // we tracked same profile twice
'wall_time' => '70',
),
array(
'creation_date' => '2014-01-01 00:01:05',
'category' => 'Category',
'name' => 'myName',
'action' => 'otherAction',
'count' => '1',
'wall_time' => '35',
),
array(
'creation_date' => '2014-01-01 00:01:04',
'category' => 'Category',
'name' => 'otherName',
'action' => 'myAction',
'count' => '1',
'wall_time' => '35',
),
array(
'creation_date' => '2014-01-01 00:01:03',
'category' => 'OtherCategory',
'name' => 'myName',
'action' => 'myAction',
'count' => '1',
'wall_time' => '35',
)
);
$this->assertEquals($expected, $this->profiles->popAll());
}
public function test_popAll_shouldRemoveAllProfiles()
{
$this->pushProfile('2014-01-01 00:01:02');
$this->pushProfile('2014-01-01 00:01:03', 'OtherCategory');
$this->pushProfile('2014-01-01 00:01:04', 'Category', 'otherName');
$this->assertCount(3, $this->profiles->popAll());
$this->assertSame(array(), $this->profiles->popAll());
}
private function pushProfile($creationDate, $category = 'Category', $name = 'myName', $action = 'myAction', $count = 1, $wallTime = '35')
{
$this->profiles->pushProfile($creationDate, $category, $name, $action, $count, $wallTime);
}
}
|