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
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
use Piwik\CronArchive\SharedSiteIds;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
/**
* @group Core
* @group SharedSiteIdsTest
*/
class SharedSiteIdsTest extends IntegrationTestCase
{
/**
* @var SharedSiteIds
*/
private $sharedSiteIds;
public function setUp()
{
parent::setUp();
$this->sharedSiteIds = new SharedSiteIds(array(1,2,5,9));
}
public function tearDown()
{
$siteIdsToCleanup = new SharedSiteIds(array());
$siteIdsToCleanup->setSiteIdsToArchive(array());
parent::tearDown();
}
public function test_construct_withEmptyValue()
{
$this->sharedSiteIds->setSiteIdsToArchive(array());
$siteIds = new SharedSiteIds(null);
$this->assertEquals(0, $siteIds->getNumSites());
$this->assertNull($siteIds->getNextSiteId());
}
public function test_isSupported()
{
$this->assertTrue(SharedSiteIds::isSupported());
}
public function test_getNumSites()
{
$this->assertEquals(4, $this->sharedSiteIds->getNumSites());
}
public function test_getAllSiteIdsToArchive()
{
$this->assertEquals(array(1,2,5,9), $this->sharedSiteIds->getAllSiteIdsToArchive());
}
public function test_getNumProcessedWebsites_getNextSiteId()
{
$this->assertEquals(0, $this->sharedSiteIds->getNumProcessedWebsites());
$this->assertEquals(1, $this->sharedSiteIds->getNextSiteId());
$this->assertEquals(1, $this->sharedSiteIds->getNumProcessedWebsites());
$this->assertEquals(2, $this->sharedSiteIds->getNextSiteId());
$this->assertEquals(2, $this->sharedSiteIds->getNumProcessedWebsites());
$this->assertEquals(5, $this->sharedSiteIds->getNextSiteId());
$this->assertEquals(3, $this->sharedSiteIds->getNumProcessedWebsites());
$this->assertEquals(9, $this->sharedSiteIds->getNextSiteId());
$this->assertEquals(4, $this->sharedSiteIds->getNumProcessedWebsites());
$this->assertNull($this->sharedSiteIds->getNextSiteId());
$this->assertEquals(4, $this->sharedSiteIds->getNumProcessedWebsites());
}
public function test_usingMultipleSharedSiteIds()
{
$second = new SharedSiteIds(array(7,9,11,6,1,2));
// should ignore his queue and help processing the existing queue
$this->assertEquals(4, $second->getNumSites());
$this->assertEquals(4, $this->sharedSiteIds->getNumSites());
$this->assertEquals(array(1,2,5,9), $second->getAllSiteIdsToArchive());
$this->assertEquals(1, $second->getNextSiteId());
$this->assertEquals(1, $second->getNumProcessedWebsites());
$this->assertEquals(array(2,5,9), $this->sharedSiteIds->getAllSiteIdsToArchive());
$this->assertEquals(2, $this->sharedSiteIds->getNextSiteId());
$this->assertEquals(2, $this->sharedSiteIds->getNumProcessedWebsites());
$this->assertEquals(array(5,9), $second->getAllSiteIdsToArchive());
$this->assertEquals(5, $second->getNextSiteId());
$this->assertEquals(3, $second->getNumProcessedWebsites());
$this->assertEquals(array(9), $this->sharedSiteIds->getAllSiteIdsToArchive());
$this->assertEquals(9, $this->sharedSiteIds->getNextSiteId());
$this->assertEquals(4, $this->sharedSiteIds->getNumProcessedWebsites());
$this->assertNull($second->getNextSiteId());
$this->assertEquals(4, $second->getNumProcessedWebsites());
$this->assertEquals(array(), $second->getAllSiteIdsToArchive());
$this->assertNull($this->sharedSiteIds->getNextSiteId());
$this->assertEquals(4, $this->sharedSiteIds->getNumProcessedWebsites());
$this->assertEquals(array(), $this->sharedSiteIds->getAllSiteIdsToArchive());
}
}
|