blob: 7ab46a894534d67e031c0e6459a44195a053c1fb (
plain)
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
|
<?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\Common;
use Piwik\CronArchive;
use Piwik\CronArchive\ReArchiveList;
use Piwik\Date;
use Piwik\Db;
use Piwik\Option;
use Piwik\Plugin;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
class PluginTest extends IntegrationTestCase
{
protected static function beforeTableDataCached()
{
parent::beforeTableDataCached();
Fixture::createWebsite('2020-03-04 00:00:00');
}
public function test_schedulePluginReArchiving_shouldReArchiveFromLastDeactivationTime()
{
$time = Date::today()->subDay(3);
Option::set(Plugin\Manager::LAST_PLUGIN_DEACTIVATION_TIME_OPTION_PREFIX . 'ExamplePlugin', $time->getTimestamp());
$plugin = new Plugin('ExamplePlugin');
$plugin->schedulePluginReArchiving();
$date = $this->getDateFromReArchiveList();
$this->assertEquals($time->getDatetime(), $date);
}
public function test_schedulePluginReArchiving_shouldReArchiveFromLastCoreArchiveTimeIfEarlier()
{
$time = Date::today()->subDay(3);
Option::set(Plugin\Manager::LAST_PLUGIN_DEACTIVATION_TIME_OPTION_PREFIX . 'ExamplePlugin', $time->getTimestamp());
$cronTime = Date::today()->subDay(5);
Option::set(CronArchive::OPTION_ARCHIVING_FINISHED_TS, $cronTime->getTimestamp());
$plugin = new Plugin('ExamplePlugin');
$plugin->schedulePluginReArchiving();
$date = $this->getDateFromReArchiveList();
$this->assertEquals($cronTime->getDatetime(), $date);
}
public function test_schedulePluginReArchiving_shouldReArchiveFromLastCoreArchiveTimeIfNoDeactivation()
{
$cronTime = Date::today()->subDay(5);
Option::set(CronArchive::OPTION_ARCHIVING_FINISHED_TS, $cronTime->getTimestamp());
$plugin = new Plugin('ExamplePlugin');
$plugin->schedulePluginReArchiving();
$date = $this->getDateFromReArchiveList();
$this->assertNull($date);
}
public function test_schedulePluginReArchiving_shouldReArchiveFromNMonthsAgo_IfNoDecativationTimeOrCronTimeExists()
{
$plugin = new Plugin('ExamplePlugin');
$plugin->schedulePluginReArchiving();
$date = $this->getDateFromReArchiveList();
$this->assertNull($date);
}
private function getDateFromReArchiveList()
{
$list = new ReArchiveList();
$items = $list->getAll();
$item = reset($items);
$item = json_decode($item, $assocc = true);
if (empty($item['startDate'])) {
return null;
}
$date = $item['startDate'];
return Date::factory($date)->getDatetime();
}
}
|