forked from matomo-org/matomo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs matomo-org#4903 added tests and fixed some issues
- Loading branch information
Showing
5 changed files
with
189 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
/** | ||
* Piwik - Open source web analytics | ||
* | ||
* @link http://piwik.org | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
*/ | ||
|
||
use \Piwik\ArchiveProcessor\FixedSiteIds; | ||
|
||
/** | ||
* @group Core | ||
*/ | ||
class FixedSiteIdsTest extends PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var FixedSiteIds | ||
*/ | ||
private $fixedSiteIds; | ||
|
||
public function setUp() | ||
{ | ||
$this->fixedSiteIds = new FixedSiteIds(array(1,2,5,9)); | ||
} | ||
|
||
public function test_construct_withEmptyValue() | ||
{ | ||
$siteIds = new FixedSiteIds(null); | ||
$this->assertEquals(0, $siteIds->getNumSites()); | ||
$this->assertNull($siteIds->getNextSiteId()); | ||
} | ||
|
||
public function test_getNumSites() | ||
{ | ||
$this->assertEquals(4, $this->fixedSiteIds->getNumSites()); | ||
} | ||
|
||
public function test_getNumProcessedWebsites_getNextSiteId() | ||
{ | ||
$this->assertEquals(0, $this->fixedSiteIds->getNumProcessedWebsites()); | ||
$this->assertEquals(1, $this->fixedSiteIds->getNextSiteId()); | ||
$this->assertEquals(1, $this->fixedSiteIds->getNumProcessedWebsites()); | ||
$this->assertEquals(2, $this->fixedSiteIds->getNextSiteId()); | ||
$this->assertEquals(2, $this->fixedSiteIds->getNumProcessedWebsites()); | ||
$this->assertEquals(5, $this->fixedSiteIds->getNextSiteId()); | ||
$this->assertEquals(3, $this->fixedSiteIds->getNumProcessedWebsites()); | ||
$this->assertEquals(9, $this->fixedSiteIds->getNextSiteId()); | ||
$this->assertEquals(4, $this->fixedSiteIds->getNumProcessedWebsites()); | ||
|
||
$this->assertNull($this->fixedSiteIds->getNextSiteId()); | ||
$this->assertEquals(4, $this->fixedSiteIds->getNumProcessedWebsites()); | ||
} | ||
|
||
|
||
} |
108 changes: 108 additions & 0 deletions
108
tests/PHPUnit/Core/ArchiveProcessor/SharedSiteIdsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
/** | ||
* Piwik - Open source web analytics | ||
* | ||
* @link http://piwik.org | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
*/ | ||
|
||
use \Piwik\ArchiveProcessor\SharedSiteIds; | ||
|
||
/** | ||
* @group Core | ||
*/ | ||
class SharedSiteIdsTest extends PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var SharedSiteIds | ||
*/ | ||
private $sharedSiteIds; | ||
|
||
public function setUp() | ||
{ | ||
$this->sharedSiteIds = new SharedSiteIds(array(1,2,5,9)); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
$this->sharedSiteIds->setSiteIdsToArchive(array()); | ||
} | ||
|
||
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()); | ||
} | ||
|
||
} |