diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2016-12-15 01:54:34 +0300 |
---|---|---|
committer | Matthieu Aubry <mattab@users.noreply.github.com> | 2016-12-15 01:54:34 +0300 |
commit | cc9fc7a5df4398afb2ea4744751813640dddd05d (patch) | |
tree | 78069e80086f9d02e0afb02ee29b72ea54c50cea /tests/PHPUnit | |
parent | e72541e585a1c4ee51a0819261b3c6becc77b7d0 (diff) |
make sure to always trigger site event when creating a new site instance (#11001)
Diffstat (limited to 'tests/PHPUnit')
-rw-r--r-- | tests/PHPUnit/Integration/SiteTest.php | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/PHPUnit/Integration/SiteTest.php b/tests/PHPUnit/Integration/SiteTest.php new file mode 100644 index 0000000000..498884d681 --- /dev/null +++ b/tests/PHPUnit/Integration/SiteTest.php @@ -0,0 +1,81 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ +namespace Piwik\Tests\Integration; + +use Piwik\Piwik; +use Piwik\Plugins\SitesManager\API; +use Piwik\Site; +use Piwik\Tests\Framework\Fixture; +use Piwik\Tests\Framework\TestCase\IntegrationTestCase; + +/** + * @group Core + */ +class SiteTest extends IntegrationTestCase +{ + private $idSite; + + public $siteAppendix = ' foo'; + + public function setUp() + { + parent::setUp(); + + $this->idSite = Fixture::createWebsite('2014-01-02 03:04:05'); + + $self = $this; + + Piwik::addAction('Site.setSites', function (&$sites) use ($self) { + foreach ($sites as &$site) { + if (strpos($site['name'], $self->siteAppendix) !== 0) { + $site['name'] .= $self->siteAppendix; + } + } + }); + } + + /** + * @expectedException \Piwik\Exception\UnexpectedWebsiteFoundException + * @expectedExceptionMessage An unexpected website was found in the request + */ + public function test_constructor_throwsException_ifSiteDoesNotExist() + { + $this->makeSite(9999); + } + + public function test_constructor_enrichesSite() + { + $site = $this->makeSite($this->idSite); + $this->assertSame('Piwik test' . $this->siteAppendix, $site->getName()); + } + + public function test_construct_enrichesSiteEvenIfSiteWasSetToCachePreviously() + { + $site = API::getInstance()->getSiteFromId($this->idSite); + Site::setSiteFromArray($this->idSite, $site); + + $site = $this->makeSite($this->idSite); + $this->assertSame('Piwik test' . $this->siteAppendix, $site->getName()); + } + + public function test_construct_whenRemovingSiteFromGlobalSitesArray_TheObjectItselfStillworks() + { + $site = $this->makeSite($this->idSite); + $this->assertSame('Piwik test' . $this->siteAppendix, $site->getName()); + + Site::clearCache(); + + $this->assertSame('Piwik test' . $this->siteAppendix, $site->getName()); + $this->assertSame(array(), Site::getSites()); // make sure data was not fetched again + } + + private function makeSite($idSite) + { + return new Site($idSite); + } +} |