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
|
<?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 PHPUnit\Integration;
use Piwik\Archive;
use Piwik\ArchiveProcessor\Parameters;
use Piwik\ArchiveProcessor\Rules;
use Piwik\Config;
use Piwik\DataAccess\ArchiveWriter;
use Piwik\Period\Factory;
use Piwik\Segment;
use Piwik\Site;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
class ArchiveTest extends IntegrationTestCase
{
public function setUp(): void
{
parent::setUp();
Fixture::createWebsite('2014-05-06');
}
public function test_pluginSpecificArchiveUsed_EvenIfAllArchiveExists_IfThereAreNoDataInAllArchive()
{
$idSite = 1;
// insert all plugin archive
$params = new Parameters(new Site($idSite), Factory::build('day', '2014-05-07'), new Segment('', [$idSite]));
$archiveWriter = new ArchiveWriter($params);
$archiveWriter->initNewArchive();
$archiveWriter->insertRecord('ExamplePlugin_archive1metric', 1);
$archiveWriter->insertRecord('ExamplePlugin_archive2metric', 5);
$archiveWriter->finalizeArchive();
// insert single plugin archive
$_GET['pluginOnly'] = 1;
$_GET['trigger'] = 'archivephp';
$params = new Parameters(new Site($idSite), Factory::build('day', '2014-05-07'), new Segment('', [$idSite]));
$params->setRequestedPlugin('ExamplePlugin');
$params->onlyArchiveRequestedPlugin();
$archiveWriter = new ArchiveWriter($params);
$archiveWriter->initNewArchive();
$archiveWriter->insertRecord('ExamplePlugin_archive2metric', 2);
$archiveWriter->insertRecord('ExamplePlugin_archive3metric', 3);
$archiveWriter->finalizeArchive();
// insert single plugin archive
$params = new Parameters(new Site($idSite), Factory::build('day', '2014-05-07'), new Segment('', [$idSite]));
$params->setRequestedPlugin('ExamplePlugin');
$params->onlyArchiveRequestedPlugin();
$archiveWriter = new ArchiveWriter($params);
$archiveWriter->initNewArchive();
$archiveWriter->insertRecord('ExamplePlugin_archive3metric', 7);
$archiveWriter->finalizeArchive();
$archive = Archive::build($idSite, 'day', '2014-05-07');
$metrics = $archive->getNumeric(['ExamplePlugin_archive1metric', 'ExamplePlugin_archive2metric', 'ExamplePlugin_archive3metric']);
$expected = [
'ExamplePlugin_archive1metric' => 0,
'ExamplePlugin_archive2metric' => 0,
'ExamplePlugin_archive3metric' => 7,
];
$this->assertEquals($expected, $metrics);
}
public function test_pluginSpecificArchiveUsed_EvenIfAllArchiveExists_IfThereAreNoDataInAllArchive_WithBrowserArchivingDisabled()
{
self::$fixture->getTestEnvironment()->overrideConfig('General', 'enable_browser_archiving_triggering', 0);
self::$fixture->getTestEnvironment()->overrideConfig('General', 'archiving_range_force_on_browser_request', 0);
self::$fixture->getTestEnvironment()->save();
Config::getInstance()->General['enable_browser_archiving_triggering'] = 0;
Config::getInstance()->General['archiving_range_force_on_browser_request'] = 0;
$this->assertTrue(Rules::isArchivingDisabledFor([1], new Segment('', [1]), 'day'));
$this->test_pluginSpecificArchiveUsed_EvenIfAllArchiveExists_IfThereAreNoDataInAllArchive();
}
}
|